fix #889, add the Go To Today button at the event list view too

This commit is contained in:
tibbi 2020-03-08 20:04:26 +01:00
parent 9b97f25971
commit b96f7b4b89
3 changed files with 11 additions and 11 deletions

View File

@ -173,7 +173,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
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
findItem(R.id.go_to_today).isVisible = shouldGoToTodayBeVisible || config.storedView == EVENTS_LIST_VIEW
findItem(R.id.go_to_date).isVisible = config.storedView != EVENTS_LIST_VIEW
}

View File

@ -40,15 +40,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
init {
setupDragListener(true)
var firstNonPastSectionIndex = -1
listItems.forEachIndexed { index, listItem ->
if (firstNonPastSectionIndex == -1 && listItem is ListSection) {
if (!listItem.isPastSection) {
firstNonPastSectionIndex = index
}
}
}
val firstNonPastSectionIndex = listItems.indexOfFirst { it is ListSection && !it.isPastSection }
if (firstNonPastSectionIndex != -1) {
activity.runOnUiThread {
recyclerView.scrollToPosition(firstNonPastSectionIndex)

View File

@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.EventActivity
import com.simplemobiletools.calendar.pro.activities.MainActivity
@ -18,6 +19,7 @@ import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.models.Event
import com.simplemobiletools.calendar.pro.models.ListEvent
import com.simplemobiletools.calendar.pro.models.ListItem
import com.simplemobiletools.calendar.pro.models.ListSection
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.MONTH_SECONDS
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
@ -187,7 +189,13 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
checkEvents()
}
override fun goToToday() {}
override fun goToToday() {
val listItems = context!!.getEventListItems(mEvents)
val firstNonPastSectionIndex = listItems.indexOfFirst { it is ListSection && !it.isPastSection }
if (firstNonPastSectionIndex != -1) {
(mView.calendar_events_list.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(firstNonPastSectionIndex, 0)
}
}
override fun showGoToDateDialog() {}