This commit is contained in:
Rawlin C 2023-07-05 13:58:24 +05:30
parent 1e1666432f
commit 728c2b50b1
2 changed files with 5 additions and 21 deletions

View File

@ -98,7 +98,7 @@ class AlarmsAdapter(
alarm_days.setTextColor(textColor)
alarm_label.text = alarm.label
alarm_label.setTextColor(textColor) //test
alarm_label.setTextColor(textColor)
alarm_label.beVisibleIf(alarm.label.isNotEmpty())
alarm_switch.isChecked = alarm.isEnabled

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.clock.helpers.ALARM_ID
import com.simplemobiletools.clock.helpers.NOTIFICATION_ID
import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.extensions.removeBit
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import java.util.Calendar
import kotlin.math.pow
@ -36,7 +37,7 @@ class DismissAlarmReceiver : BroadcastReceiver() {
private fun scheduleNextAlarm(alarm: Alarm, context: Context) {
val oldBitmask = alarm.days
alarm.days = removeTodayFromBitmask(oldBitmask)
context.scheduleNextAlarm(alarm, false)
context.scheduleNextAlarm(alarm, true)
alarm.days = oldBitmask
}
@ -44,25 +45,8 @@ class DismissAlarmReceiver : BroadcastReceiver() {
val calendar = Calendar.getInstance()
calendar.firstDayOfWeek = Calendar.MONDAY
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
// boolean array with each day of the week set as per the bitmask provided
val daysOfWeek = BooleanArray(7) { value ->
var bitValue = bitmask
for (i in 0 until value) {
bitValue /= 2
}
bitValue % 2 == 1
}
val todayBitmask = 2.0.pow(dayOfWeek).toInt()
daysOfWeek[dayOfWeek] = false // remove today
// Convert the boolean array back to an integer (bitmask)
var updatedBitmask = 0
for (i in 0..6) {
if (daysOfWeek[i]) {
updatedBitmask += 2.0.pow(i).toInt()
}
} // This will return a new bitmask without today included
return updatedBitmask
return bitmask.removeBit(todayBitmask)
}
}