store filtered event types in db
This commit is contained in:
parent
a8652b06e0
commit
57d2ef24ac
|
@ -16,7 +16,7 @@ import com.simplemobiletools.calendar.adapters.MyMonthPagerAdapter
|
||||||
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
|
import com.simplemobiletools.calendar.adapters.MyWeekPagerAdapter
|
||||||
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
|
import com.simplemobiletools.calendar.adapters.MyYearPagerAdapter
|
||||||
import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
|
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.dialogs.ImportEventsDialog
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
|
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
|
||||||
|
@ -129,7 +129,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showFilterDialog() {
|
private fun showFilterDialog() {
|
||||||
FilterEventsDialog(this) {
|
FilterEventTypesDialog(this) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ class FilterEventTypeAdapter(val activity: SimpleActivity, val mItems: List<Even
|
||||||
class ViewHolder(val activity: SimpleActivity, view: View) : RecyclerView.ViewHolder(view) {
|
class ViewHolder(val activity: SimpleActivity, view: View) : RecyclerView.ViewHolder(view) {
|
||||||
fun bindView(eventType: EventType): View {
|
fun bindView(eventType: EventType): View {
|
||||||
itemView.apply {
|
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_color.setBackgroundWithStroke(eventType.color, activity.config.backgroundColor)
|
||||||
filter_event_type_holder.setOnClickListener { filter_event_type_checkbox.toggle() }
|
filter_event_type_holder.setOnClickListener { filter_event_type_checkbox.toggle() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,23 +8,18 @@ import com.simplemobiletools.calendar.adapters.FilterEventTypeAdapter
|
||||||
import com.simplemobiletools.calendar.helpers.DBHelper
|
import com.simplemobiletools.calendar.helpers.DBHelper
|
||||||
import com.simplemobiletools.calendar.models.EventType
|
import com.simplemobiletools.calendar.models.EventType
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
|
||||||
import kotlinx.android.synthetic.main.dialog_filter_events.view.*
|
|
||||||
import java.util.*
|
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?
|
val dialog: AlertDialog?
|
||||||
var eventTypes = ArrayList<EventType>()
|
var eventTypes = ArrayList<EventType>()
|
||||||
|
|
||||||
init {
|
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 {
|
DBHelper.newInstance(activity).getEventTypes {
|
||||||
eventTypes = it
|
eventTypes = it
|
||||||
view.filter_events_list.adapter = FilterEventTypeAdapter(activity, it)
|
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it)
|
||||||
|
|
||||||
activity.runOnUiThread {
|
|
||||||
activity.updateTextColors(view.filter_events_list)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
|
@ -45,6 +45,10 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
get() = prefs.getInt(REMINDER_MINUTES, 10)
|
get() = prefs.getInt(REMINDER_MINUTES, 10)
|
||||||
set(mins) = prefs.edit().putInt(REMINDER_MINUTES, mins).apply()
|
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
|
var googleSync: Boolean
|
||||||
get() = prefs.getBoolean(GOOGLE_SYNC, false)
|
get() = prefs.getBoolean(GOOGLE_SYNC, false)
|
||||||
set(googleSync) = prefs.edit().putBoolean(GOOGLE_SYNC, googleSync).apply()
|
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, "")
|
get() = prefs.getString(SYNC_ACCOUNT_NAME, "")
|
||||||
set(syncAccountName) = prefs.edit().putString(SYNC_ACCOUNT_NAME, syncAccountName).apply()
|
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 {
|
fun getDefaultNotificationSound(): String {
|
||||||
try {
|
try {
|
||||||
return RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION)?.toString() ?: ""
|
return RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION)?.toString() ?: ""
|
||||||
|
|
|
@ -37,6 +37,7 @@ val VIBRATE = "vibrate"
|
||||||
val REMINDER_SOUND = "reminder_sound"
|
val REMINDER_SOUND = "reminder_sound"
|
||||||
val VIEW = "view"
|
val VIEW = "view"
|
||||||
val REMINDER_MINUTES = "reminder_minutes"
|
val REMINDER_MINUTES = "reminder_minutes"
|
||||||
|
val DISPLAY_EVENT_TYPES = "display_event_types"
|
||||||
val GOOGLE_SYNC = "google_sync"
|
val GOOGLE_SYNC = "google_sync"
|
||||||
val SYNC_ACCOUNT_NAME = "sync_account_name"
|
val SYNC_ACCOUNT_NAME = "sync_account_name"
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Int {
|
fun insertEventType(eventType: EventType, db: SQLiteDatabase = mDb): Int {
|
||||||
val values = fillEventTypeValues(eventType)
|
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 {
|
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))
|
if (ids.contains(DBHelper.REGULAR_EVENT_ID))
|
||||||
deleteIds = ids.filter { it != DBHelper.REGULAR_EVENT_ID } as ArrayList<Int>
|
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())
|
if (deleteIds.isEmpty())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:overScrollMode="never"
|
android:overScrollMode="never"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
|
@ -5,25 +5,14 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:padding="@dimen/activity_margin">
|
android:padding="@dimen/normal_margin">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
android:id="@+id/filter_event_type_checkbox"
|
android:id="@+id/filter_event_type_checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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:clickable="false"
|
||||||
android:paddingLeft="@dimen/medium_margin"
|
android:paddingLeft="@dimen/small_margin"/>
|
||||||
android:paddingRight="@dimen/medium_margin"
|
|
||||||
android:text="@string/text_color"/>
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/filter_event_type_color"
|
android:id="@+id/filter_event_type_color"
|
||||||
|
|
Loading…
Reference in New Issue