properly handle no alarm set

This commit is contained in:
tibbi 2018-04-11 18:00:16 +02:00
parent a8e512b551
commit b0cfa4efd2
1 changed files with 4 additions and 4 deletions

View File

@ -196,8 +196,8 @@ fun Context.formatTo12HourFormat(showSeconds: Boolean, hours: Int, minutes: Int,
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun Context.getNextAlarm(): String {
return if (isLollipopPlus()) {
val milliseconds = (getSystemService(Context.ALARM_SERVICE) as AlarmManager).nextAlarmClock.triggerTime
if (isLollipopPlus()) {
val milliseconds = (getSystemService(Context.ALARM_SERVICE) as AlarmManager).nextAlarmClock?.triggerTime ?: return ""
val calendar = Calendar.getInstance()
val isDaylightSavingActive = TimeZone.getDefault().inDaylightTime(Date())
var offset = calendar.timeZone.rawOffset
@ -209,9 +209,9 @@ fun Context.getNextAlarm(): String {
val dayOfWeekIndex = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
val dayOfWeek = resources.getStringArray(R.array.week_days_short)[dayOfWeekIndex]
val formatted = getFormattedTime(((milliseconds + offset) / 1000L).toInt(), false, false)
"$dayOfWeek $formatted"
return "$dayOfWeek $formatted"
} else {
Settings.System.getString(contentResolver, Settings.System.NEXT_ALARM_FORMATTED) ?: ""
return Settings.System.getString(contentResolver, Settings.System.NEXT_ALARM_FORMATTED) ?: ""
}
}