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 47c381deb1a1..b7dd7f2c25c0 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 @@ -164,6 +164,7 @@ import java.util.EnumSet import javax.inject.Inject import com.google.android.material.R as MaterialR + @AndroidEntryPoint @Suppress("LargeClass") class ReaderPostDetailFragment : ViewPagerFragment(), @@ -595,6 +596,10 @@ class ReaderPostDetailFragment : ViewPagerFragment(), // Do nothing } + viewModel.postBlocked.observe(viewLifecycleOwner) { postBlocked -> + modifyMoreMenu(postBlocked) + } + viewModel.snackbarEvents.observeEvent(viewLifecycleOwner) { it.showSnackbar(binding) } viewModel.navigationEvents.observeEvent(viewLifecycleOwner) { it.handleNavigationEvent() } @@ -983,6 +988,18 @@ class ReaderPostDetailFragment : ViewPagerFragment(), } } + private fun modifyMoreMenu( + postBlocked: Boolean + ){ + val moreMenu:MenuItem? = toolBar.menu.findItem(R.id.menu_more) + if (postBlocked){ + moreMenu?.setIcon(R.drawable.ic_undo_white_24dp) + } + else{ + moreMenu?.setIcon(R.drawable.ic_ellipsis_vertical_white_24dp) + } + } + private fun showOrHideMoreMenu( state: ReaderPostDetailsUiState ) { 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 7b3055f380dc..64a94458732f 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 @@ -18,6 +18,7 @@ import org.wordpress.android.models.ReaderPost import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.prefs.AppPrefsWrapper +import org.wordpress.android.ui.reader.actions.ReaderBlogActions.BlockedBlogResult import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource import org.wordpress.android.ui.reader.discover.ReaderCardUiState.ReaderRecommendedBlogsCardUiState.ReaderRecommendedBlogUiState import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.OpenPost @@ -104,6 +105,12 @@ class ReaderPostCardActionsHandler @Inject constructor( ) { private lateinit var coroutineScope: CoroutineScope + private lateinit var blockedBlogResult: BlockedBlogResult + + private lateinit var blockedBlogSource: String + + private lateinit var updateBlockedStateFunction:(Boolean)->Unit + private val _navigationEvents = MediatorLiveData>() val navigationEvents: LiveData> = _navigationEvents @@ -400,6 +407,18 @@ class ReaderPostCardActionsHandler @Inject constructor( _navigationEvents.postValue(Event(ShowReadingPreferences)) } + fun handleUndoClicked(){ + coroutineScope.launch { + undoBlockBlogUseCase.undoBlockBlog(blockedBlogResult, blockedBlogSource) + _refreshPosts.postValue(Event(Unit)) + updateBlockedStateFunction(false) + } + } + + fun initUpdateBlockedStateFunction(func: (Boolean)->Unit){ + updateBlockedStateFunction = func + } + private suspend fun handleBlockSiteClicked( blogId: Long, feedId: Long, @@ -408,7 +427,10 @@ class ReaderPostCardActionsHandler @Inject constructor( blockBlogUseCase.blockBlog(blogId, feedId).collect { when (it) { is BlockSiteState.SiteBlockedInLocalDb -> { + blockedBlogSource = source + blockedBlogResult = it.blockedBlogData _refreshPosts.postValue(Event(Unit)) + updateBlockedStateFunction(true) _snackbarEvents.postValue( Event( SnackbarMessageHolder( @@ -418,6 +440,7 @@ class ReaderPostCardActionsHandler @Inject constructor( coroutineScope.launch { undoBlockBlogUseCase.undoBlockBlog(it.blockedBlogData, source) _refreshPosts.postValue(Event(Unit)) + updateBlockedStateFunction(false) } }) ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostMoreButtonUiStateBuilder.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostMoreButtonUiStateBuilder.kt index 4d7253d3ee31..27ce93f27e37 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostMoreButtonUiStateBuilder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostMoreButtonUiStateBuilder.kt @@ -63,10 +63,8 @@ class ReaderPostMoreButtonUiStateBuilder @Inject constructor( menuItems.add(buildShare(onButtonClicked)) menuItems.add(buildFollow(isPostFollowed, onButtonClicked)) if (includeReadingPreferences) { - menuItems.add(SpacerNoAction()) menuItems.add(buildReadingPreferences(onButtonClicked)) } - menuItems.add(SpacerNoAction()) menuItems.add(buildBlockSite(onButtonClicked)) menuItems.add(buildReportPost(onButtonClicked)) checkAndAddUserMenuItems(post, menuItems, onButtonClicked) @@ -234,7 +232,7 @@ class ReaderPostMoreButtonUiStateBuilder @Inject constructor( type = READING_PREFERENCES, label = UiStringRes(R.string.reader_menu_reading_preferences), labelColor = MaterialR.attr.colorOnSurface, - iconRes = R.drawable.ic_reader_preferences_white_24dp, + iconRes = R.drawable.ic_reader_preferences, iconColor = R.attr.wpColorOnSurfaceMedium, onClicked = onButtonClicked ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/BlockBlogUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/BlockBlogUseCase.kt index 1ac96e183f02..6f35df9c206f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/BlockBlogUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/BlockBlogUseCase.kt @@ -30,16 +30,17 @@ class BlockBlogUseCase @Inject constructor( blogId: Long, feedId: Long ) = flow { + performAction(blogId, feedId) // Blocking multiple sites in parallel isn't supported as the user would lose the ability to undo the action - if (continuation == null) { - if (!networkUtilsWrapper.isNetworkAvailable()) { - emit(NoNetwork) - } else { - performAction(blogId, feedId) - } - } else { - emit(AlreadyRunning) - } +// if (continuation == null) { +// if (!networkUtilsWrapper.isNetworkAvailable()) { +// emit(NoNetwork) +// } else { +// performAction(blogId, feedId) +// } +// } else { +// emit(AlreadyRunning) +// } } private suspend fun FlowCollector.performAction( @@ -55,13 +56,13 @@ class BlockBlogUseCase @Inject constructor( val blockedBlogData = readerBlogActionsWrapper.blockBlogFromReaderLocal(blogId, feedId) emit(SiteBlockedInLocalDb(blockedBlogData)) - val succeeded = blockBlogAndWaitForResult(blockedBlogData) - - if (succeeded) { - emit(Success) - } else { - emit(RequestFailed) - } +// val succeeded = blockBlogAndWaitForResult(blockedBlogData) +// +// if (succeeded) { +// emit(Success) +// } else { +// emit(RequestFailed) +// } } private suspend fun blockBlogAndWaitForResult(blockedBlogResult: BlockedBlogResult): Boolean { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderPostDetailViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderPostDetailViewModel.kt index 884564b2d79d..9ad03b42b5bd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderPostDetailViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderPostDetailViewModel.kt @@ -48,6 +48,7 @@ import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.CHANGE import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.FAILED import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.HAS_NEW import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.UNCHANGED +import org.wordpress.android.ui.reader.actions.ReaderBlogActions.BlockedBlogResult import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ReplaceRelatedPostDetailsWithHistory import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowEngagedPeopleList @@ -160,6 +161,9 @@ class ReaderPostDetailViewModel @Inject constructor( private val _reloadFragment = MutableLiveData>() val reloadFragment: LiveData> = _reloadFragment + private val _postBlocked = MutableLiveData(false) + val postBlocked: LiveData = _postBlocked + /** * Post which is about to be reblogged after the user selects a target site. */ @@ -171,6 +175,8 @@ class ReaderPostDetailViewModel @Inject constructor( var isFeed: Boolean = false var interceptedUri: String? = null + private var blockedBlogResult : BlockedBlogResult? = null + var post: ReaderPost? = null val hasPost: Boolean get() = post != null @@ -302,6 +308,10 @@ class ReaderPostDetailViewModel @Inject constructor( _updateLikesState.value = state } } + + readerPostCardActionsHandler.initUpdateBlockedStateFunction { state -> + _postBlocked.postValue(state) + } } fun showJetpackPoweredBottomSheet() { @@ -459,6 +469,10 @@ class ReaderPostDetailViewModel @Inject constructor( } _uiState.value = it.copy(moreMenuItems = moreMenuItems) + }?: run{ + if (_postBlocked.value == true) { + readerPostCardActionsHandler.handleUndoClicked() + } } } } diff --git a/WordPress/src/main/res/drawable/ic_reader_preferences_white_24dp.xml b/WordPress/src/main/res/drawable/ic_reader_preferences_white_24dp.xml deleted file mode 100644 index 72f003dc8ee1..000000000000 --- a/WordPress/src/main/res/drawable/ic_reader_preferences_white_24dp.xml +++ /dev/null @@ -1,12 +0,0 @@ - - -