mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-03-26 08:20:05 +01:00
refactor
This commit is contained in:
parent
1e1666432f
commit
728c2b50b1
@ -98,7 +98,7 @@ class AlarmsAdapter(
|
|||||||
alarm_days.setTextColor(textColor)
|
alarm_days.setTextColor(textColor)
|
||||||
|
|
||||||
alarm_label.text = alarm.label
|
alarm_label.text = alarm.label
|
||||||
alarm_label.setTextColor(textColor) //test
|
alarm_label.setTextColor(textColor)
|
||||||
alarm_label.beVisibleIf(alarm.label.isNotEmpty())
|
alarm_label.beVisibleIf(alarm.label.isNotEmpty())
|
||||||
|
|
||||||
alarm_switch.isChecked = alarm.isEnabled
|
alarm_switch.isChecked = alarm.isEnabled
|
||||||
|
@ -7,6 +7,7 @@ import com.simplemobiletools.clock.extensions.*
|
|||||||
import com.simplemobiletools.clock.helpers.ALARM_ID
|
import com.simplemobiletools.clock.helpers.ALARM_ID
|
||||||
import com.simplemobiletools.clock.helpers.NOTIFICATION_ID
|
import com.simplemobiletools.clock.helpers.NOTIFICATION_ID
|
||||||
import com.simplemobiletools.clock.models.Alarm
|
import com.simplemobiletools.clock.models.Alarm
|
||||||
|
import com.simplemobiletools.commons.extensions.removeBit
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
@ -36,7 +37,7 @@ class DismissAlarmReceiver : BroadcastReceiver() {
|
|||||||
private fun scheduleNextAlarm(alarm: Alarm, context: Context) {
|
private fun scheduleNextAlarm(alarm: Alarm, context: Context) {
|
||||||
val oldBitmask = alarm.days
|
val oldBitmask = alarm.days
|
||||||
alarm.days = removeTodayFromBitmask(oldBitmask)
|
alarm.days = removeTodayFromBitmask(oldBitmask)
|
||||||
context.scheduleNextAlarm(alarm, false)
|
context.scheduleNextAlarm(alarm, true)
|
||||||
alarm.days = oldBitmask
|
alarm.days = oldBitmask
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,25 +45,8 @@ class DismissAlarmReceiver : BroadcastReceiver() {
|
|||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
calendar.firstDayOfWeek = Calendar.MONDAY
|
calendar.firstDayOfWeek = Calendar.MONDAY
|
||||||
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7
|
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 todayBitmask = 2.0.pow(dayOfWeek).toInt()
|
||||||
val daysOfWeek = BooleanArray(7) { value ->
|
|
||||||
var bitValue = bitmask
|
|
||||||
for (i in 0 until value) {
|
|
||||||
bitValue /= 2
|
|
||||||
}
|
|
||||||
bitValue % 2 == 1
|
|
||||||
}
|
|
||||||
|
|
||||||
daysOfWeek[dayOfWeek] = false // remove today
|
return bitmask.removeBit(todayBitmask)
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user