properly reset some calendars at toggling Sunday First or 24 hour time format

This commit is contained in:
tibbi 2018-01-21 23:59:04 +01:00
parent 1741455f15
commit 354d658395
6 changed files with 44 additions and 16 deletions

View File

@ -129,7 +129,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
if (config.storedView == WEEKLY_VIEW) {
if (mStoredIsSundayFirst != config.isSundayFirst || mStoredUse24HourFormat != config.use24hourFormat) {
updateViewPager()
}
}

View File

@ -35,6 +35,7 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
private val redTextColor = resources.getColor(R.color.red_text)
private val now = activity.getNowSeconds()
private val todayDate = Formatter.getDayTitle(activity, Formatter.getDayCodeFromTS(now))
private var use24HourFormat = activity.config.use24hourFormat
override fun getActionMenuId() = R.menu.cab_event_list
@ -76,6 +77,11 @@ class EventListAdapter(activity: SimpleActivity, val listItems: ArrayList<ListIt
override fun getItemViewType(position: Int) = if (listItems[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
fun toggle24HourFormat(use24HourFormat: Boolean) {
this.use24HourFormat = use24HourFormat
notifyDataSetChanged()
}
private fun setupListEvent(view: View, listEvent: ListEvent) {
view.apply {
event_section_title.text = listEvent.title

View File

@ -26,18 +26,30 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
private var mEvents: List<Event> = ArrayList()
private var prevEventsHash = 0
private var lastHash = 0
private var use24HourFormat = false
lateinit var mView: View
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.fragment_event_list, container, false)
val placeholderText = String.format(getString(R.string.two_string_placeholder), "${getString(R.string.no_upcoming_events)}\n", getString(R.string.add_some_events))
mView.calendar_empty_list_placeholder.text = placeholderText
use24HourFormat = context!!.config.use24hourFormat
return mView
}
override fun onResume() {
super.onResume()
checkEvents()
val use24Hour = context!!.config.use24hourFormat
if (use24Hour != use24HourFormat) {
use24HourFormat = use24Hour
(mView.calendar_events_list.adapter as? EventListAdapter)?.toggle24HourFormat(use24HourFormat)
}
}
override fun onPause() {
super.onPause()
use24HourFormat = context!!.config.use24hourFormat
}
private fun checkEvents() {

View File

@ -59,6 +59,11 @@ class MonthFragment : Fragment(), MonthlyCalendar {
return view
}
override fun onPause() {
super.onPause()
mSundayFirst = context!!.config.isSundayFirst
}
override fun onResume() {
super.onResume()
if (mConfig.isSundayFirst != mSundayFirst) {

View File

@ -101,15 +101,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
return mView
}
override fun setMenuVisibility(menuVisible: Boolean) {
super.setMenuVisibility(menuVisible)
isFragmentVisible = menuVisible
if (isFragmentVisible && wasFragmentInit) {
mListener?.updateHoursTopMargin(mView.week_top_holder.height)
checkScrollLimits(mView.week_events_scrollview.scrollY)
}
}
override fun onPause() {
super.onPause()
wasExtraHeightAdded = true
@ -140,6 +131,15 @@ class WeekFragment : Fragment(), WeeklyCalendar {
})
}
override fun setMenuVisibility(menuVisible: Boolean) {
super.setMenuVisibility(menuVisible)
isFragmentVisible = menuVisible
if (isFragmentVisible && wasFragmentInit) {
mListener?.updateHoursTopMargin(mView.week_top_holder.height)
checkScrollLimits(mView.week_events_scrollview.scrollY)
}
}
private fun setupDayLabels() {
var curDay = Formatter.getDateTimeFromTS(mWeekTimestamp)
val textColor = context!!.config.textColor
@ -150,8 +150,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.findViewById<TextView>(mRes.getIdentifier("week_day_label_$i", "id", context!!.packageName)).apply {
text = "$dayLetter\n${curDay.dayOfMonth}"
setTextColor(if (todayCode == dayCode) primaryColor else textColor)
if (todayCode == dayCode)
if (todayCode == dayCode) {
todayColumnIndex = i
}
}
curDay = curDay.plusDays(1)
}
@ -174,9 +175,8 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_events_scrollview.scrollY = minScrollY
} else if (maxScrollY != -1 && y > maxScrollY) {
mView.week_events_scrollview.scrollY = maxScrollY
} else {
if (isFragmentVisible)
mListener?.scrollTo(y)
} else if (isFragmentVisible) {
mListener?.scrollTo(y)
}
}
@ -238,7 +238,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
updateEvents()
}
fun updateEvents() {
private fun updateEvents() {
if (mWasDestroyed)
return
@ -360,7 +360,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
val minTS = Math.max(startDateTime.seconds(), mWeekTimestamp)
val maxTS = Math.min(endDateTime.seconds(), mWeekTimestamp + WEEK_SECONDS)
val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS)
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (context.config.isSundayFirst) 0 else 1) % 7
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (context!!.config.isSundayFirst) 0 else 1) % 7
val daysCnt = Days.daysBetween(Formatter.getDateTimeFromTS(minTS).toLocalDate(), Formatter.getDateTimeFromTS(maxTS).toLocalDate()).days
var doesEventFit: Boolean

View File

@ -40,6 +40,11 @@ class YearFragment : Fragment(), YearlyCalendar {
return mView
}
override fun onPause() {
super.onPause()
mSundayFirst = context!!.config.isSundayFirst
}
override fun onResume() {
super.onResume()
val sundayFirst = context!!.config.isSundayFirst