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..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
@@ -935,6 +936,15 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
is ReaderNavigationEvents.ShowPostDetail,
is ReaderNavigationEvents.ShowVideoViewer,
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/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 ebface3b6753..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
@@ -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,10 @@ class ReaderPostCardActionsHandler @Inject constructor(
recommendedBlogUiState: ReaderRecommendedBlogUiState,
source: String
) {
+ if (!accountStore.hasAccessToken()) {
+ showSignInPrompt()
+ return
+ }
val param = ReaderSiteFollowUseCase.Param(
blogId = recommendedBlogUiState.blogId,
blogName = recommendedBlogUiState.name,
@@ -311,6 +317,10 @@ class ReaderPostCardActionsHandler @Inject constructor(
post: ReaderPost,
source: String
) {
+ if (!accountStore.hasAccessToken()) {
+ showSignInPrompt()
+ return
+ }
followSite(
ReaderSiteFollowUseCase.Param(
post.blogId,
@@ -320,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
diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml
index d08673ae4a48..ce989bfef621 100644
--- a/WordPress/src/main/res/values/strings.xml
+++ b/WordPress/src/main/res/values/strings.xml
@@ -2355,6 +2355,8 @@
Can\'t like while logged out of WordPress.com
+ Log in to WordPress.com to subscribe to this site
+ Log In
Unable to retrieve this post
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 **/