From 4311f96f63dcdd82e7ee227dbb0706d703695de6 Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 7 Feb 2024 08:59:13 +0100 Subject: [PATCH] Make sure to use the site address when the title is empty --- .../ui/reader/adapters/ReaderBlogAdapter.java | 2 +- .../discover/ReaderPostUiStateBuilder.kt | 3 +++ .../ui/reader/subfilter/SubFilterViewModel.kt | 23 ++++++++++++++++++- .../ui/reader/subfilter/SubfilterListItem.kt | 3 ++- .../ui/reader/viewmodels/ReaderViewModel.kt | 5 +++- .../ui/reader/views/ReaderSiteHeaderView.java | 2 +- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java index 095981ff9370..29693db4b77e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java @@ -149,7 +149,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (blogInfo.hasName()) { blogHolder.mTxtTitle.setText(blogInfo.getName()); } else { - blogHolder.mTxtTitle.setText(R.string.reader_untitled_post); + blogHolder.mTxtTitle.setText(UrlUtils.getHost(blogInfo.getUrl())); } if (blogInfo.hasUrl()) { blogHolder.mTxtUrl.setText(UrlUtils.getHost(blogInfo.getUrl())); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt index bb27b1b4d64f..d5dbaf10043e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt @@ -431,6 +431,9 @@ class ReaderPostUiStateBuilder @Inject constructor( private fun buildBlogName(post: ReaderPost, isP2Post: Boolean = false): UiString { val blogName = post.takeIf { it.hasBlogName() }?.blogName?.let { UiStringText(it) } + ?:post.takeIf { it.hasBlogUrl() } + ?.blogUrl + ?.let { UiStringText(urlUtilsWrapper.removeScheme(it)) } ?: UiStringRes(R.string.untitled_in_parentheses) if (!isP2Post) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt index 1a9cda7734b1..a66ad865c7db 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.reader.subfilter import android.os.Bundle import androidx.annotation.VisibleForTesting +import androidx.compose.ui.text.toLowerCase import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import kotlinx.coroutines.CoroutineDispatcher @@ -12,6 +13,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.datasets.ReaderBlogTable import org.wordpress.android.datasets.ReaderTagTable import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.models.ReaderBlog import org.wordpress.android.models.ReaderTag import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD @@ -32,9 +34,12 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.EventBusWrapper +import org.wordpress.android.util.StringUtils +import org.wordpress.android.util.UrlUtils import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ScopedViewModel import org.wordpress.android.viewmodel.SingleLiveEvent +import java.util.Comparator import java.util.EnumSet import javax.inject.Inject import javax.inject.Named @@ -110,6 +115,17 @@ class SubFilterViewModel @Inject constructor( } } + private fun getBlogNameForComparison(blog: ReaderBlog?): String { + return if (blog == null) { + "" + } else if (blog.hasName()) { + blog.name + } else if (blog.hasUrl()) { + StringUtils.notNullStr(UrlUtils.getHost(blog.url)) + } else { + "" + } + } fun loadSubFilters() { launch { val filterList = ArrayList() @@ -124,7 +140,12 @@ class SubFilterViewModel @Inject constructor( blog.organizationId == organization.orgId } ?: false } - } + }.sortedWith(Comparator { blog1, blog2 -> + // sort followed blogs by name/domain to match display + val blogOneName = getBlogNameForComparison(blog1) + val blogNameTwo = getBlogNameForComparison(blog2) + blogOneName.compareTo(blogNameTwo, true) + }) filterList.addAll( followedBlogs.map { blog -> diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt index 1e24f2c868d4..2b005e15b809 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt @@ -11,6 +11,7 @@ import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.ItemType.TAG import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.ui.utils.UiString.UiStringText +import org.wordpress.android.util.UrlUtils sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = false) { open var isSelected: Boolean = false @@ -68,7 +69,7 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = override val label: UiString = if (blog.name.isNotEmpty()) { UiStringText(blog.name) } else { - UiStringRes(R.string.reader_untitled_post) + UiStringText(UrlUtils.getHost(blog.url)) } val showUnseenCount: Boolean = blog.numUnseenPosts > 0 val unseenCount: Int = blog.numUnseenPosts diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt index 2f97cf4fcbea..ce0b5e04441a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt @@ -50,6 +50,7 @@ import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringText import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.util.SnackbarSequencer +import org.wordpress.android.util.UrlUtilsWrapper import org.wordpress.android.util.distinct import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ScopedViewModel @@ -75,6 +76,7 @@ class ReaderViewModel @Inject constructor( private val snackbarSequencer: SnackbarSequencer, private val jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil, private val readerTopBarMenuHelper: ReaderTopBarMenuHelper, + private val urlUtilsWrapper: UrlUtilsWrapper, // todo: annnmarie removed this private val getFollowedTagsUseCase: GetFollowedTagsUseCase ) : ScopedViewModel(mainDispatcher) { private var initialized: Boolean = false @@ -447,7 +449,8 @@ class ReaderViewModel @Inject constructor( fun onSubFilterItemSelected(item: SubfilterListItem) { when (item) { is SubfilterListItem.SiteAll -> clearTopBarFilter() - is SubfilterListItem.Site -> updateTopBarFilter(item.blog.name, ReaderFilterType.BLOG) + is SubfilterListItem.Site -> updateTopBarFilter(item.blog.name + .ifEmpty { urlUtilsWrapper.removeScheme(item.blog.url.ifEmpty { "" }) }, ReaderFilterType.BLOG) is SubfilterListItem.Tag -> updateTopBarFilter(item.tag.tagDisplayName, ReaderFilterType.TAG) else -> Unit // do nothing } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java index 7fb609c0941b..c4aad5a3b025 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/ReaderSiteHeaderView.java @@ -158,7 +158,7 @@ private void showBlogInfo(ReaderBlog blogInfo, String source) { if (blogInfo.hasName()) { txtBlogName.setText(blogInfo.getName()); } else { - txtBlogName.setText(R.string.reader_untitled_post); + txtBlogName.setText(UrlUtils.getHost(blogInfo.getUrl())); } if (blogInfo.hasUrl()) {