Skip to content

Commit

Permalink
Further update
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltey committed Aug 29, 2024
1 parent 0d402e8 commit 677ac32
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/org/wikipedia/page/PageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ class PageFragment : Fragment(), BackPressedHandler, CommunicationBridge.Communi
requireActivity(),
titleId = R.string.recommended_content_survey_dialog_title,
messageId = R.string.recommended_content_survey_dialog_message,
snackbarMessageId = R.string.recommended_content_survey_dialog_submitted_message,
source = InvokeSource.RECOMMENDED_CONTENT
)
}
Expand Down
90 changes: 50 additions & 40 deletions app/src/main/java/org/wikipedia/views/SurveyDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.google.android.material.textfield.TextInputEditText
import org.wikipedia.Constants
import org.wikipedia.R
import org.wikipedia.analytics.eventplatform.PatrollerExperienceEvent
import org.wikipedia.databinding.DialogFeedbackOptionsBinding
import org.wikipedia.settings.Prefs
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
Expand All @@ -19,48 +20,50 @@ object SurveyDialog {
fun showFeedbackOptionsDialog(activity: Activity,
titleId: Int = R.string.patroller_diff_feedback_dialog_title,
messageId: Int = R.string.patroller_diff_feedback_dialog_message,
snackbarMessageId: Int = R.string.patroller_diff_feedback_submitted_snackbar,
source: Constants.InvokeSource) {
var dialog: AlertDialog? = null
val feedbackView = activity.layoutInflater.inflate(R.layout.dialog_feedback_options, null)
feedbackView.findViewById<TextView>(R.id.messageText).text = activity.getString(messageId)
val binding = DialogFeedbackOptionsBinding.inflate(activity.layoutInflater)
binding.messageText.text = activity.getString(messageId)

if (source == Constants.InvokeSource.SUGGESTED_EDITS_RECENT_EDITS) {
val clickListener = View.OnClickListener {
val feedbackOption = (it as TextView).text.toString()
dialog?.dismiss()
if (feedbackOption == activity.getString(R.string.patroller_diff_feedback_dialog_option_satisfied)) {
showFeedbackSnackbarAndTooltip(activity, source)
showFeedbackSnackbarAndTooltip(activity, snackbarMessageId, source)
} else {
showFeedbackInputDialog(activity, source)
showFeedbackInputDialog(activity, snackbarMessageId, source)
}

sendAnalyticsEvent("feedback_selection", "feedback_form", source,
PatrollerExperienceEvent.getActionDataString(feedbackOption = feedbackOption))
}
feedbackView.findViewById<TextView>(R.id.optionSatisfied).setOnClickListener(clickListener)
feedbackView.findViewById<TextView>(R.id.optionNeutral).setOnClickListener(clickListener)
feedbackView.findViewById<TextView>(R.id.optionUnsatisfied).setOnClickListener(clickListener)
binding.optionSatisfied.setOnClickListener(clickListener)
binding.optionNeutral.setOnClickListener(clickListener)
binding.optionUnsatisfied.setOnClickListener(clickListener)
} else if (source == Constants.InvokeSource.RECOMMENDED_CONTENT) {
feedbackView.findViewById<View>(R.id.feedbackInputContainer).isVisible = true
binding.optionNeutral.isChecked = true
binding.feedbackInputContainer.isVisible = true
}

sendAnalyticsEvent("impression", "feedback_form", source)
val dialogBuilder = MaterialAlertDialogBuilder(activity)
.setTitle(titleId)
.setCancelable(false)
.setView(feedbackView)
.setView(binding.root)
if (source == Constants.InvokeSource.RECOMMENDED_CONTENT) {
dialogBuilder.setPositiveButton(R.string.patroller_diff_feedback_dialog_submit) { _, _ ->
val feedbackInput = feedbackView.findViewById<TextInputEditText>(R.id.feedbackInput).text.toString()
val feedbackInput = binding.feedbackInput.text.toString()
// TODO: send event
showFeedbackSnackbarAndTooltip(activity, source)
showFeedbackSnackbarAndTooltip(activity, snackbarMessageId, source)
}
dialogBuilder.setNegativeButton(R.string.text_input_dialog_cancel_button_text) { _, _ -> }
}
dialog = dialogBuilder.show()
}

private fun showFeedbackInputDialog(activity: Activity, source: Constants.InvokeSource) {
private fun showFeedbackInputDialog(activity: Activity, messageId: Int, source: Constants.InvokeSource) {
val feedbackView = activity.layoutInflater.inflate(R.layout.dialog_feedback_input, null)
sendAnalyticsEvent("impression", "feedback_input_form", source)
MaterialAlertDialogBuilder(activity)
Expand All @@ -70,42 +73,49 @@ object SurveyDialog {
val feedbackInput = feedbackView.findViewById<TextInputEditText>(R.id.feedbackInput).text.toString()
sendAnalyticsEvent("feedback_input_submit", "feedback_input_form", source,
PatrollerExperienceEvent.getActionDataString(feedbackText = feedbackInput))
showFeedbackSnackbarAndTooltip(activity, source)
showFeedbackSnackbarAndTooltip(activity, messageId, source)
}
.show()
}

private fun showFeedbackSnackbarAndTooltip(activity: Activity, source: Constants.InvokeSource) {
FeedbackUtil.showMessage(activity, R.string.patroller_diff_feedback_submitted_snackbar)
private fun showFeedbackSnackbarAndTooltip(activity: Activity, messageId: Int, source: Constants.InvokeSource) {
FeedbackUtil.showMessage(activity, messageId)
sendAnalyticsEvent("feedback_submit_toast", "feedback_form", source)
activity.window.decorView.postDelayed({
val anchorView = activity.findViewById<View>(R.id.more_options)
if (!activity.isDestroyed && anchorView != null && Prefs.showOneTimeRecentEditsFeedbackForm) {
sendAnalyticsEvent("tooltip_impression", "feedback_form", source)
FeedbackUtil.getTooltip(
activity,
activity.getString(R.string.patroller_diff_feedback_tooltip),
arrowAnchorPadding = -DimenUtil.roundedDpToPx(7f),
topOrBottomMargin = 0,
aboveOrBelow = false,
autoDismiss = false,
showDismissButton = true
).apply {
showAlignBottom(anchorView)
when (source) {
Constants.InvokeSource.SUGGESTED_EDITS_RECENT_EDITS -> {
Prefs.showOneTimeRecentEditsFeedbackForm = false
}
Constants.InvokeSource.RECOMMENDED_CONTENT -> {
// TODO: add preference
}
else -> {
// do nothing
when (source) {
Constants.InvokeSource.SUGGESTED_EDITS_RECENT_EDITS -> {
activity.window.decorView.postDelayed({
val anchorView = activity.findViewById<View>(R.id.more_options)
if (!activity.isDestroyed && anchorView != null && Prefs.showOneTimeRecentEditsFeedbackForm) {
sendAnalyticsEvent("tooltip_impression", "feedback_form", source)
FeedbackUtil.getTooltip(
activity,
activity.getString(R.string.patroller_diff_feedback_tooltip),
arrowAnchorPadding = -DimenUtil.roundedDpToPx(7f),
topOrBottomMargin = 0,
aboveOrBelow = false,
autoDismiss = false,
showDismissButton = true
).apply {
showAlignBottom(anchorView)
when (source) {
Constants.InvokeSource.SUGGESTED_EDITS_RECENT_EDITS -> {
Prefs.showOneTimeRecentEditsFeedbackForm = false
}
else -> {
// do nothing
}
}
}
}
}
}, 100)
}
}, 100)
Constants.InvokeSource.RECOMMENDED_CONTENT -> {
// TODO: add analytics event
}
else -> {
// do nothing
}
}
}

private fun sendAnalyticsEvent(action: String, activeInterface: String, source: Constants.InvokeSource, actionData: String = "") {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-qq/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1715,4 +1715,5 @@
<string name="recommended_content_survey_dialog_title">Title for the Recommended Content survey dialog.</string>
<string name="recommended_content_survey_dialog_message">Message text for the Recommended Content survey dialog.</string>
<string name="recommended_content_survey_dialog_input_hint">Hint label for the Recommended Content survey dialog input field.</string>
<string name="recommended_content_survey_dialog_submitted_message">Snackbar message for the Recommended Content survey after submitting it.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@
<string name="recommended_content_survey_dialog_title">Help improve recommended content.</string>
<string name="recommended_content_survey_dialog_message">Are you satisfied with this recommended search result?</string>
<string name="recommended_content_survey_dialog_input_hint">Additional Feedback</string>
<string name="recommended_content_survey_dialog_submitted_message">Feedback submitted. Thank you!</string>
<!-- /Recommended Content -->

</resources>

0 comments on commit 677ac32

Please sign in to comment.