mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
adding more dayless alarm improvements
This commit is contained in:
@ -238,7 +238,7 @@ class ReminderActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun finishActivity() {
|
||||
if (alarm != null) {
|
||||
if (alarm != null && alarm!!.days > 0) {
|
||||
scheduleNextAlarm(alarm!!, false)
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.PICK_AUDIO_FILE_INTENT_ID
|
||||
import com.simplemobiletools.clock.helpers.TODAY_BIT
|
||||
import com.simplemobiletools.clock.helpers.TOMORROW_BIT
|
||||
import com.simplemobiletools.clock.helpers.getCurrentDayMinutes
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
@ -166,11 +167,6 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
view.edit_alarm_dayless_label.beVisibleIf(alarm.days <= 0)
|
||||
}
|
||||
|
||||
private fun getCurrentDayMinutes(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
return calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
|
||||
}
|
||||
|
||||
private fun getProperDayDrawable(selected: Boolean): Drawable {
|
||||
val drawableId = if (selected) R.drawable.circle_background_filled else R.drawable.circle_background_stroke
|
||||
val drawable = activity.resources.getDrawable(drawableId)
|
||||
|
@ -81,10 +81,26 @@ fun Context.createNewAlarm(timeInMinutes: Int, weekDays: Int): Alarm {
|
||||
fun Context.scheduleNextAlarm(alarm: Alarm, showToast: Boolean) {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.firstDayOfWeek = Calendar.MONDAY
|
||||
val currentTimeInMinutes = getCurrentDayMinutes()
|
||||
|
||||
if (alarm.days == TODAY_BIT) {
|
||||
val triggerInMinutes = alarm.timeInMinutes - currentTimeInMinutes
|
||||
setupAlarmClock(alarm, triggerInMinutes * 60 - calendar.get(Calendar.SECOND))
|
||||
|
||||
if (showToast) {
|
||||
showRemainingTimeMessage(triggerInMinutes)
|
||||
}
|
||||
} else if (alarm.days == TOMORROW_BIT) {
|
||||
val triggerInMinutes = alarm.timeInMinutes - currentTimeInMinutes + DAY_MINUTES
|
||||
setupAlarmClock(alarm, triggerInMinutes * 60 - calendar.get(Calendar.SECOND))
|
||||
|
||||
if (showToast) {
|
||||
showRemainingTimeMessage(triggerInMinutes)
|
||||
}
|
||||
} else {
|
||||
for (i in 0..7) {
|
||||
val currentDay = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
val isCorrectDay = alarm.days and 2.0.pow(currentDay).toInt() != 0
|
||||
val currentTimeInMinutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
|
||||
if (isCorrectDay && (alarm.timeInMinutes > currentTimeInMinutes || i > 0)) {
|
||||
val triggerInMinutes = alarm.timeInMinutes - currentTimeInMinutes + (i * DAY_MINUTES)
|
||||
setupAlarmClock(alarm, triggerInMinutes * 60 - calendar.get(Calendar.SECOND))
|
||||
@ -98,6 +114,7 @@ fun Context.scheduleNextAlarm(alarm: Alarm, showToast: Boolean) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.showRemainingTimeMessage(totalMinutes: Int) {
|
||||
val fullString = String.format(getString(R.string.alarm_goes_off_in), formatMinutesToTimeString(totalMinutes))
|
||||
@ -224,8 +241,11 @@ fun Context.showAlarmNotification(alarm: Alarm) {
|
||||
val notification = getAlarmNotification(pendingIntent, alarm)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(alarm.id, notification)
|
||||
|
||||
if (alarm.days > 0) {
|
||||
scheduleNextAlarm(alarm, false)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.getTimerNotification(pendingIntent: PendingIntent, addDeleteIntent: Boolean): Notification {
|
||||
|
@ -12,7 +12,7 @@ import com.simplemobiletools.clock.adapters.AlarmsAdapter
|
||||
import com.simplemobiletools.clock.dialogs.EditAlarmDialog
|
||||
import com.simplemobiletools.clock.extensions.*
|
||||
import com.simplemobiletools.clock.helpers.DEFAULT_ALARM_MINUTES
|
||||
import com.simplemobiletools.clock.helpers.getNextDayBit
|
||||
import com.simplemobiletools.clock.helpers.getTomorrowBit
|
||||
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
|
||||
import com.simplemobiletools.clock.models.Alarm
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
@ -60,7 +60,7 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
alarm_fab.setOnClickListener {
|
||||
val newAlarm = context.createNewAlarm(DEFAULT_ALARM_MINUTES, 0)
|
||||
newAlarm.isEnabled = true
|
||||
newAlarm.days = getNextDayBit()
|
||||
newAlarm.days = getTomorrowBit()
|
||||
openEditAlarm(newAlarm)
|
||||
}
|
||||
}
|
||||
|
@ -80,19 +80,18 @@ fun formatTime(showSeconds: Boolean, use24HourFormat: Boolean, hours: Int, minut
|
||||
}
|
||||
}
|
||||
|
||||
fun getTodayBit(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
return 2.0.pow(dayOfWeek).toInt()
|
||||
}
|
||||
|
||||
fun getNextDayBit(): Int {
|
||||
fun getTomorrowBit(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.add(Calendar.DAY_OF_WEEK, 1)
|
||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
||||
return 2.0.pow(dayOfWeek).toInt()
|
||||
}
|
||||
|
||||
fun getCurrentDayMinutes(): Int {
|
||||
val calendar = Calendar.getInstance()
|
||||
return calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
|
||||
}
|
||||
|
||||
fun getAllTimeZones() = arrayListOf(
|
||||
MyTimeZone(1, "GMT-11:00 Midway", "Pacific/Midway"),
|
||||
MyTimeZone(2, "GMT-10:00 Honolulu", "Pacific/Honolulu"),
|
||||
|
Reference in New Issue
Block a user