allow changing the minutes used at postponing by Snooze

This commit is contained in:
tibbi 2017-05-18 23:40:48 +02:00
parent bb475eea5f
commit 846ee6a1b3
23 changed files with 229 additions and 33 deletions

View File

@ -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)

View File

@ -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()
})
}
}
}

View File

@ -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)
}
}

View File

@ -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<String>
get() = prefs.getStringSet(DISPLAY_EVENT_TYPES, HashSet<String>())
set(displayEventTypes) = prefs.edit().remove(DISPLAY_EVENT_TYPES).putStringSet(DISPLAY_EVENT_TYPES, displayEventTypes).apply()

View File

@ -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)

View File

@ -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)
}

View File

@ -255,6 +255,41 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_snooze_delay_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/bigger_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_snooze_delay_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/settings_snooze_delay"
android:layout_toStartOf="@+id/settings_snooze_delay"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/snooze_delay"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_snooze_delay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_default_reminder_holder"
android:layout_width="match_parent"

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snooze_picker_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/big_margin"
android:paddingRight="@dimen/big_margin"
android:paddingTop="@dimen/big_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/snooze_picker_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:text="@string/minutes_raw"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/snooze_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="number"
android:maxLength="5"
android:paddingTop="@dimen/normal_margin"/>
</LinearLayout>

View File

@ -108,12 +108,12 @@
<string name="days_raw">Tage</string>
<string name="add_another_reminder">Füge eine weitere Erinnerung hinzu</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d Minute vorher</item>
<item quantity="other">%1$d Minuten vorher</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d Stunde vorher</item>
<item quantity="other">%1$d Stunden vorher</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google Sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Januar</string>
<string name="february">Februar</string>
<string name="march">März</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">días</string>
<string name="add_another_reminder">Agregar otro recordatorio</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minuto antes</item>
<item quantity="other">%1$d minutos antes</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hora antes</item>
<item quantity="other">%1$d horas antes</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Sincronización de Google</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Enero</string>
<string name="february">Febrero</string>
<string name="march">Marzo</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">jours</string>
<string name="add_another_reminder">Ajouter un autre rappel</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute avant</item>
<item quantity="other">%1$d minutes avant</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d heure avant</item>
<item quantity="other">%1$d heures avant</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Synchronisation Google</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Janvier</string>
<string name="february">Février</string>
<string name="march">Mars</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">days</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">जनवरी</string>
<string name="february">फरवरी</string>
<string name="march">मार्च</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">nap</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d percel korábban</item>
<item quantity="other">%1$d percel korábban</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d órával korábban</item>
<item quantity="other">%1$d órával korábban</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Január</string>
<string name="february">Február</string>
<string name="march">Március</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">days</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Gennaio</string>
<string name="february">Febbraio</string>
<string name="march">Marzo</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">days</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">ינואר</string>
<string name="february">פברואר</string>
<string name="march">מרץ</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw"></string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d 分 前</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d 時間 前</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">1月</string>
<string name="february">2月</string>
<string name="march">3月</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">dias</string>
<string name="add_another_reminder">Adicionar outro lembrete</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minuto antes</item>
<item quantity="other">%1$d minutos antes</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hora antes</item>
<item quantity="other">%1$d horas antes</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Sincronização Google</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">janeiro</string>
<string name="february">fevereiro</string>
<string name="march">março</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">dias</string>
<string name="add_another_reminder">Adicionar outro lembrete</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minuto antes</item>
<item quantity="other">%1$d minutos antes</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hora antes</item>
<item quantity="other">%1$d horas antes</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Sincronização Google</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">janeiro</string>
<string name="february">fevereiro</string>
<string name="march">março</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">дней</string>
<string name="add_another_reminder">Добавить ещё одно напоминание</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d минута до события</item>
<item quantity="other">%1$d минут(-ы) до события</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d час до события</item>
<item quantity="other">%1$d часа(-ов) до события</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Синхронизация с Google</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Январь</string>
<string name="february">Февраль</string>
<string name="march">Март</string>

View File

@ -112,13 +112,13 @@
<string name="days_raw">dni</string>
<string name="add_another_reminder">Pridať ďalšiu pripomienku</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minútu vopred</item>
<item quantity="few">%1$d minúty vopred</item>
<item quantity="other">%1$d minút vopred</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hodinu vopred</item>
<item quantity="few">%1$d hodiny vopred</item>
<item quantity="other">%1$d hodín vopred</item>
@ -193,6 +193,12 @@
<string name="google_sync">Google synchronizácia</string>
<string name="snooze_delay">Posunúť pripomienku s Odložiť o</string>
<plurals name="minutes">
<item quantity="one">%1$d minútu</item>
<item quantity="few">%1$d minúty</item>
<item quantity="other">%1$d minút</item>
</plurals>
<string name="january">Január</string>
<string name="february">Február</string>
<string name="march">Marec</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">dagar</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minuter före</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d timmar före</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Januari</string>
<string name="february">Februari</string>
<string name="march">Mars</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">günler</string>
<string name="add_another_reminder">Başka bir hatırlatma ekle</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d dakika önce</item>
<item quantity="other">%1$d dakika önce</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d saat önce</item>
<item quantity="other">%1$d saat önce</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google senkronizasyonu</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">Ocak</string>
<string name="february">Şubat</string>
<string name="march">Mart</string>

View File

@ -108,12 +108,12 @@
<string name="days_raw">days</string>
<string name="add_another_reminder">Add another reminder</string>
<plurals name="minutes">
<plurals name="minutes_before">
<item quantity="one">%1$d minute before</item>
<item quantity="other">%1$d minutes before</item>
</plurals>
<plurals name="hours">
<plurals name="hours_before">
<item quantity="one">%1$d hour before</item>
<item quantity="other">%1$d hours before</item>
</plurals>
@ -186,6 +186,11 @@
<string name="google_sync">Google sync</string>
<string name="snooze_delay">Postpone reminder with Snooze by</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<string name="january">January</string>
<string name="february">February</string>
<string name="march">March</string>