mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-02-09 00:18:44 +01:00
properly handle no alarm set
This commit is contained in:
parent
a8e512b551
commit
b0cfa4efd2
@ -196,8 +196,8 @@ fun Context.formatTo12HourFormat(showSeconds: Boolean, hours: Int, minutes: Int,
|
|||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
fun Context.getNextAlarm(): String {
|
fun Context.getNextAlarm(): String {
|
||||||
return if (isLollipopPlus()) {
|
if (isLollipopPlus()) {
|
||||||
val milliseconds = (getSystemService(Context.ALARM_SERVICE) as AlarmManager).nextAlarmClock.triggerTime
|
val milliseconds = (getSystemService(Context.ALARM_SERVICE) as AlarmManager).nextAlarmClock?.triggerTime ?: return ""
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
val isDaylightSavingActive = TimeZone.getDefault().inDaylightTime(Date())
|
val isDaylightSavingActive = TimeZone.getDefault().inDaylightTime(Date())
|
||||||
var offset = calendar.timeZone.rawOffset
|
var offset = calendar.timeZone.rawOffset
|
||||||
@ -209,9 +209,9 @@ fun Context.getNextAlarm(): String {
|
|||||||
val dayOfWeekIndex = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
val dayOfWeekIndex = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||||
val dayOfWeek = resources.getStringArray(R.array.week_days_short)[dayOfWeekIndex]
|
val dayOfWeek = resources.getStringArray(R.array.week_days_short)[dayOfWeekIndex]
|
||||||
val formatted = getFormattedTime(((milliseconds + offset) / 1000L).toInt(), false, false)
|
val formatted = getFormattedTime(((milliseconds + offset) / 1000L).toInt(), false, false)
|
||||||
"$dayOfWeek $formatted"
|
return "$dayOfWeek $formatted"
|
||||||
} else {
|
} else {
|
||||||
Settings.System.getString(contentResolver, Settings.System.NEXT_ALARM_FORMATTED) ?: ""
|
return Settings.System.getString(contentResolver, Settings.System.NEXT_ALARM_FORMATTED) ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user