From fa57325a73111d1d0918c7dca676de88e8411b4d Mon Sep 17 00:00:00 2001 From: adalpari Date: Wed, 26 Nov 2025 17:31:02 +0100 Subject: [PATCH 1/6] Showing a simple toast --- .../ui/reader/discover/ReaderPostCardActionsHandler.kt | 8 ++++++++ WordPress/src/main/res/values/strings.xml | 1 + 2 files changed, 9 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt index ebface3b6753..2c311c4c84a1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt @@ -12,6 +12,7 @@ import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.datasets.ReaderBlogTableWrapper import org.wordpress.android.fluxc.Dispatcher +import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.AccountStore.AddOrDeleteSubscriptionPayload.SubscriptionAction.DELETE import org.wordpress.android.fluxc.store.AccountStore.AddOrDeleteSubscriptionPayload.SubscriptionAction.NEW import org.wordpress.android.models.ReaderPost @@ -100,6 +101,7 @@ class ReaderPostCardActionsHandler @Inject constructor( private val appReviewsManagerWrapper: AppReviewsManagerWrapper, private val seenStatusToggleUseCase: ReaderSeenStatusToggleUseCase, private val readerBlogTableWrapper: ReaderBlogTableWrapper, + private val accountStore: AccountStore, @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher ) { private lateinit var coroutineScope: CoroutineScope @@ -299,6 +301,12 @@ class ReaderPostCardActionsHandler @Inject constructor( recommendedBlogUiState: ReaderRecommendedBlogUiState, source: String ) { + if (!accountStore.hasAccessToken()) { + _snackbarEvents.postValue( + Event(SnackbarMessageHolder(UiStringRes(R.string.reader_toast_err_cannot_follow_logged_out))) + ) + return + } val param = ReaderSiteFollowUseCase.Param( blogId = recommendedBlogUiState.blogId, blogName = recommendedBlogUiState.name, diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index d08673ae4a48..030de3a06dba 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -2355,6 +2355,7 @@ Can\'t like while logged out of WordPress.com + Can\'t follow while logged out of WordPress.com Unable to retrieve this post From 198b5325acf7bb6e5e368b1138e489b63f5bdf22 Mon Sep 17 00:00:00 2001 From: adalpari Date: Wed, 26 Nov 2025 17:40:27 +0100 Subject: [PATCH 2/6] Openig login flow --- .../android/ui/reader/ReaderPostDetailFragment.kt | 3 ++- .../ui/reader/discover/ReaderDiscoverFragment.kt | 11 +++++++++++ .../ui/reader/discover/ReaderNavigationEvents.kt | 1 + .../reader/discover/ReaderPostCardActionsHandler.kt | 10 +++++++++- WordPress/src/main/res/values/strings.xml | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt index bc4bdc52de56..6f0972ef98b3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt @@ -934,7 +934,8 @@ class ReaderPostDetailFragment : ViewPagerFragment(), is ReaderNavigationEvents.ShowPostDetail, is ReaderNavigationEvents.ShowVideoViewer, - is ReaderNavigationEvents.ShowReaderSubs -> Unit // Do Nothing + is ReaderNavigationEvents.ShowReaderSubs, + is ReaderNavigationEvents.ShowSignIn -> Unit // Do Nothing } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverFragment.kt index 9ec358add447..5f507e896400 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverFragment.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.appcompat.app.AlertDialog +import org.wordpress.android.BuildConfig import androidx.core.content.ContextCompat import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager @@ -39,6 +40,7 @@ import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowReade import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowReaderSubs import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowReportPost import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowReportUser +import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowSignIn import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowSitePickerForResult import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowVideoViewer import org.wordpress.android.ui.reader.tracker.ReaderTracker @@ -220,9 +222,18 @@ class ReaderDiscoverFragment : ViewPagerFragment(R.layout.reader_discover_fragme OpenUrlType.INTERNAL ) is ShowReaderSubs -> ReaderActivityLauncher.showReaderSubs(requireActivity()) + is ShowSignIn -> navigateToLogin() else -> Unit // Do Nothing } + private fun navigateToLogin() { + if (BuildConfig.IS_JETPACK_APP) { + ActivityLauncher.showSignInForResultJetpackOnly(requireActivity()) + } else { + ActivityLauncher.showSignInForResultWpComOnly(requireActivity()) + } + } + private fun showBookmarkSavedLocallyDialog(bookmarkDialog: ShowBookmarkedSavedOnlyLocallyDialog) { if (bookmarksSavedLocallyDialog == null) { MaterialAlertDialogBuilder(requireActivity()) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderNavigationEvents.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderNavigationEvents.kt index b96ef3fe0123..d2dfeddde923 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderNavigationEvents.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderNavigationEvents.kt @@ -69,4 +69,5 @@ sealed class ReaderNavigationEvents { ) : ReaderNavigationEvents() data object ShowReadingPreferences : ReaderNavigationEvents() + data object ShowSignIn : ReaderNavigationEvents() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt index 2c311c4c84a1..3ad22f26f248 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt @@ -303,7 +303,15 @@ class ReaderPostCardActionsHandler @Inject constructor( ) { if (!accountStore.hasAccessToken()) { _snackbarEvents.postValue( - Event(SnackbarMessageHolder(UiStringRes(R.string.reader_toast_err_cannot_follow_logged_out))) + Event( + SnackbarMessageHolder( + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out), + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out_action), + buttonAction = { + _navigationEvents.postValue(Event(ReaderNavigationEvents.ShowSignIn)) + } + ) + ) ) return } diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 030de3a06dba..2433a0e5c852 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -2355,7 +2355,8 @@ Can\'t like while logged out of WordPress.com - Can\'t follow while logged out of WordPress.com + Log in to follow this site + Log In Unable to retrieve this post From 551526b2c73ff4e8a52a9dd7f4476b35031f6907 Mon Sep 17 00:00:00 2001 From: adalpari Date: Wed, 26 Nov 2025 17:47:55 +0100 Subject: [PATCH 3/6] Checking the subscribe action inside the menu as well --- .../android/ui/reader/ReaderPostDetailFragment.kt | 13 +++++++++++-- .../discover/ReaderPostCardActionsHandler.kt | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt index 6f0972ef98b3..6d4d04c9f8d4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt @@ -57,6 +57,7 @@ import dagger.hilt.android.AndroidEntryPoint import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode +import org.wordpress.android.BuildConfig import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.analytics.AnalyticsTracker @@ -934,8 +935,16 @@ class ReaderPostDetailFragment : ViewPagerFragment(), is ReaderNavigationEvents.ShowPostDetail, is ReaderNavigationEvents.ShowVideoViewer, - is ReaderNavigationEvents.ShowReaderSubs, - is ReaderNavigationEvents.ShowSignIn -> Unit // Do Nothing + is ReaderNavigationEvents.ShowReaderSubs -> Unit // Do Nothing + is ReaderNavigationEvents.ShowSignIn -> navigateToLogin() + } + } + + private fun navigateToLogin() { + if (BuildConfig.IS_JETPACK_APP) { + ActivityLauncher.showSignInForResultJetpackOnly(requireActivity()) + } else { + ActivityLauncher.showSignInForResultWpComOnly(requireActivity()) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt index 3ad22f26f248..112b655fe61b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt @@ -327,6 +327,20 @@ class ReaderPostCardActionsHandler @Inject constructor( post: ReaderPost, source: String ) { + if (!accountStore.hasAccessToken()) { + _snackbarEvents.postValue( + Event( + SnackbarMessageHolder( + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out), + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out_action), + buttonAction = { + _navigationEvents.postValue(Event(ReaderNavigationEvents.ShowSignIn)) + } + ) + ) + ) + return + } followSite( ReaderSiteFollowUseCase.Param( post.blogId, From 6208a2dd2f58d229a2692e409f462e58035ab555 Mon Sep 17 00:00:00 2001 From: adalpari Date: Wed, 26 Nov 2025 17:50:20 +0100 Subject: [PATCH 4/6] Minor refactor --- .../discover/ReaderPostCardActionsHandler.kt | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt index 112b655fe61b..e59d1cdba19b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandler.kt @@ -302,17 +302,7 @@ class ReaderPostCardActionsHandler @Inject constructor( source: String ) { if (!accountStore.hasAccessToken()) { - _snackbarEvents.postValue( - Event( - SnackbarMessageHolder( - UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out), - UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out_action), - buttonAction = { - _navigationEvents.postValue(Event(ReaderNavigationEvents.ShowSignIn)) - } - ) - ) - ) + showSignInPrompt() return } val param = ReaderSiteFollowUseCase.Param( @@ -328,17 +318,7 @@ class ReaderPostCardActionsHandler @Inject constructor( source: String ) { if (!accountStore.hasAccessToken()) { - _snackbarEvents.postValue( - Event( - SnackbarMessageHolder( - UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out), - UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out_action), - buttonAction = { - _navigationEvents.postValue(Event(ReaderNavigationEvents.ShowSignIn)) - } - ) - ) - ) + showSignInPrompt() return } followSite( @@ -350,6 +330,20 @@ class ReaderPostCardActionsHandler @Inject constructor( ) } + private fun showSignInPrompt() { + _snackbarEvents.postValue( + Event( + SnackbarMessageHolder( + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out), + UiStringRes(R.string.reader_snackbar_err_cannot_follow_logged_out_action), + buttonAction = { + _navigationEvents.postValue(Event(ReaderNavigationEvents.ShowSignIn)) + } + ) + ) + ) + } + private suspend fun followSite( followSiteParam: ReaderSiteFollowUseCase.Param, source: String From 82ce3bf9e55e51a888d30c36e9621b4e9bc1cd89 Mon Sep 17 00:00:00 2001 From: adalpari Date: Wed, 26 Nov 2025 18:06:46 +0100 Subject: [PATCH 5/6] String change --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 2433a0e5c852..ce989bfef621 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -2355,7 +2355,7 @@ Can\'t like while logged out of WordPress.com - Log in to follow this site + Log in to WordPress.com to subscribe to this site Log In From 7610fbda454227d1c68a2fb6d07e7e460c8069f4 Mon Sep 17 00:00:00 2001 From: adalpari Date: Thu, 27 Nov 2025 09:26:30 +0100 Subject: [PATCH 6/6] Fixing tests --- .../ui/reader/discover/ReaderPostCardActionsHandlerTest.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandlerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandlerTest.kt index aa9580135f85..e20b1313018c 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandlerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostCardActionsHandlerTest.kt @@ -19,6 +19,7 @@ import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.datasets.ReaderBlogTableWrapper import org.wordpress.android.fluxc.Dispatcher +import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.AccountStore.AddOrDeleteSubscriptionPayload.SubscriptionAction import org.wordpress.android.models.ReaderPost import org.wordpress.android.ui.pages.SnackbarMessageHolder @@ -129,6 +130,9 @@ class ReaderPostCardActionsHandlerTest : BaseUnitTest() { @Mock private lateinit var dispatcher: Dispatcher + @Mock + private lateinit var accountStore: AccountStore + @Mock private lateinit var resourceProvider: ResourceProvider @@ -155,12 +159,14 @@ class ReaderPostCardActionsHandlerTest : BaseUnitTest() { mock(), seenStatusToggleUseCase, readerBlogTableWrapper, + accountStore, testDispatcher() ) actionHandler.initScope(testScope()) whenever(appPrefsWrapper.shouldShowBookmarksSavedLocallyDialog()).thenReturn(false) whenever(htmlMessageUtils.getHtmlMessageFromStringFormatResId(any(), anyVararg())).thenReturn(mock()) whenever(readerBlogTableWrapper.getReaderBlog(any(), any())).thenReturn(mock()) + whenever(accountStore.hasAccessToken()).thenReturn(true) } /** BOOKMARK ACTION begin **/