filter monthly calendar by event types
This commit is contained in:
parent
c9f3e6fec3
commit
bb6073ac11
|
@ -167,7 +167,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
} else if (config.storedView == WEEKLY_VIEW) {
|
||||
(week_view_view_pager.adapter as MyWeekPagerAdapter).refreshEvents(week_view_view_pager.currentItem)
|
||||
} else {
|
||||
|
||||
(main_view_pager.adapter as MyMonthPagerAdapter).refreshEvents(main_view_pager.currentItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,9 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
FilePickerDialog(this) {
|
||||
if (it.toLowerCase().endsWith(".ics")) {
|
||||
ImportEventsDialog(this, it) {
|
||||
if (it)
|
||||
if (it) {
|
||||
updateViewPager()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.invalid_file_format)
|
||||
|
|
|
@ -78,7 +78,7 @@ class WidgetMonthlyConfigureActivity : AppCompatActivity(), MonthlyCalendar {
|
|||
config_bg_seekbar.progress = (mBgAlpha * 100).toInt()
|
||||
updateBgColor()
|
||||
|
||||
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime())
|
||||
MonthlyCalendarImpl(this, applicationContext).updateMonthlyCalendar(DateTime(), false)
|
||||
}
|
||||
|
||||
fun saveConfig() {
|
||||
|
|
|
@ -4,11 +4,13 @@ import android.os.Bundle
|
|||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v4.app.FragmentStatePagerAdapter
|
||||
import android.util.SparseArray
|
||||
import com.simplemobiletools.calendar.fragments.MonthFragment
|
||||
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
||||
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||
|
||||
class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: NavigationListener) : FragmentStatePagerAdapter(fm) {
|
||||
private val mFragments = SparseArray<MonthFragment>()
|
||||
|
||||
override fun getCount() = mCodes.size
|
||||
|
||||
|
@ -20,6 +22,14 @@ class MyMonthPagerAdapter(fm: FragmentManager, private val mCodes: List<String>,
|
|||
val fragment = MonthFragment()
|
||||
fragment.arguments = bundle
|
||||
fragment.setListener(mListener)
|
||||
|
||||
mFragments.put(position, fragment)
|
||||
return fragment
|
||||
}
|
||||
|
||||
fun refreshEvents(pos: Int) {
|
||||
for (i in -1..1) {
|
||||
mFragments[pos + i].updateCalendar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,12 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
|||
mCalendar.apply {
|
||||
mTargetDate = Formatter.getDateTimeFromCode(mDayCode)
|
||||
getDays() // prefill the screen asap, even if without events
|
||||
updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
|
||||
}
|
||||
updateCalendar()
|
||||
}
|
||||
|
||||
fun updateCalendar() {
|
||||
mCalendar.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
|
||||
}
|
||||
|
||||
override fun updateMonthlyCalendar(month: String, days: List<Day>) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers
|
|||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
|
||||
import com.simplemobiletools.calendar.models.Day
|
||||
|
@ -15,6 +16,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
|
||||
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
||||
var mEvents: List<Event>
|
||||
var mFilterEventTypes = true
|
||||
|
||||
lateinit var mTargetDate: DateTime
|
||||
|
||||
|
@ -22,7 +24,8 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
mEvents = ArrayList<Event>()
|
||||
}
|
||||
|
||||
fun updateMonthlyCalendar(targetDate: DateTime) {
|
||||
fun updateMonthlyCalendar(targetDate: DateTime, filterEventTypes: Boolean = true) {
|
||||
mFilterEventTypes = filterEventTypes
|
||||
mTargetDate = targetDate
|
||||
val startTS = mTargetDate.minusMonths(1).seconds()
|
||||
val endTS = mTargetDate.plusMonths(1).seconds()
|
||||
|
@ -113,7 +116,10 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
}
|
||||
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
mEvents = events
|
||||
if (mFilterEventTypes)
|
||||
mEvents = mContext.getFilteredEvents(events)
|
||||
else
|
||||
mEvents = events
|
||||
getDays()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
|
|||
|
||||
mRemoteViews.setInt(R.id.calendar_holder, "setBackgroundColor", config.widgetBgColor)
|
||||
|
||||
mCalendar?.updateMonthlyCalendar(DateTime())
|
||||
mCalendar?.updateMonthlyCalendar(DateTime(), false)
|
||||
}
|
||||
|
||||
private fun updateWidget() {
|
||||
|
|
Loading…
Reference in New Issue