add a filter to daily view too

This commit is contained in:
tibbi 2017-02-12 18:49:41 +01:00
parent 5b8c9b89c3
commit 6d79b686fa
6 changed files with 54 additions and 12 deletions

View File

@ -3,10 +3,15 @@ package com.simplemobiletools.calendar.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v4.view.ViewPager import android.support.v4.view.ViewPager
import android.util.SparseIntArray
import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
import com.simplemobiletools.calendar.dialogs.FilterEventTypesDialog
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
import com.simplemobiletools.calendar.helpers.DAY_CODE import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.NEW_EVENT_START_TS import com.simplemobiletools.calendar.helpers.NEW_EVENT_START_TS
import com.simplemobiletools.calendar.interfaces.NavigationListener import com.simplemobiletools.calendar.interfaces.NavigationListener
@ -20,6 +25,7 @@ class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChange
private var mDayCode = "" private var mDayCode = ""
private var mPagerDays: MutableList<String>? = null private var mPagerDays: MutableList<String>? = null
private var mPagerPos = 0 private var mPagerPos = 0
private var eventTypeColors = SparseIntArray()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -34,6 +40,26 @@ class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChange
day_fab.setOnClickListener { addNewEvent() } day_fab.setOnClickListener { addNewEvent() }
updateTextColors(day_coordinator) updateTextColors(day_coordinator)
DBHelper.newInstance(applicationContext).getEventTypes {
eventTypeColors.clear()
it.map { eventTypeColors.put(it.id, it.color) }
invalidateOptionsMenu()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_day, menu)
menu.findItem(R.id.filter).isVisible = eventTypeColors.size() > 1
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.filter -> showFilterDialog()
else -> return super.onOptionsItemSelected(item)
}
return true
} }
private fun fillViewPager(targetDay: String) { private fun fillViewPager(targetDay: String) {
@ -47,6 +73,12 @@ class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChange
} }
} }
private fun showFilterDialog() {
FilterEventTypesDialog(this) {
recheckEvents()
}
}
private fun addNewEvent() { private fun addNewEvent() {
Intent(applicationContext, EventActivity::class.java).apply { Intent(applicationContext, EventActivity::class.java).apply {
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(mPagerDays?.get(view_pager.currentItem).toString())) putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(mPagerDays?.get(view_pager.currentItem).toString()))

View File

@ -98,7 +98,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu) menuInflater.inflate(R.menu.menu_main, menu)
menu.findItem(R.id.filter).isVisible = eventTypeColors.size() > 1 menu.findItem(R.id.filter).isVisible = eventTypeColors.size() > 1
return true return true
} }

View File

@ -29,7 +29,8 @@ class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, p
} }
fun checkDayEvents(pos: Int) { fun checkDayEvents(pos: Int) {
mFragments[pos - 1].checkEvents() for (i in -1..1) {
mFragments[pos + 1].checkEvents() mFragments[pos + i].checkEvents()
}
} }
} }

View File

@ -18,7 +18,10 @@ import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.DayEventsAdapter import com.simplemobiletools.calendar.adapters.DayEventsAdapter
import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getAppropriateTheme import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.extensions.getFilteredEvents
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteItemsListener import com.simplemobiletools.calendar.interfaces.DeleteItemsListener
import com.simplemobiletools.calendar.interfaces.NavigationListener import com.simplemobiletools.calendar.interfaces.NavigationListener
@ -38,21 +41,18 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
lateinit var mRes: Resources lateinit var mRes: Resources
lateinit var mHolder: RelativeLayout lateinit var mHolder: RelativeLayout
lateinit var mConfig: Config
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_day, container, false) val view = inflater.inflate(R.layout.fragment_day, container, false)
mRes = resources mRes = resources
mHolder = view.day_holder mHolder = view.day_holder
mConfig = context.config
mDayCode = arguments.getString(DAY_CODE) mDayCode = arguments.getString(DAY_CODE)
val day = Formatter.getDayTitle(activity.applicationContext, mDayCode) val day = Formatter.getDayTitle(activity.applicationContext, mDayCode)
mHolder.top_value.apply { mHolder.top_value.apply {
text = day text = day
setOnClickListener { pickDay() } setOnClickListener { pickDay() }
setTextColor(mConfig.textColor) setTextColor(context.config.textColor)
} }
setupButtons() setupButtons()
@ -65,7 +65,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
} }
private fun setupButtons() { private fun setupButtons() {
mTextColor = mConfig.textColor mTextColor = context.config.textColor
mHolder.apply { mHolder.apply {
top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP) top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP)
@ -117,7 +117,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
DBHelper.newInstance(context, this).getEvents(startTS, endTS, this) DBHelper.newInstance(context, this).getEvents(startTS, endTS, this)
} }
private fun updateEvents(events: MutableList<Event>) { private fun updateEvents(events: List<Event>) {
if (activity == null) if (activity == null)
return return
@ -149,14 +149,14 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
} }
override fun eventsDeleted(cnt: Int) { override fun eventsDeleted(cnt: Int) {
checkEvents()
(activity as DayActivity).recheckEvents() (activity as DayActivity).recheckEvents()
} }
override fun gotEvents(events: MutableList<Event>) { override fun gotEvents(events: MutableList<Event>) {
val sorted = ArrayList<Event>(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))) val sorted = ArrayList<Event>(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })))
val filtered = context.getFilteredEvents(sorted)
activity?.runOnUiThread { activity?.runOnUiThread {
updateEvents(sorted) updateEvents(filtered)
} }
} }
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/filter"
android:icon="@drawable/ic_filter"
android:title="@string/filter"
app:showAsAction="ifRoom"/>
</menu>