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

fix: back button in actionbar #1442

Merged
merged 2 commits into from Mar 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -125,7 +125,6 @@ class EventDetailsFragment : Fragment() {
.nonNull()
.observe(viewLifecycleOwner, Observer {
showEventErrorScreen(true)
setHasOptionsMenu(false)
})

eventViewModel.loadEvent(safeArgs.eventId)
Expand Down Expand Up @@ -394,5 +393,9 @@ class EventDetailsFragment : Fragment() {
private fun showEventErrorScreen(show: Boolean) {
rootView.container.visibility = if (!show) View.VISIBLE else View.GONE
rootView.eventErrorCard.visibility = if (show) View.VISIBLE else View.GONE
val menuItemSize = menuActionBar?.size() ?: 0
for (i in 0..(menuItemSize - 1)) {
menuActionBar?.getItem(i)?.isVisible = !show
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when we go back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't really understand your question? @iamareebjamal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it reappear correctly when we go back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, it will reappear correctly because:

  1. Menu Items visibility will only change on function showEventErrorScreen()
  2. When error fetching occurs, the error is observed and call that function showEventErrorScreen() to true -> menu items visibility is false -> disappear
  3. When error fetching stop occurring, the event detail is fetched and the event variable in the ViewModel is observed and call that function showEventErrorScreen() to false -> menu items visibility is true -> reappear

You can see it in here from line 84 to 104

       eventViewModel.event
            .nonNull()
            .observe(this, Observer {
                loadEvent(it)
                eventShare = it
                title = eventShare.name

                if (eventShare.favorite) {
                    setFavoriteIcon(R.drawable.ic_baseline_favorite_white)
                }

                if (runOnce) {
                    loadSocialLinksFragment()
                    loadSimilarEventsFragment()
                }
                runOnce = false

                Timber.d("Fetched events of id %d", safeArgs.eventId)
                showEventErrorScreen(false)
                setHasOptionsMenu(true)
            })

}
}