use the Reminder activity for alarms too
This commit is contained in:
parent
4fa13283c8
commit
516341bf1b
|
@ -3,10 +3,9 @@ package com.simplemobiletools.clock.activities
|
|||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.config
|
||||
import com.simplemobiletools.clock.extensions.hideTimerNotification
|
||||
import com.simplemobiletools.clock.extensions.showOverLockscreen
|
||||
import com.simplemobiletools.clock.extensions.showTimerNotification
|
||||
import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
|
@ -14,6 +13,8 @@ import kotlinx.android.synthetic.main.activity_reminder.*
|
|||
|
||||
class ReminderActivity : SimpleActivity() {
|
||||
private val hideNotificationHandler = Handler()
|
||||
private var isAlarmReminder = false
|
||||
private var alarm: Alarm? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -21,25 +22,40 @@ class ReminderActivity : SimpleActivity() {
|
|||
showOverLockscreen()
|
||||
updateTextColors(reminder_holder)
|
||||
|
||||
reminder_title.text = getString(R.string.timer)
|
||||
reminder_text.text = getString(R.string.time_expired)
|
||||
val id = intent.getIntExtra(ALARM_ID, -1)
|
||||
isAlarmReminder = id != -1
|
||||
if (id != -1) {
|
||||
alarm = dbHelper.getAlarmWithId(id) ?: return
|
||||
}
|
||||
|
||||
reminder_title.text = getString(if (isAlarmReminder) R.string.alarm else R.string.timer)
|
||||
reminder_text.text = if (isAlarmReminder) getFormattedTime(alarm!!.timeInMinutes * 60, false, false) else getString(R.string.time_expired)
|
||||
reminder_stop.background = resources.getColoredDrawableWithColor(R.drawable.circle_background_filled, getAdjustedPrimaryColor())
|
||||
reminder_stop.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
Handler().postDelayed({
|
||||
showTimerNotification()
|
||||
if (isAlarmReminder) {
|
||||
showAlarmNotification(alarm!!)
|
||||
} else {
|
||||
showTimerNotification()
|
||||
}
|
||||
|
||||
val maxDuration = if (isAlarmReminder) config.alarmMaxReminderSecs else config.timerMaxReminderSecs
|
||||
hideNotificationHandler.postDelayed({
|
||||
finish()
|
||||
}, config.timerMaxReminderSecs * 1000L)
|
||||
}, maxDuration * 1000L)
|
||||
}, 1000L)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
hideTimerNotification()
|
||||
if (isAlarmReminder) {
|
||||
hideNotification(alarm?.id ?: 0)
|
||||
} else {
|
||||
hideTimerNotification()
|
||||
}
|
||||
hideNotificationHandler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import com.simplemobiletools.clock.activities.ReminderActivity
|
||||
import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||
|
||||
|
@ -18,7 +19,11 @@ class AlarmReceiver : BroadcastReceiver() {
|
|||
context.hideNotification(id)
|
||||
}, context.config.alarmMaxReminderSecs * 1000L)
|
||||
} else {
|
||||
|
||||
Intent(context, ReminderActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
putExtra(ALARM_ID, id)
|
||||
context.startActivity(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue