Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Fixes
- The **Media mounted** trigger now actually fires (its broadcast was never registered)
- Rule cards show readable schedules: "Weekdays at 07:30" instead of "Day mask 62", and time windows show their end time

## 0.8.0

### Security
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/endroid/latch/data/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ data class Rule(
TriggerType.AIRPLANE_ON -> "Airplane on"
TriggerType.AIRPLANE_OFF -> "Airplane off"
TriggerType.MEDIA_MOUNTED -> "Media mounted"
TriggerType.TIME_WINDOW -> "Window %02d:%02d".format(triggerValue, triggerValue2)
TriggerType.DAY_OF_WEEK -> "Day mask $triggerValue"
TriggerType.TIME_WINDOW -> "Window %02d:%02d–%s".format(triggerValue, triggerValue2, triggerParam.ifBlank { "?" })
TriggerType.DAY_OF_WEEK -> com.endroid.latch.engine.RuleLogic.dayNames(triggerValue) +
if (triggerValue2 >= 0) " at %02d:%02d".format(triggerValue2 / 60, triggerValue2 % 60) else ""
TriggerType.USER_PRESENT -> "User unlocked"
TriggerType.POWER_SAVE_ON -> "Battery saver on"
TriggerType.POWER_SAVE_OFF -> "Battery saver off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class LatchMonitorService : Service() {
addDataScheme("package")
}
ContextCompat.registerReceiver(this, systemEvents, pkgFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
val mediaFilter = IntentFilter(Intent.ACTION_MEDIA_MOUNTED).apply { addDataScheme("file") }
ContextCompat.registerReceiver(this, connectivity, mediaFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
registered = true
} catch (_: Exception) {
registered = false
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/endroid/latch/engine/RuleLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ object RuleLogic {
return (mask and bit) != 0
}

/** Human label for a day mask (Calendar SUNDAY=bit 0 … SATURDAY=bit 6). */
fun dayNames(mask: Int): String {
val m = mask and 0x7F
val weekdays = 0b0111110 // Mon..Fri
val weekend = 0b1000001 // Sun, Sat
return when (m) {
0 -> "No days"
0x7F -> "Every day"
weekdays -> "Weekdays"
weekend -> "Weekends"
else -> listOf(1 to "Mon", 2 to "Tue", 3 to "Wed", 4 to "Thu", 5 to "Fri", 6 to "Sat", 0 to "Sun")
.filter { (m shr it.first) and 1 == 1 }
.joinToString(", ") { it.second }
}
}

fun clampPercent(v: Int): Int = v.coerceIn(0, 100)
fun brightnessRaw(percent: Int): Int {
val p = clampPercent(percent)
Expand Down
8 changes: 8 additions & 0 deletions app/src/test/java/com/endroid/latch/RuleLogicTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ class RuleLogicTest {
assertEquals("example.com", RuleLogic.hostForLog("https://example.com/hook?token=SECRET"))
assertEquals("?", RuleLogic.hostForLog("not a url"))
}

@Test fun dayNamesLabels() {
assertEquals("Every day", RuleLogic.dayNames(0x7F))
assertEquals("Weekdays", RuleLogic.dayNames(0b0111110))
assertEquals("Weekends", RuleLogic.dayNames(0b1000001))
assertEquals("Mon, Wed", RuleLogic.dayNames(0b0001010))
assertEquals("No days", RuleLogic.dayNames(0))
}
}
Loading