mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	properly handle no alarm set
This commit is contained in:
		| @@ -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) ?: "" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user