Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/21180-fixed incorrect working state of 'Three-dots' icon #21352

Merged
merged 20 commits into from
Oct 29, 2024
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 @@ -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
Loading