avoid always showing "Go to today" menu item at the list view

This commit is contained in:
tibbi 2020-11-02 23:05:05 +01:00
parent 53b78ec0a9
commit 8e586b47af
2 changed files with 19 additions and 2 deletions

View file

@ -168,10 +168,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
shouldGoToTodayBeVisible = currentFragments.last().shouldGoToTodayBeVisible()
menu.apply {
goToTodayButton = findItem(R.id.go_to_today)
findItem(R.id.filter).isVisible = mShouldFilterBeVisible
findItem(R.id.go_to_today).isVisible = (shouldGoToTodayBeVisible || config.storedView == EVENTS_LIST_VIEW) && !mIsSearchOpen
findItem(R.id.go_to_today).isVisible = shouldGoToTodayBeVisible && !mIsSearchOpen
findItem(R.id.go_to_date).isVisible = config.storedView != EVENTS_LIST_VIEW
}

View file

@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.EventActivity
import com.simplemobiletools.calendar.pro.activities.MainActivity
@ -42,6 +43,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
private var minFetchedTS = 0L
private var maxFetchedTS = 0L
private var wereInitialEventsAdded = false
private var hasBeenScrolled = false
private var bottomItemAtRefresh: ListItem? = null
private var use24HourFormat = false
@ -134,6 +136,16 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
fetchNextPeriod()
}
}
mView.calendar_events_list.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!hasBeenScrolled) {
hasBeenScrolled = true
activity?.invalidateOptionsMenu()
}
}
})
} else {
(currAdapter as EventListAdapter).updateListItems(listItems)
if (updateStatus == UPDATE_TOP) {
@ -195,6 +207,10 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
val firstNonPastSectionIndex = listItems.indexOfFirst { it is ListSection && !it.isPastSection }
if (firstNonPastSectionIndex != -1) {
(mView.calendar_events_list.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(firstNonPastSectionIndex, 0)
mView.calendar_events_list.onGlobalLayout {
hasBeenScrolled = false
activity?.invalidateOptionsMenu()
}
}
}
@ -204,7 +220,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
checkEvents()
}
override fun shouldGoToTodayBeVisible() = false
override fun shouldGoToTodayBeVisible() = hasBeenScrolled
override fun updateActionBarTitle() {
(activity as? MainActivity)?.updateActionBarTitle(getString(R.string.app_launcher_name))