Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ sealed class ReaderNavigationEvents {
) : ReaderNavigationEvents()

data object ShowReadingPreferences : ReaderNavigationEvents()
data object ShowSignIn : ReaderNavigationEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -311,6 +317,10 @@ class ReaderPostCardActionsHandler @Inject constructor(
post: ReaderPost,
source: String
) {
if (!accountStore.hasAccessToken()) {
showSignInPrompt()
return
}
followSite(
ReaderSiteFollowUseCase.Param(
post.blogId,
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,8 @@

<!-- snackbar messages -->
<string name="reader_snackbar_err_cannot_like_post_logged_out">Can\'t like while logged out of WordPress.com</string>
<string name="reader_snackbar_err_cannot_follow_logged_out">Log in to WordPress.com to subscribe to this site</string>
<string name="reader_snackbar_err_cannot_follow_logged_out_action">Log In</string>

<!-- failure messages when retrieving a single reader post -->
<string name="reader_err_get_post_generic">Unable to retrieve this post</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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 **/
Expand Down