mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-02-13 02:10:40 +01:00
Refactored removeTodayFromBitmask to not use bit operators
This commit is contained in:
parent
9be4f122e8
commit
1e1666432f
@ -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)
|
alarm_label.setTextColor(textColor) //test
|
||||||
alarm_label.beVisibleIf(alarm.label.isNotEmpty())
|
alarm_label.beVisibleIf(alarm.label.isNotEmpty())
|
||||||
|
|
||||||
alarm_switch.isChecked = alarm.isEnabled
|
alarm_switch.isChecked = alarm.isEnabled
|
||||||
|
@ -9,6 +9,7 @@ import com.simplemobiletools.clock.helpers.NOTIFICATION_ID
|
|||||||
import com.simplemobiletools.clock.models.Alarm
|
import com.simplemobiletools.clock.models.Alarm
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
class DismissAlarmReceiver : BroadcastReceiver() {
|
class DismissAlarmReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
@ -42,9 +43,26 @@ class DismissAlarmReceiver : BroadcastReceiver() {
|
|||||||
private fun removeTodayFromBitmask(bitmask: Int): Int {
|
private fun removeTodayFromBitmask(bitmask: Int): Int {
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
calendar.firstDayOfWeek = Calendar.MONDAY
|
calendar.firstDayOfWeek = Calendar.MONDAY
|
||||||
val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 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 = 1 shl dayOfWeek // This will left shift 0000001 by dayOfWeek places, creating a bitmask for today
|
daysOfWeek[dayOfWeek] = false // remove today
|
||||||
return bitmask and todayBitmask.inv() // This will return a new bitmask without today included
|
|
||||||
|
// 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