store filtered event types in db

This commit is contained in:
tibbi 2017-02-12 13:07:34 +01:00
parent a8652b06e0
commit 57d2ef24ac
8 changed files with 39 additions and 27 deletions

View File

@ -16,7 +16,7 @@ import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import com.simplemobiletools.calendar.dialogs.FilterEventsDialog
import com.simplemobiletools.calendar.dialogs.FilterEventTypesDialog
import com.simplemobiletools.calendar.dialogs.ImportEventsDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
@ -129,7 +129,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
private fun showFilterDialog() {
FilterEventsDialog(this) {
FilterEventTypesDialog(this) {
}
}

View File

@ -38,7 +38,8 @@ class FilterEventTypeAdapter(val activity: SimpleActivity, val mItems: List<Even
class ViewHolder(val activity: SimpleActivity, view: View) : RecyclerView.ViewHolder(view) {
fun bindView(eventType: EventType): View {
itemView.apply {
filter_event_type_title.text = eventType.title
filter_event_type_checkbox.setColors(activity.config.textColor, activity.config.primaryColor, activity.config.backgroundColor)
filter_event_type_checkbox.text = eventType.title
filter_event_type_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
filter_event_type_holder.setOnClickListener { filter_event_type_checkbox.toggle() }
}

View File

@ -8,23 +8,18 @@ import com.simplemobiletools.calendar.adapters.FilterEventTypeAdapter
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.dialog_filter_events.view.*
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
import java.util.*
class FilterEventsDialog(val activity: SimpleActivity, val callback: () -> Unit) : AlertDialog.Builder(activity) {
class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> Unit) : AlertDialog.Builder(activity) {
val dialog: AlertDialog?
var eventTypes = ArrayList<EventType>()
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_events, null)
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_event_types, null)
DBHelper.newInstance(activity).getEventTypes {
eventTypes = it
view.filter_events_list.adapter = FilterEventTypeAdapter(activity, it)
activity.runOnUiThread {
activity.updateTextColors(view.filter_events_list)
}
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it)
}
dialog = AlertDialog.Builder(activity)

View File

@ -45,6 +45,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(REMINDER_MINUTES, 10)
set(mins) = prefs.edit().putInt(REMINDER_MINUTES, mins).apply()
var displayEventTypes: Set<String>
get() = prefs.getStringSet(DISPLAY_EVENT_TYPES, HashSet<String>())
set(displayEventTypes) = prefs.edit().remove(DISPLAY_EVENT_TYPES).putStringSet(DISPLAY_EVENT_TYPES, displayEventTypes).apply()
var googleSync: Boolean
get() = prefs.getBoolean(GOOGLE_SYNC, false)
set(googleSync) = prefs.edit().putBoolean(GOOGLE_SYNC, googleSync).apply()
@ -53,6 +57,22 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(SYNC_ACCOUNT_NAME, "")
set(syncAccountName) = prefs.edit().putString(SYNC_ACCOUNT_NAME, syncAccountName).apply()
fun addDisplayEventType(type: String) {
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
}
fun addDisplayEventTypes(types: Set<String>) {
val currDisplayEventTypes = HashSet<String>(displayEventTypes)
currDisplayEventTypes.addAll(types)
displayEventTypes = currDisplayEventTypes
}
fun removeDisplayEventTypes(types: Set<String>) {
val currDisplayEventTypes = HashSet<String>(displayEventTypes)
currDisplayEventTypes.removeAll(types)
displayEventTypes = currDisplayEventTypes
}
fun getDefaultNotificationSound(): String {
try {
return RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION)?.toString() ?: ""

View File

@ -37,6 +37,7 @@ val VIBRATE = "vibrate"
val REMINDER_SOUND = "reminder_sound"
val VIEW = "view"
val REMINDER_MINUTES = "reminder_minutes"
val DISPLAY_EVENT_TYPES = "display_event_types"
val GOOGLE_SYNC = "google_sync"
val SYNC_ACCOUNT_NAME = "sync_account_name"

View File

@ -194,7 +194,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Int {
val values = fillEventTypeValues(eventType)
return db.insert(TYPES_TABLE_NAME, null, values).toInt()
val insertedId = db.insert(TYPES_TABLE_NAME, null, values).toInt()
context.config.addDisplayEventType(insertedId.toString())
return insertedId
}
fun updateEventType(eventType: EventType): Int {
@ -262,6 +264,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (ids.contains(DBHelper.REGULAR_EVENT_ID))
deleteIds = ids.filter { it != DBHelper.REGULAR_EVENT_ID } as ArrayList<Int>
val deletedSet = HashSet<String>()
deleteIds.map { deletedSet.add(it.toString()) }
context.config.removeDisplayEventTypes(deletedSet)
if (deleteIds.isEmpty())
return

View File

@ -2,9 +2,10 @@
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/filter_events_list"
android:id="@+id/filter_event_types_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingTop="@dimen/medium_margin"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

View File

@ -5,25 +5,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
android:padding="@dimen/normal_margin">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/filter_event_type_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/filter_event_type_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/filter_event_type_checkbox"
android:layout_toRightOf="@+id/filter_event_type_checkbox"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/text_color"/>
android:paddingLeft="@dimen/small_margin"/>
<ImageView
android:id="@+id/filter_event_type_color"