allow customizing max reminder length at Alarm

This commit is contained in:
tibbi 2018-03-11 19:27:41 +01:00
parent b4bb2172c6
commit afa4599f5e
7 changed files with 68 additions and 11 deletions

View file

@ -41,7 +41,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.15.11'
implementation 'com.simplemobiletools:commons:3.15.12'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.shawnlin:number-picker:2.4.6'

View file

@ -3,7 +3,9 @@ package com.simplemobiletools.clock.activities
import android.os.Bundle
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.helpers.DEFAULT_MAX_ALARM_REMINDER_SECS
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
@ -22,6 +24,7 @@ class SettingsActivity : SimpleActivity() {
setupPreventPhoneFromSleeping()
setupShowSeconds()
setupDisplayOtherTimeZones()
setupAlarmMaxReminder()
setupUseSameSnooze()
setupSnoozeTime()
setupVibrate()
@ -84,6 +87,16 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupAlarmMaxReminder() {
updateAlarmMaxReminderText()
settings_alarm_max_reminder_holder.setOnClickListener {
showPickSecondsDialog(config.alarmMaxReminderSecs, true, true) {
config.alarmMaxReminderSecs = if (it != 0) it else DEFAULT_MAX_ALARM_REMINDER_SECS
updateAlarmMaxReminderText()
}
}
}
private fun setupUseSameSnooze() {
settings_snooze_time_holder.beVisibleIf(config.useSameSnooze)
settings_use_same_snooze.isChecked = config.useSameSnooze
@ -97,8 +110,8 @@ class SettingsActivity : SimpleActivity() {
private fun setupSnoozeTime() {
updateSnoozeText()
settings_snooze_time_holder.setOnClickListener {
showPickIntervalDialog(config.snoozeTime, true) {
config.snoozeTime = it
showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true) {
config.snoozeTime = it / MINUTE_SECONDS
updateSnoozeText()
}
}
@ -112,6 +125,10 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun updateAlarmMaxReminderText() {
settings_alarm_max_reminder.text = formatSecondsToTimeString(config.alarmMaxReminderSecs)
}
private fun updateSnoozeText() {
settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime)
}

View file

@ -7,7 +7,8 @@ import com.simplemobiletools.clock.extensions.dbHelper
import com.simplemobiletools.clock.extensions.hideNotification
import com.simplemobiletools.clock.extensions.setupAlarmClock
import com.simplemobiletools.clock.helpers.ALARM_ID
import com.simplemobiletools.commons.extensions.showPickIntervalDialog
import com.simplemobiletools.commons.extensions.showPickSecondsDialog
import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
class SnoozeReminderActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -15,9 +16,9 @@ class SnoozeReminderActivity : AppCompatActivity() {
val id = intent.getIntExtra(ALARM_ID, -1)
val alarm = dbHelper.getAlarmWithId(id) ?: return
hideNotification(id)
showPickIntervalDialog(config.snoozeTime, true, cancelCallback = { dialogCancelled() }) {
config.snoozeTime = it
setupAlarmClock(alarm, it * 60)
showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true, cancelCallback = { dialogCancelled() }) {
config.snoozeTime = it * 60
setupAlarmClock(alarm, it)
finishActivity()
}
}

View file

@ -41,4 +41,8 @@ class Config(context: Context) : BaseConfig(context) {
var timerSoundTitle: String
get() = prefs.getString(TIMER_SOUND_TITLE, context.getDefaultAlarmTitle())
set(timerSoundTitle) = prefs.edit().putString(TIMER_SOUND_TITLE, timerSoundTitle).apply()
var alarmMaxReminderSecs: Int
get() = prefs.getInt(ALARM_MAX_REMINDER_SECS, DEFAULT_MAX_ALARM_REMINDER_SECS)
set(alarmMaxReminderSecs) = prefs.edit().putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs).apply()
}

View file

@ -11,6 +11,7 @@ const val TIMER_SECONDS = "timer_seconds"
const val TIMER_VIBRATE = "timer_vibrate"
const val TIMER_SOUND_URI = "timer_sound_uri"
const val TIMER_SOUND_TITLE = "timer_sound_title"
const val ALARM_MAX_REMINDER_SECS = "alarm_max_reminder_secs"
const val TABS_COUNT = 4
const val EDITED_TIME_ZONE_SEPARATOR = ":"
@ -18,6 +19,7 @@ const val ALARM_ID = "alarm_id"
const val DEFAULT_ALARM_MINUTES = 480
const val DAY_MINUTES = 1440
const val TIMER_NOTIF_ID = 9999
const val DEFAULT_MAX_ALARM_REMINDER_SECS = 300
const val SORT_BY_LAP = 1
const val SORT_BY_LAP_TIME = 2

View file

@ -24,8 +24,6 @@ import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.commons.helpers.isOreoPlus
class AlarmReceiver : BroadcastReceiver() {
private val NOTIFICATION_DISAPPEAR_MS = 600000L
override fun onReceive(context: Context, intent: Intent) {
val id = intent.getIntExtra(ALARM_ID, -1)
val alarm = context.dbHelper.getAlarmWithId(id) ?: return
@ -38,7 +36,7 @@ class AlarmReceiver : BroadcastReceiver() {
Handler().postDelayed({
context.hideNotification(id)
}, NOTIFICATION_DISAPPEAR_MS)
}, context.config.alarmMaxReminderSecs * 1000L)
}
@SuppressLint("NewApi")
@ -73,7 +71,7 @@ class AlarmReceiver : BroadcastReceiver() {
}
if (alarm.vibrate) {
val vibrateArray = LongArray((NOTIFICATION_DISAPPEAR_MS / 500).toInt()) { 500 }
val vibrateArray = LongArray(context.config.alarmMaxReminderSecs * 2) { 500 }
builder.setVibrate(vibrateArray)
}

View file

@ -184,6 +184,41 @@
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>
<RelativeLayout
android:id="@+id/settings_alarm_max_reminder_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/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_alarm_max_reminder_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/settings_alarm_max_reminder"
android:layout_toStartOf="@+id/settings_alarm_max_reminder"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/max_reminder_length"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_alarm_max_reminder"
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_use_same_snooze_holder"
android:layout_width="match_parent"