From 56d0d8c4645d9aad8bb3aac3a24cd2d36e3927ba Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Wed, 7 Feb 2024 22:40:46 +0100 Subject: [PATCH] Ensure to verify that blog.url is not null before using it. While it should never occur that the URL is null, it's better to err on the side of caution. --- .../android/ui/reader/subfilter/SubFilterViewModel.kt | 4 ++-- .../android/ui/reader/subfilter/SubfilterListItem.kt | 3 ++- .../android/ui/reader/views/ReaderSiteHeaderView.java | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) 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 11a170fb3329..44d50e65e150 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 @@ -142,8 +142,8 @@ class SubFilterViewModel @Inject constructor( }.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) + val blogTwoName = getBlogNameForComparison(blog2) + blogOneName.compareTo(blogTwoName, true) }) filterList.addAll( 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 f78c7550aee1..dcaf479f983e 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 @@ -69,7 +69,8 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = override val label: UiString = if (blog.name.isNotEmpty()) { UiStringText(blog.name) } else { - UiStringText(if (blog.url.isNotEmpty()) UrlUtils.getHost(blog.url) else "") + if (blog.url.isNotEmpty()) UiStringText(UrlUtils.getHost(blog.url)) + else UiStringRes(R.string.reader_untitled_post) } val showUnseenCount: Boolean = blog.numUnseenPosts > 0 val unseenCount: Int = blog.numUnseenPosts 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 c4aad5a3b025..3fd01fae0109 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,11 @@ private void showBlogInfo(ReaderBlog blogInfo, String source) { if (blogInfo.hasName()) { txtBlogName.setText(blogInfo.getName()); } else { - txtBlogName.setText(UrlUtils.getHost(blogInfo.getUrl())); + if (blogInfo.getUrl() != null) { + txtBlogName.setText(UrlUtils.getHost(blogInfo.getUrl())); + } else { + txtBlogName.setText(R.string.reader_untitled_post); + } } if (blogInfo.hasUrl()) {