From e4453a4e339bd632f98b748bb2005dad0fffa8c4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 24 Oct 2018 11:40:28 +0200 Subject: [PATCH] make pull-to-refresh for caldav calendars optional, disabled by default --- .../calendar/activities/MainActivity.kt | 2 +- .../calendar/activities/SettingsActivity.kt | 17 +++++++++++++- .../calendar/helpers/Config.kt | 4 ++++ .../calendar/helpers/Constants.kt | 1 + app/src/main/res/layout/activity_settings.xml | 23 +++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) 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 370f02510..769fbf9cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -133,7 +133,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { search_placeholder_2.setTextColor(config.textColor) calendar_fab.setColors(config.textColor, getAdjustedPrimaryColor(), config.backgroundColor) search_holder.background = ColorDrawable(config.backgroundColor) - swipe_refresh_layout.isEnabled = config.caldavSync + swipe_refresh_layout.isEnabled = config.caldavSync && config.pullToRefresh } override fun onPause() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index efb680b6c..6e62dad67 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -38,7 +38,6 @@ class SettingsActivity : SimpleActivity() { setContentView(R.layout.activity_settings) res = resources mStoredPrimaryColor = config.primaryColor - setupCaldavSync() } override fun onResume() { @@ -63,6 +62,9 @@ class SettingsActivity : SimpleActivity() { setupUseSameSnooze() setupLoopReminders() setupSnoozeTime() + setupCaldavSync() + setupManageSyncedCalendars() + setupPullToRefresh() setupDefaultReminder() setupDefaultReminder1() setupDefaultReminder2() @@ -163,7 +165,18 @@ class SettingsActivity : SimpleActivity() { } } } + } + private fun setupPullToRefresh() { + settings_caldav_pull_to_refresh_holder.beVisibleIf(config.caldavSync) + settings_caldav_pull_to_refresh.isChecked = config.pullToRefresh + settings_caldav_pull_to_refresh_holder.setOnClickListener { + settings_caldav_pull_to_refresh.toggle() + config.pullToRefresh = settings_caldav_pull_to_refresh.isChecked + } + } + + private fun setupManageSyncedCalendars() { settings_manage_synced_calendars_holder.beVisibleIf(config.caldavSync) settings_manage_synced_calendars_holder.setOnClickListener { showCalendarPicker() @@ -177,6 +190,7 @@ class SettingsActivity : SimpleActivity() { settings_caldav_sync.isChecked = false config.caldavSync = false settings_manage_synced_calendars_holder.beGone() + settings_caldav_pull_to_refresh_holder.beGone() config.getSyncedCalendarIdsAsList().forEach { CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong()) } @@ -194,6 +208,7 @@ class SettingsActivity : SimpleActivity() { } settings_manage_synced_calendars_holder.beVisibleIf(newCalendarIds.isNotEmpty()) + settings_caldav_pull_to_refresh_holder.beVisibleIf(newCalendarIds.isNotEmpty()) settings_caldav_sync.isChecked = newCalendarIds.isNotEmpty() config.caldavSync = newCalendarIds.isNotEmpty() if (settings_caldav_sync.isChecked) { 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 c7607cfe3..dcd3f76b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -162,4 +162,8 @@ class Config(context: Context) : BaseConfig(context) { var defaultReminder3: Int get() = prefs.getInt(DEFAULT_REMINDER_3, REMINDER_OFF) set(defaultReminder3) = prefs.edit().putInt(DEFAULT_REMINDER_3, defaultReminder3).apply() + + var pullToRefresh: Boolean + get() = prefs.getBoolean(PULL_TO_REFRESH, false) + set(pullToRefresh) = prefs.edit().putBoolean(PULL_TO_REFRESH, pullToRefresh).apply() } 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 b3f448ba3..af6b78735 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -64,6 +64,7 @@ const val USE_PREVIOUS_EVENT_REMINDERS = "use_previous_event_reminders" const val DEFAULT_REMINDER_1 = "default_reminder_1" const val DEFAULT_REMINDER_2 = "default_reminder_2" const val DEFAULT_REMINDER_3 = "default_reminder_3" +const val PULL_TO_REFRESH = "pull_to_refresh" // repeat_rule for monthly and yearly repetition const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index bd039ca27..6e84056c5 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -529,6 +529,29 @@ + + + + + +