diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index b9eb87faf..330e66c84 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -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) { } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt index bbfa4ab94..f3acb62e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/FilterEventTypeAdapter.kt @@ -38,7 +38,8 @@ class FilterEventTypeAdapter(val activity: SimpleActivity, val mItems: List Unit) : AlertDialog.Builder(activity) { +class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> Unit) : AlertDialog.Builder(activity) { val dialog: AlertDialog? var eventTypes = ArrayList() 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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt index f36ac00f6..ac871697b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -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 + get() = prefs.getStringSet(DISPLAY_EVENT_TYPES, HashSet()) + 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(Arrays.asList(type))) + } + + fun addDisplayEventTypes(types: Set) { + val currDisplayEventTypes = HashSet(displayEventTypes) + currDisplayEventTypes.addAll(types) + displayEventTypes = currDisplayEventTypes + } + + fun removeDisplayEventTypes(types: Set) { + val currDisplayEventTypes = HashSet(displayEventTypes) + currDisplayEventTypes.removeAll(types) + displayEventTypes = currDisplayEventTypes + } + fun getDefaultNotificationSound(): String { try { return RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION)?.toString() ?: "" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index b1c6d905d..07138f8f7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -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" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 605f5019d..26436e02a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -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 + val deletedSet = HashSet() + deleteIds.map { deletedSet.add(it.toString()) } + context.config.removeDisplayEventTypes(deletedSet) if (deleteIds.isEmpty()) return diff --git a/app/src/main/res/layout/dialog_filter_events.xml b/app/src/main/res/layout/dialog_filter_event_types.xml similarity index 82% rename from app/src/main/res/layout/dialog_filter_events.xml rename to app/src/main/res/layout/dialog_filter_event_types.xml index 165c700f9..a77264d7b 100644 --- a/app/src/main/res/layout/dialog_filter_events.xml +++ b/app/src/main/res/layout/dialog_filter_event_types.xml @@ -2,9 +2,10 @@ diff --git a/app/src/main/res/layout/filter_event_type_view.xml b/app/src/main/res/layout/filter_event_type_view.xml index 17ab8c4fe..14091e41f 100644 --- a/app/src/main/res/layout/filter_event_type_view.xml +++ b/app/src/main/res/layout/filter_event_type_view.xml @@ -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"> - - + android:paddingLeft="@dimen/small_margin"/>