open the app at pressing the alarm in the launcher

This commit is contained in:
tibbi 2018-03-13 18:08:48 +01:00
parent 53a373b3e9
commit 291220404e
2 changed files with 12 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import android.text.SpannableString
import android.text.style.RelativeSizeSpan
import android.widget.Toast
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.MainActivity
import com.simplemobiletools.clock.helpers.*
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.clock.models.AlarmSound
@ -125,15 +126,20 @@ fun Context.showRemainingTimeMessage(totalMinutes: Int) {
fun Context.setupAlarmClock(alarm: Alarm, triggerInSeconds: Int) {
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val targetMS = System.currentTimeMillis() + triggerInSeconds * 1000
val pendingIntent = getOpenAppIntent(alarm)
if (isLollipopPlus()) {
val info = AlarmManager.AlarmClockInfo(targetMS, pendingIntent)
alarmManager.setAlarmClock(info, pendingIntent)
val info = AlarmManager.AlarmClockInfo(targetMS, getOpenAppIntent())
alarmManager.setAlarmClock(info, getAlarmIntent(alarm))
}
}
fun Context.getOpenAppIntent(alarm: Alarm): PendingIntent {
fun Context.getOpenAppIntent(): PendingIntent {
val intent = Intent(this, MainActivity::class.java)
intent.putExtra(OPEN_TAB, TAB_ALARM)
return PendingIntent.getActivity(this, OPEN_ALARMS_TAB_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
fun Context.getAlarmIntent(alarm: Alarm): PendingIntent {
val intent = Intent(this, AlarmReceiver::class.java)
intent.putExtra(ALARM_ID, alarm.id)
return PendingIntent.getBroadcast(this, alarm.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
@ -141,7 +147,7 @@ fun Context.getOpenAppIntent(alarm: Alarm): PendingIntent {
fun Context.cancelAlarmClock(alarm: Alarm) {
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.cancel(getOpenAppIntent(alarm))
alarmManager.cancel(getAlarmIntent(alarm))
}
fun Context.hideNotification(id: Int) {

View File

@ -24,6 +24,7 @@ const val DAY_MINUTES = 1440
const val DEFAULT_MAX_ALARM_REMINDER_SECS = 300
const val DEFAULT_MAX_TIMER_REMINDER_SECS = 60
const val OPEN_ALARMS_TAB_INTENT_ID = 9996
const val UPDATE_WIDGET_INTENT_ID = 9997
const val OPEN_APP_INTENT_ID = 9998
const val TIMER_NOTIF_ID = 9999