remove Reminder activity on notification swipe
This commit is contained in:
parent
516341bf1b
commit
ee5e15c384
|
@ -40,7 +40,9 @@
|
||||||
android:name=".activities.MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
android:launchMode="singleTask"/>
|
android:launchMode="singleTask"/>
|
||||||
|
|
||||||
<activity android:name=".activities.ReminderActivity"/>
|
<activity
|
||||||
|
android:name=".activities.ReminderActivity"
|
||||||
|
android:launchMode="singleTask"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SettingsActivity"
|
android:name=".activities.SettingsActivity"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.clock.activities
|
package com.simplemobiletools.clock.activities
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
|
@ -39,7 +40,7 @@ class ReminderActivity : SimpleActivity() {
|
||||||
if (isAlarmReminder) {
|
if (isAlarmReminder) {
|
||||||
showAlarmNotification(alarm!!)
|
showAlarmNotification(alarm!!)
|
||||||
} else {
|
} else {
|
||||||
showTimerNotification()
|
showTimerNotification(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val maxDuration = if (isAlarmReminder) config.alarmMaxReminderSecs else config.timerMaxReminderSecs
|
val maxDuration = if (isAlarmReminder) config.alarmMaxReminderSecs else config.timerMaxReminderSecs
|
||||||
|
@ -49,6 +50,11 @@ class ReminderActivity : SimpleActivity() {
|
||||||
}, 1000L)
|
}, 1000L)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
if (isAlarmReminder) {
|
if (isAlarmReminder) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import android.text.SpannableString
|
||||||
import android.text.style.RelativeSizeSpan
|
import android.text.style.RelativeSizeSpan
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
|
import com.simplemobiletools.clock.activities.ReminderActivity
|
||||||
import com.simplemobiletools.clock.activities.SnoozeReminderActivity
|
import com.simplemobiletools.clock.activities.SnoozeReminderActivity
|
||||||
import com.simplemobiletools.clock.activities.SplashActivity
|
import com.simplemobiletools.clock.activities.SplashActivity
|
||||||
import com.simplemobiletools.clock.helpers.*
|
import com.simplemobiletools.clock.helpers.*
|
||||||
|
@ -243,15 +244,15 @@ fun Context.showAlarmNotification(alarm: Alarm) {
|
||||||
scheduleNextAlarm(alarm, false)
|
scheduleNextAlarm(alarm, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.showTimerNotification() {
|
fun Context.showTimerNotification(addDeleteIntent: Boolean) {
|
||||||
val pendingIntent = getOpenTimerTabIntent()
|
val pendingIntent = getOpenTimerTabIntent()
|
||||||
val notification = getTimerNotification(pendingIntent)
|
val notification = getTimerNotification(pendingIntent, addDeleteIntent)
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
notificationManager.notify(TIMER_NOTIF_ID, notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
fun Context.getTimerNotification(pendingIntent: PendingIntent): Notification {
|
fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent: Boolean): Notification {
|
||||||
val channelId = "timer_channel"
|
val channelId = "timer_channel"
|
||||||
if (isOreoPlus()) {
|
if (isOreoPlus()) {
|
||||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
@ -265,6 +266,7 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent): Notification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val reminderActivityIntent = getReminderActivityIntent()
|
||||||
val builder = NotificationCompat.Builder(this)
|
val builder = NotificationCompat.Builder(this)
|
||||||
.setContentTitle(getString(R.string.timer))
|
.setContentTitle(getString(R.string.timer))
|
||||||
.setContentText(getString(R.string.time_expired))
|
.setContentText(getString(R.string.time_expired))
|
||||||
|
@ -275,7 +277,11 @@ fun Context.getTimerNotification(pendingIntent: PendingIntent): Notification {
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setSound(Uri.parse(config.timerSoundUri), AudioManager.STREAM_SYSTEM)
|
.setSound(Uri.parse(config.timerSoundUri), AudioManager.STREAM_SYSTEM)
|
||||||
.setChannelId(channelId)
|
.setChannelId(channelId)
|
||||||
.addAction(R.drawable.ic_cross, getString(R.string.dismiss), getTimerPendingIntent())
|
.addAction(R.drawable.ic_cross, getString(R.string.dismiss), if (addDeleteIntent) reminderActivityIntent else getTimerPendingIntent())
|
||||||
|
|
||||||
|
if (addDeleteIntent) {
|
||||||
|
builder.setDeleteIntent(reminderActivityIntent)
|
||||||
|
}
|
||||||
|
|
||||||
if (isLollipopPlus()) {
|
if (isLollipopPlus()) {
|
||||||
builder.setVisibility(Notification.VISIBILITY_PUBLIC)
|
builder.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
|
@ -347,3 +353,8 @@ fun Context.getSnoozePendingIntent(alarm: Alarm): PendingIntent {
|
||||||
PendingIntent.getActivity(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
PendingIntent.getActivity(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getReminderActivityIntent(): PendingIntent {
|
||||||
|
val intent = Intent(this, ReminderActivity::class.java)
|
||||||
|
return PendingIntent.getActivity(this, REMINDER_ACTIVITY_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ class TimerFragment : Fragment() {
|
||||||
view.timer_time.text = formattedDuration
|
view.timer_time.text = formattedDuration
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
if (context?.isScreenOn() == true) {
|
if (context?.isScreenOn() == true) {
|
||||||
context!!.showTimerNotification()
|
context!!.showTimerNotification(false)
|
||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
context?.hideTimerNotification()
|
context?.hideTimerNotification()
|
||||||
}, context?.config!!.timerMaxReminderSecs * 1000L)
|
}, context?.config!!.timerMaxReminderSecs * 1000L)
|
||||||
|
|
|
@ -23,6 +23,7 @@ const val DAY_MINUTES = 1440
|
||||||
const val DEFAULT_MAX_ALARM_REMINDER_SECS = 300
|
const val DEFAULT_MAX_ALARM_REMINDER_SECS = 300
|
||||||
const val DEFAULT_MAX_TIMER_REMINDER_SECS = 60
|
const val DEFAULT_MAX_TIMER_REMINDER_SECS = 60
|
||||||
|
|
||||||
|
const val REMINDER_ACTIVITY_INTENT_ID = 9995
|
||||||
const val OPEN_ALARMS_TAB_INTENT_ID = 9996
|
const val OPEN_ALARMS_TAB_INTENT_ID = 9996
|
||||||
const val UPDATE_WIDGET_INTENT_ID = 9997
|
const val UPDATE_WIDGET_INTENT_ID = 9997
|
||||||
const val OPEN_APP_INTENT_ID = 9998
|
const val OPEN_APP_INTENT_ID = 9998
|
||||||
|
|
Loading…
Reference in New Issue