Skip to content

Commit

Permalink
Merge pull request #21352 from Agoni-0/issue/21180
Browse files Browse the repository at this point in the history
Issue/21180-fixed incorrect working state of 'Three-dots' icon
  • Loading branch information
nbradbury authored Oct 29, 2024
2 parents bb38297 + 7776467 commit 95088f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,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 +987,18 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
}
}

private fun modifyMoreMenu(
postBlocked: Boolean
){
val moreMenu:MenuItem? = toolBar.menu.findItem(R.id.menu_more)
if (postBlocked){
moreMenu?.setVisible(false)
}
else{
moreMenu?.setVisible(true)
}
}

private fun showOrHideMoreMenu(
state: ReaderPostDetailsUiState
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class ReaderPostCardActionsHandler @Inject constructor(
) {
private lateinit var coroutineScope: CoroutineScope

private var updateBlockedStateFunction: ((Boolean) -> Unit)? = null

private val _navigationEvents = MediatorLiveData<Event<ReaderNavigationEvents>>()
val navigationEvents: LiveData<Event<ReaderNavigationEvents>> = _navigationEvents

Expand Down Expand Up @@ -400,6 +402,10 @@ class ReaderPostCardActionsHandler @Inject constructor(
_navigationEvents.postValue(Event(ShowReadingPreferences))
}

fun initUpdateBlockedStateFunction(func: (Boolean)->Unit){
updateBlockedStateFunction = func
}

private suspend fun handleBlockSiteClicked(
blogId: Long,
feedId: Long,
Expand All @@ -409,6 +415,7 @@ class ReaderPostCardActionsHandler @Inject constructor(
when (it) {
is BlockSiteState.SiteBlockedInLocalDb -> {
_refreshPosts.postValue(Event(Unit))
updateBlockedStateFunction?.let { func -> func(true) }
_snackbarEvents.postValue(
Event(
SnackbarMessageHolder(
Expand All @@ -418,6 +425,7 @@ class ReaderPostCardActionsHandler @Inject constructor(
coroutineScope.launch {
undoBlockBlogUseCase.undoBlockBlog(it.blockedBlogData, source)
_refreshPosts.postValue(Event(Unit))
updateBlockedStateFunction?.let { func -> func(false) }
}
})
)
Expand All @@ -428,12 +436,14 @@ class ReaderPostCardActionsHandler @Inject constructor(
_snackbarEvents.postValue(
Event(SnackbarMessageHolder(UiStringRes(R.string.reader_toast_err_unable_to_block_blog)))
)
updateBlockedStateFunction?.let { func -> func(false) }
}
BlockSiteState.Failed.RequestFailed -> {
_refreshPosts.postValue(Event(Unit))
_snackbarEvents.postValue(
Event(SnackbarMessageHolder(UiStringRes(R.string.reader_toast_err_unable_to_block_blog)))
)
updateBlockedStateFunction?.let { func -> func(false) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ReaderPostMoreButtonUiStateBuilder @Inject constructor(
menuItems.add(buildBlockSite(onButtonClicked))
menuItems.add(buildReportPost(onButtonClicked))
checkAndAddUserMenuItems(post, menuItems, onButtonClicked)

return menuItems
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ 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.
*/
private var pendingReblogPost: ReaderPost? = null

private var isStarted = false
private var isRelatedPost: Boolean = false

var isFeed: Boolean = false
var interceptedUri: String? = null

var post: ReaderPost? = null
val hasPost: Boolean
get() = post != null
Expand Down Expand Up @@ -302,6 +302,10 @@ class ReaderPostDetailViewModel @Inject constructor(
_updateLikesState.value = state
}
}

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

fun showJetpackPoweredBottomSheet() {
Expand Down

0 comments on commit 95088f2

Please sign in to comment.