From 846ee6a1b3a59f9099ce2b4146349e9864d39e46 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 18 May 2017 23:40:48 +0200 Subject: [PATCH] allow changing the minutes used at postponing by Snooze --- .../calendar/activities/SettingsActivity.kt | 16 +++++++++ .../calendar/dialogs/SnoozePickerDialog.kt | 34 ++++++++++++++++++ .../calendar/extensions/Context.kt | 4 +-- .../calendar/helpers/Config.kt | 4 +++ .../calendar/helpers/Constants.kt | 1 + .../calendar/services/SnoozeService.kt | 3 +- app/src/main/res/layout/activity_settings.xml | 35 +++++++++++++++++++ .../main/res/layout/dialog_snooze_picker.xml | 29 +++++++++++++++ app/src/main/res/values-de/strings.xml | 9 +++-- app/src/main/res/values-es/strings.xml | 9 +++-- app/src/main/res/values-fr/strings.xml | 9 +++-- app/src/main/res/values-hi-rIN/strings.xml | 9 +++-- app/src/main/res/values-hu/strings.xml | 9 +++-- app/src/main/res/values-it/strings.xml | 9 +++-- app/src/main/res/values-iw/strings.xml | 9 +++-- app/src/main/res/values-ja/strings.xml | 9 +++-- app/src/main/res/values-pt-rBR/strings.xml | 9 +++-- app/src/main/res/values-pt/strings.xml | 9 +++-- app/src/main/res/values-ru/strings.xml | 9 +++-- app/src/main/res/values-sk/strings.xml | 10 ++++-- app/src/main/res/values-sv/strings.xml | 9 +++-- app/src/main/res/values-tr/strings.xml | 9 +++-- app/src/main/res/values/strings.xml | 9 +++-- 23 files changed, 229 insertions(+), 33 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt create mode 100644 app/src/main/res/layout/dialog_snooze_picker.xml 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 f7e7cc8a2..c2891ca2e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -7,6 +7,7 @@ import android.net.Uri import android.os.Bundle import android.os.Parcelable import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.dialogs.SnoozePickerDialog import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getReminderText @@ -50,6 +51,7 @@ class SettingsActivity : SimpleActivity() { setupWeeklyEnd() setupVibrate() setupReminderSound() + setupSnoozeDelay() setupEventReminder() updateTextColors(settings_holder) checkPrimaryColor() @@ -184,6 +186,20 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupSnoozeDelay() { + updateSnoozeText() + settings_snooze_delay_holder.setOnClickListener { + SnoozePickerDialog(this, config.snoozeDelay) { + config.snoozeDelay = it + updateSnoozeText() + } + } + } + + private fun updateSnoozeText() { + settings_snooze_delay.text = resources.getQuantityString(R.plurals.minutes, config.snoozeDelay, config.snoozeDelay) + } + private fun setupEventReminder() { var reminderMinutes = config.defaultReminderMinutes settings_default_reminder.text = getReminderText(reminderMinutes) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt new file mode 100644 index 000000000..a7695f902 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/SnoozePickerDialog.kt @@ -0,0 +1,34 @@ +package com.simplemobiletools.calendar.dialogs + +import android.support.v7.app.AlertDialog +import android.view.ViewGroup +import android.view.WindowManager +import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.activities.SimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.value +import kotlinx.android.synthetic.main.dialog_snooze_picker.view.* + +class SnoozePickerDialog(val activity: SimpleActivity, val minutes: Int, val callback: (newMinutes: Int) -> Unit) + : AlertDialog.Builder(activity) { + init { + val view = (activity.layoutInflater.inflate(R.layout.dialog_snooze_picker, null) as ViewGroup).apply { + snooze_picker_label.text = snooze_picker_label.text.toString().capitalize() + snooze_picker.setText(minutes.toString()) + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ + val value = view.snooze_picker.value + val minutes = Integer.valueOf(if (value.isEmpty() || value == "0") "1" else value) + callback(minutes) + dismiss() + }) + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 793c1ceba..e211c3391 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -116,9 +116,9 @@ fun Context.getReminderText(minutes: Int) = when (minutes) { if (minutes % 1440 == 0) resources.getQuantityString(R.plurals.days, minutes / 1440, minutes / 1440) else if (minutes % 60 == 0) - resources.getQuantityString(R.plurals.hours, minutes / 60, minutes / 60) + resources.getQuantityString(R.plurals.hours_before, minutes / 60, minutes / 60) else - resources.getQuantityString(R.plurals.minutes, minutes, minutes) + resources.getQuantityString(R.plurals.minutes_before, minutes, minutes) } } 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 cb4fdeef5..fa1acfb7e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -53,6 +53,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(REMINDER_MINUTES, 10) set(mins) = prefs.edit().putInt(REMINDER_MINUTES, mins).apply() + var snoozeDelay: Int + get() = prefs.getInt(SNOOZE_DELAY, 10) + set(snoozeDelay) = prefs.edit().putInt(SNOOZE_DELAY, snoozeDelay).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() 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 287a437aa..fde11bf6e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -42,6 +42,7 @@ val REMINDER_MINUTES = "reminder_minutes" val DISPLAY_EVENT_TYPES = "display_event_types" val GOOGLE_SYNC = "google_sync" val SYNC_ACCOUNT_NAME = "sync_account_name" +val SNOOZE_DELAY = "snooze_delay" val letterIDs = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter, R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt index 11113d5a0..03f06176b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/services/SnoozeService.kt @@ -4,6 +4,7 @@ import android.app.IntentService import android.app.NotificationManager import android.content.Context import android.content.Intent +import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.scheduleEventIn import com.simplemobiletools.calendar.helpers.EVENT_ID @@ -14,7 +15,7 @@ class SnoozeService : IntentService("Snooze") { val event = dbHelper.getEventWithId(eventId) if (eventId != 0 && event != null) { - applicationContext.scheduleEventIn(System.currentTimeMillis() + 600000, event) + applicationContext.scheduleEventIn(System.currentTimeMillis() + applicationContext.config.snoozeDelay * 60000, event) val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager manager.cancel(eventId) } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 780d94fce..03f2a7499 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -255,6 +255,41 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 4ed234292..952c4dda7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -108,12 +108,12 @@ Tage Füge eine weitere Erinnerung hinzu - + %1$d Minute vorher %1$d Minuten vorher - + %1$d Stunde vorher %1$d Stunden vorher @@ -186,6 +186,11 @@ Google Sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Januar Februar März diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9fe669e29..a359edbf8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -108,12 +108,12 @@ días Agregar otro recordatorio - + %1$d minuto antes %1$d minutos antes - + %1$d hora antes %1$d horas antes @@ -186,6 +186,11 @@ Sincronización de Google Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Enero Febrero Marzo diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e695bbb90..87b4a7247 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -108,12 +108,12 @@ jours Ajouter un autre rappel - + %1$d minute avant %1$d minutes avant - + %1$d heure avant %1$d heures avant @@ -186,6 +186,11 @@ Synchronisation Google Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Janvier Février Mars diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index 43de1c805..a1fe5dda9 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -108,12 +108,12 @@ days Add another reminder - + %1$d minute before %1$d minutes before - + %1$d hour before %1$d hours before @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + जनवरी फरवरी मार्च diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 118d1b6b9..3e48e30bd 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -108,12 +108,12 @@ nap Add another reminder - + %1$d percel korábban %1$d percel korábban - + %1$d órával korábban %1$d órával korábban @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Január Február Március diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 0111a1b2b..a7d9728fd 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -108,12 +108,12 @@ days Add another reminder - + %1$d minute before %1$d minutes before - + %1$d hour before %1$d hours before @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Gennaio Febbraio Marzo diff --git a/app/src/main/res/values-iw/strings.xml b/app/src/main/res/values-iw/strings.xml index 0ecbeae60..5f86dc713 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -108,12 +108,12 @@ days Add another reminder - + %1$d minute before %1$d minutes before - + %1$d hour before %1$d hours before @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + ינואר פברואר מרץ diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4b424483b..88e754c55 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -108,12 +108,12 @@ Add another reminder - + %1$d minute before %1$d 分 前 - + %1$d hour before %1$d 時間 前 @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + 1月 2月 3月 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 3692e44d6..4dd38e19e 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -108,12 +108,12 @@ dias Adicionar outro lembrete - + %1$d minuto antes %1$d minutos antes - + %1$d hora antes %1$d horas antes @@ -186,6 +186,11 @@ Sincronização Google Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + janeiro fevereiro março diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 415b5e601..8c31ffbf6 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -108,12 +108,12 @@ dias Adicionar outro lembrete - + %1$d minuto antes %1$d minutos antes - + %1$d hora antes %1$d horas antes @@ -186,6 +186,11 @@ Sincronização Google Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + janeiro fevereiro março diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 2bd26aae8..cf93b5cec 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -108,12 +108,12 @@ дней Добавить ещё одно напоминание - + %1$d минута до события %1$d минут(-ы) до события - + %1$d час до события %1$d часа(-ов) до события @@ -186,6 +186,11 @@ Синхронизация с Google Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Январь Февраль Март diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index f014fe0ba..f4a4a7794 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -112,13 +112,13 @@ dni Pridať ďalšiu pripomienku - + %1$d minútu vopred %1$d minúty vopred %1$d minút vopred - + %1$d hodinu vopred %1$d hodiny vopred %1$d hodín vopred @@ -193,6 +193,12 @@ Google synchronizácia Posunúť pripomienku s Odložiť o + + %1$d minútu + %1$d minúty + %1$d minút + + Január Február Marec diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index ed59219dc..e5d5cd30e 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -108,12 +108,12 @@ dagar Add another reminder - + %1$d minute before %1$d minuter före - + %1$d hour before %1$d timmar före @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Januari Februari Mars diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 27c35ac36..a0e9b21d0 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -108,12 +108,12 @@ günler Başka bir hatırlatma ekle - + %1$d dakika önce %1$d dakika önce - + %1$d saat önce %1$d saat önce @@ -186,6 +186,11 @@ Google senkronizasyonu Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + Ocak Şubat Mart diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1dfc316ce..4e6f65fd4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -108,12 +108,12 @@ days Add another reminder - + %1$d minute before %1$d minutes before - + %1$d hour before %1$d hours before @@ -186,6 +186,11 @@ Google sync Postpone reminder with Snooze by + + %1$d minute + %1$d minutes + + January February March