handle Snooze with a constant interval
This commit is contained in:
parent
539be21489
commit
241f527412
5 changed files with 119 additions and 27 deletions
|
@ -41,7 +41,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.15.4'
|
||||
implementation 'com.simplemobiletools:commons:3.15.6'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package com.simplemobiletools.clock.activities
|
|||
import android.os.Bundle
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.extensions.useEnglishToggled
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
import java.util.*
|
||||
|
||||
|
@ -25,13 +22,15 @@ class SettingsActivity : SimpleActivity() {
|
|||
setupPreventPhoneFromSleeping()
|
||||
setupShowSeconds()
|
||||
setupDisplayOtherTimeZones()
|
||||
setupUseSameSnooze()
|
||||
setupSnoozeTime()
|
||||
updateTextColors(settings_holder)
|
||||
setupSectionColors()
|
||||
}
|
||||
|
||||
private fun setupSectionColors() {
|
||||
val adjustedPrimaryColor = getAdjustedPrimaryColor()
|
||||
arrayListOf(clock_tab_label).forEach {
|
||||
arrayListOf(clock_tab_label, alarm_tab_label).forEach {
|
||||
it.setTextColor(adjustedPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
@ -83,4 +82,28 @@ class SettingsActivity : SimpleActivity() {
|
|||
config.displayOtherTimeZones = settings_display_other_timezones.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupUseSameSnooze() {
|
||||
settings_snooze_time_holder.beVisibleIf(config.useSameSnooze)
|
||||
settings_use_same_snooze.isChecked = config.useSameSnooze
|
||||
settings_use_same_snooze_holder.setOnClickListener {
|
||||
settings_use_same_snooze.toggle()
|
||||
config.useSameSnooze = settings_use_same_snooze.isChecked
|
||||
settings_snooze_time_holder.beVisibleIf(config.useSameSnooze)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSnoozeTime() {
|
||||
updateSnoozeText()
|
||||
settings_snooze_time_holder.setOnClickListener {
|
||||
showPickIntervalDialog(config.snoozeTime, true) {
|
||||
config.snoozeTime = it
|
||||
updateSnoozeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSnoozeText() {
|
||||
settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.simplemobiletools.clock.models.Alarm
|
|||
import com.simplemobiletools.clock.models.AlarmSound
|
||||
import com.simplemobiletools.clock.models.MyTimeZone
|
||||
import com.simplemobiletools.clock.receivers.AlarmReceiver
|
||||
import com.simplemobiletools.commons.extensions.formatMinutesToTimeString
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.isLollipopPlus
|
||||
import java.util.*
|
||||
|
@ -105,27 +106,8 @@ fun Context.scheduleNextAlarm(alarm: Alarm, showToast: Boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.showRemainingTimeMessage(triggerInMinutes: Int) {
|
||||
val days = triggerInMinutes / DAY_MINUTES
|
||||
val hours = (triggerInMinutes % DAY_MINUTES) / 60
|
||||
val minutes = triggerInMinutes % 60
|
||||
val timesString = StringBuilder()
|
||||
if (days > 0) {
|
||||
val daysString = String.format(resources.getQuantityString(R.plurals.days, days, days))
|
||||
timesString.append("$daysString, ")
|
||||
}
|
||||
|
||||
if (hours > 0) {
|
||||
val hoursString = String.format(resources.getQuantityString(R.plurals.hours, hours, hours))
|
||||
timesString.append("$hoursString, ")
|
||||
}
|
||||
|
||||
if (minutes > 0) {
|
||||
val minutesString = String.format(resources.getQuantityString(R.plurals.minutes, minutes, minutes))
|
||||
timesString.append(minutesString)
|
||||
}
|
||||
|
||||
val fullString = String.format(getString(R.string.alarm_goes_off_in), timesString.toString().trim().trimEnd(','))
|
||||
fun Context.showRemainingTimeMessage(totalMinutes: Int) {
|
||||
val fullString = String.format(getString(R.string.alarm_goes_off_in), formatMinutesToTimeString(totalMinutes))
|
||||
toast(fullString, Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
package com.simplemobiletools.clock.services
|
||||
|
||||
import android.app.IntentService
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.dbHelper
|
||||
import com.simplemobiletools.clock.extensions.setupAlarmClock
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
|
||||
class SnoozeService : IntentService("Snooze") {
|
||||
override fun onHandleIntent(intent: Intent) {
|
||||
val id = intent.getIntExtra(ALARM_ID, -1)
|
||||
val alarm = dbHelper.getAlarmWithId(id) ?: return
|
||||
setupAlarmClock(alarm, config.snoozeTime * 60)
|
||||
|
||||
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.cancel(alarm.id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,5 +165,81 @@
|
|||
android:text="@string/display_other_time_zones"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/alarm_tab_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:background="@color/divider_grey"
|
||||
android:importantForAccessibility="no"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/alarm_tab_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/bigger_margin"
|
||||
android:layout_marginStart="@dimen/bigger_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:text="@string/alarm_tab"
|
||||
android:textAllCaps="true"
|
||||
android:textSize="@dimen/smaller_text_size"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_use_same_snooze_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_use_same_snooze"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/use_same_snooze"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_snooze_time_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_snooze_time_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/settings_snooze_time"
|
||||
android:layout_toStartOf="@+id/settings_snooze_time"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/snooze_time"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_snooze_time"
|
||||
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>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
Loading…
Reference in a new issue