Skip to content

Commit

Permalink
Edit call to action in preview sheet for stub articles (wikimedia#4465
Browse files Browse the repository at this point in the history
)

* Strings for the stub feature

* Update extract text

* UI updates

* Chip colors updated

* Addresses code review, design review comments

* Updated button text

* Updated success message for stub article edit

* Design review - do not dismiss dialog on return from edit

* Show snackbar above overlay

* Clean-up and touch-ups.

* Duplicate string.

---------

Co-authored-by: Sharvani Haran <[email protected]>
Co-authored-by: Dmitry Brant <[email protected]>
Co-authored-by: Dmitry Brant <[email protected]>
  • Loading branch information
4 people authored Mar 25, 2024
1 parent 3122bc6 commit c1e8312
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import org.wikipedia.analytics.metricsplatform.ArticleLinkPreviewInteraction
import org.wikipedia.bridge.JavaScriptActionHandler
import org.wikipedia.databinding.DialogLinkPreviewBinding
import org.wikipedia.dataclient.page.PageSummary
import org.wikipedia.edit.EditHandler
import org.wikipedia.edit.EditSectionActivity
import org.wikipedia.gallery.GalleryActivity
import org.wikipedia.gallery.GalleryThumbnailScrollView.GalleryViewListener
import org.wikipedia.history.HistoryEntry
Expand Down Expand Up @@ -145,12 +147,26 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV
}
}

private val requestStubArticleEditLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == EditHandler.RESULT_REFRESH_PAGE) {
overlayView?.let { overlay ->
FeedbackUtil.makeSnackbar(overlay.rootView, getString(R.string.stub_article_edit_saved_successfully))
.setAnchorView(overlay.secondaryButtonView).show()
}
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = DialogLinkPreviewBinding.inflate(inflater, container, false)
binding.linkPreviewToolbar.setOnClickListener { goToLinkedPage(false) }
binding.linkPreviewOverflowButton.setOnClickListener {
setupOverflowMenu()
}
binding.linkPreviewEditButton.setOnClickListener {
viewModel.pageTitle.run {
requestStubArticleEditLauncher.launch(EditSectionActivity.newIntent(requireContext(), -1, null, this, Constants.InvokeSource.LINK_PREVIEW_MENU, null))
}
}
L10nUtil.setConditionalLayoutDirection(binding.root, viewModel.pageTitle.wikiSite.languageCode)

lifecycleScope.launch {
Expand Down Expand Up @@ -374,23 +390,25 @@ class LinkPreviewDialog : ExtendedBottomSheetDialogFragment(), LinkPreviewErrorV
}

private fun setPreviewContents(contents: LinkPreviewContents) {
if (!contents.extract.isNullOrEmpty()) {
binding.linkPreviewExtractWebview.setBackgroundColor(Color.TRANSPARENT)
val colorHex = ResourceUtil.colorToCssString(
ResourceUtil.getThemedColor(
requireContext(),
android.R.attr.textColorPrimary
)
)
val dir = if (L10nUtil.isLangRTL(viewModel.pageTitle.wikiSite.languageCode)) "rtl" else "ltr"
binding.linkPreviewExtractWebview.loadDataWithBaseURL(
null,
"${JavaScriptActionHandler.getCssStyles(viewModel.pageTitle.wikiSite)}<div style=\"line-height: 150%; color: #$colorHex\" dir=\"$dir\">${contents.extract}</div>",
"text/html",
"UTF-8",
null
binding.linkPreviewExtractWebview.setBackgroundColor(Color.TRANSPARENT)
val colorHex = ResourceUtil.colorToCssString(
ResourceUtil.getThemedColor(
requireContext(),
android.R.attr.textColorPrimary
)
}
)
val dir = if (L10nUtil.isLangRTL(viewModel.pageTitle.wikiSite.languageCode)) "rtl" else "ltr"
val editVisibility = contents.extract.isNullOrBlank() && viewModel.pageTitle.namespace() == Namespace.MAIN
binding.linkPreviewEditButton.isVisible = editVisibility
binding.linkPreviewThumbnailGallery.isVisible = !editVisibility
val extract = if (editVisibility) "<i>" + getString(R.string.link_preview_stub_placeholder_text) + "</i>" else contents.extract
binding.linkPreviewExtractWebview.loadDataWithBaseURL(
null,
"${JavaScriptActionHandler.getCssStyles(viewModel.pageTitle.wikiSite)}<div style=\"line-height: 150%; color: #$colorHex\" dir=\"$dir\">$extract</div>",
"text/html",
"UTF-8",
null
)
contents.title.thumbUrl?.let {
binding.linkPreviewThumbnail.visibility = View.VISIBLE
ViewUtil.loadImage(binding.linkPreviewThumbnail, it)
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/org/wikipedia/util/FeedbackUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ object FeedbackUtil {
views.forEach { it.setOnClickListener(TOOLBAR_ON_CLICK_LISTENER) }
}

fun makeSnackbar(activity: Activity, text: CharSequence, duration: Int = LENGTH_DEFAULT, wikiSite: WikiSite = WikipediaApp.instance.wikiSite): Snackbar {
val view = findBestView(activity)
fun makeSnackbar(view: View, text: CharSequence, duration: Int = LENGTH_DEFAULT, wikiSite: WikiSite = WikipediaApp.instance.wikiSite): Snackbar {
val snackbar = Snackbar.make(view, StringUtil.fromHtml(text.toString()), duration)
val textView = snackbar.view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
textView.setLinkTextColor(ResourceUtil.getThemedColor(view.context, R.attr.progressive_color))
textView.movementMethod = LinkMovementMethodExt.getExternalLinkMovementMethod(wikiSite)
return snackbar
}

fun makeSnackbar(activity: Activity, text: CharSequence, duration: Int = LENGTH_DEFAULT, wikiSite: WikiSite = WikipediaApp.instance.wikiSite): Snackbar {
return makeSnackbar(findBestView(activity), text, duration, wikiSite)
}

fun showToastOverView(view: View, text: CharSequence?, duration: Int): Toast {
val toast = Toast.makeText(view.context, text, duration)
val v = LayoutInflater.from(view.context).inflate(androidx.appcompat.R.layout.abc_tooltip, null)
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/dialog_link_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/linkPreviewEditButton"
style="@style/App.Button.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="14dp"
android:layout_marginTop="4dp"
android:text="@string/menu_edit_article"
android:visibility="gone"
app:icon="@drawable/ic_mode_edit_white_24dp"
tools:visibility="visible" />
</LinearLayout>

<org.wikipedia.page.linkpreview.LinkPreviewErrorView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-qq/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1655,4 +1655,6 @@
<string name="places_survey_dialog_cancel">Negative action button text for places survey dialog</string>
<string name="places_survey_feedback_low_satisfaction_dialog_title">Title text for the secondary dialog which is shown as a result of an action on the main dialog for places feature - shown only to users who are very unsatisfied with the feature</string>
<string name="places_empty_list">Empty message for the list in the current map area. Please keep the anchor link around the \"on the map\".</string>
<string name="link_preview_stub_placeholder_text">Placeholder text shown to users in the preview dialog of an article, when there isn\'t enough content in the article to show in the preview.</string>
<string name="stub_article_edit_saved_successfully">Message text shown to users after a successful edit to a stub article.</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<string name="langlinks_your_wikipedia_languages">Your Wikipedia languages</string>
<string name="menu_save_changes">Publish changes</string>
<string name="edit_saved_successfully">Edit published!</string>
<string name="stub_article_edit_saved_successfully">Edit published! Changes may take time to appear.</string>
<string name="dialog_message_edit_failed">Edit failed!</string>
<string name="dialog_message_edit_failed_retry">Retry</string>
<string name="dialog_message_edit_failed_cancel">Cancel</string>
Expand Down Expand Up @@ -406,6 +407,7 @@
<string name="link_preview_dialog_save_button">Save</string>
<string name="link_preview_dialog_saved_button">Saved</string>
<string name="link_preview_dialog_share_button">Share</string>
<string name="link_preview_stub_placeholder_text">This article is a stub, which means there isn\'t enough content in the article to generate a preview. However, you can change that.</string>
<string name="error_page_does_not_exist">This page does not exist</string>
<string name="error_user_page_does_not_exist"><![CDATA[Wikipedia does not have a <a href="%1$s">user page</a> with this exact name. In general, this page should be created and edited by <b>%2$s</b>. If in doubt, please verify that \"%3$s\" exists.]]></string>
<string name="view_wiki_error_message_offline">Cannot connect to internet</string>
Expand Down

0 comments on commit c1e8312

Please sign in to comment.