hide the timer notification if the Reminder activity is destroyed
This commit is contained in:
parent
f28fe26a4d
commit
50f5cf3cc5
|
@ -2,7 +2,9 @@ package com.simplemobiletools.clock.activities
|
|||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.clock.extensions.hideTimerNotification
|
||||
import com.simplemobiletools.clock.extensions.showOverLockscreen
|
||||
import com.simplemobiletools.clock.extensions.showTimerNotification
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.activity_reminder.*
|
||||
|
||||
|
@ -15,5 +17,11 @@ class ReminderActivity : SimpleActivity() {
|
|||
updateTextColors(reminder_holder)
|
||||
reminder_title.text = getString(R.string.timer)
|
||||
reminder_text.text = getString(R.string.time_expired)
|
||||
showTimerNotification()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
hideTimerNotification()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,6 +162,8 @@ fun Context.hideNotification(id: Int) {
|
|||
manager.cancel(id)
|
||||
}
|
||||
|
||||
fun Context.hideTimerNotification() = hideNotification(TIMER_NOTIF_ID)
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
val widgetsCnt = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java))
|
||||
if (widgetsCnt.isNotEmpty()) {
|
||||
|
@ -226,6 +228,13 @@ fun Context.rescheduleEnabledAlarms() {
|
|||
|
||||
fun Context.isScreenOn() = (getSystemService(Context.POWER_SERVICE) as PowerManager).isScreenOn
|
||||
|
||||
fun Context.showTimerNotification() {
|
||||
val pendingIntent = getOpenTimerTabIntent()
|
||||
val notification = getTimerNotification(pendingIntent)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.getTimerNotification(pendingIntent: PendingIntent): Notification {
|
||||
val channelId = "timer_channel"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simplemobiletools.clock.fragments
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.media.AudioManager
|
||||
|
@ -18,7 +16,6 @@ import com.simplemobiletools.clock.activities.SimpleActivity
|
|||
import com.simplemobiletools.clock.dialogs.MyTimePickerDialogDialog
|
||||
import com.simplemobiletools.clock.dialogs.SelectAlarmSoundDialog
|
||||
import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.TIMER_NOTIF_ID
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.fragment_timer.view.*
|
||||
|
||||
|
@ -48,6 +45,7 @@ class TimerFragment : Fragment() {
|
|||
}
|
||||
|
||||
timer_reset.setOnClickListener {
|
||||
context!!.hideTimerNotification()
|
||||
resetTimer()
|
||||
}
|
||||
|
||||
|
@ -129,7 +127,7 @@ class TimerFragment : Fragment() {
|
|||
private fun togglePlayPause() {
|
||||
isRunning = !isRunning
|
||||
updateIcons()
|
||||
hideTimerNotification()
|
||||
context!!.hideTimerNotification()
|
||||
|
||||
if (isRunning) {
|
||||
updateHandler.post(updateRunnable)
|
||||
|
@ -154,7 +152,6 @@ class TimerFragment : Fragment() {
|
|||
currentTicks = 0
|
||||
totalTicks = 0
|
||||
initialSecs = context!!.config.timerSeconds
|
||||
hideTimerNotification()
|
||||
updateDisplayedText()
|
||||
updateIcons()
|
||||
view.timer_reset.beGone()
|
||||
|
@ -174,13 +171,9 @@ class TimerFragment : Fragment() {
|
|||
view.timer_time.text = formattedDuration
|
||||
if (diff == 0) {
|
||||
if (context?.isScreenOn() == true) {
|
||||
val pendingIntent = context!!.getOpenTimerTabIntent()
|
||||
val notification = context!!.getTimerNotification(pendingIntent)
|
||||
val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
||||
|
||||
context!!.showTimerNotification()
|
||||
Handler().postDelayed({
|
||||
hideTimerNotification()
|
||||
context?.hideTimerNotification()
|
||||
}, context?.config!!.timerMaxReminderSecs * 1000L)
|
||||
} else {
|
||||
Intent(context, ReminderActivity::class.java).apply {
|
||||
|
@ -191,10 +184,6 @@ class TimerFragment : Fragment() {
|
|||
return true
|
||||
}
|
||||
|
||||
private fun hideTimerNotification() {
|
||||
context?.hideNotification(TIMER_NOTIF_ID)
|
||||
}
|
||||
|
||||
private val updateRunnable = object : Runnable {
|
||||
override fun run() {
|
||||
if (isRunning) {
|
||||
|
|
Loading…
Reference in New Issue