Skip to content

Commit

Permalink
fix Three-dots problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Agoni-0 committed Oct 24, 2024
1 parent a270161 commit ca83b85
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Event<ReaderNavigationEvents>>()
val navigationEvents: LiveData<Event<ReaderNavigationEvents>> = _navigationEvents

Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -418,6 +440,7 @@ class ReaderPostCardActionsHandler @Inject constructor(
coroutineScope.launch {
undoBlockBlogUseCase.undoBlockBlog(it.blockedBlogData, source)
_refreshPosts.postValue(Event(Unit))
updateBlockedStateFunction(false)
}
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockSiteState>.performAction(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -160,6 +161,9 @@ class ReaderPostDetailViewModel @Inject constructor(
private val _reloadFragment = MutableLiveData<Event<Unit>>()
val reloadFragment: LiveData<Event<Unit>> = _reloadFragment

private val _postBlocked = MutableLiveData<Boolean>(false)
val postBlocked: LiveData<Boolean> = _postBlocked

/**
* Post which is about to be reblogged after the user selects a target site.
*/
Expand All @@ -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
Expand Down Expand Up @@ -302,6 +308,10 @@ class ReaderPostDetailViewModel @Inject constructor(
_updateLikesState.value = state
}
}

readerPostCardActionsHandler.initUpdateBlockedStateFunction { state ->
_postBlocked.postValue(state)
}
}

fun showJetpackPoweredBottomSheet() {
Expand Down Expand Up @@ -459,6 +469,10 @@ class ReaderPostDetailViewModel @Inject constructor(
}

_uiState.value = it.copy(moreMenuItems = moreMenuItems)
}?: run{
if (_postBlocked.value == true) {
readerPostCardActionsHandler.handleUndoClicked()
}
}
}
}
Expand Down

This file was deleted.

0 comments on commit ca83b85

Please sign in to comment.