diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1eb4d9f..9659c61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -73,6 +73,19 @@ jobs: -PversionName=${{ steps.v.outputs.versionName }} \ -PversionCode=${{ steps.v.outputs.versionCode }} \ --stacktrace + # Publishing gate: stores (Myket, Cafe Bazar, Play) reject signed-less + # APKs, so fail the job instead of shipping one. + set -- app/build/outputs/apk/release/*.apk + for APK in "$@"; do + case "$APK" in + *unsigned*) + echo "::error::unsigned release APK ($APK) — signing secrets are missing or wrong" + exit 1 + ;; + esac + done + [ -e "$1" ] || { echo "::error::no release APK produced"; exit 1; } + echo "signed release APK(s): $#" - name: Collect APK id: apk diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bcb9974..ef7e9b1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -59,7 +59,7 @@ diff --git a/app/src/main/java/com/erfanbagheri/controlix/L10n.kt b/app/src/main/java/com/erfanbagheri/controlix/L10n.kt index ea76e02..82d18d8 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/L10n.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/L10n.kt @@ -19,9 +19,25 @@ import java.util.Locale private const val LANG_PREFS = "controlix_lang" private const val LANG_KEY = "lang" -/** "" = follow the system/per-app locale; "en"/"fa" = in-app override. */ +/** "": follow the system/per-app locale; "en"/"fa": in-app override. */ private var forcedLang: String = "" +/** + * Compose-observable mirror of [forcedLang]. `tr()` resolves through a plain + * module field, so nothing recomposes when the language changes; the theme + * reads this to re-derive typography and layout direction in place instead of + * waiting for the next cold start. + */ +private val langState = androidx.compose.runtime.mutableStateOf("") + +/** The language the composition should render with — read inside @Composable. */ +fun languageState(): String = langState.value + +private fun setForcedLang(lang: String) { + forcedLang = lang + langState.value = lang +} + private var rawContext: Context? = null private var appContext: Context? = null @@ -33,7 +49,7 @@ private var appContext: Context? = null */ fun l10nApply(base: Context): Context { val lang = base.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty() - forcedLang = lang + setForcedLang(lang) // Rebuild the tr() context from scratch. The system per-app language switch // (localeConfig) never calls setLanguage, so this is the only place that can // notice it — and `base` is the one object carrying the *new* locale. @@ -75,8 +91,9 @@ private fun wrapLocale(base: Context, lang: String): Context { fun l10nInit(context: Context) { val raw = context.applicationContext rawContext = raw - forcedLang = raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty() - appContext = wrapLocale(raw, forcedLang) + val saved = raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty() + setForcedLang(saved) + appContext = wrapLocale(raw, saved) } /** @@ -88,7 +105,7 @@ fun setLanguage(lang: String) { // commit(): recreate() below re-reads this pref synchronously — // apply() races and the old locale wins until a cold restart. raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).edit().putString(LANG_KEY, lang).commit() - forcedLang = lang + setForcedLang(lang) appContext = wrapLocale(raw, lang) } diff --git a/app/src/main/java/com/erfanbagheri/controlix/data/AcSelection.kt b/app/src/main/java/com/erfanbagheri/controlix/data/AcSelection.kt index 9aa746b..95aa80e 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/data/AcSelection.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/data/AcSelection.kt @@ -72,6 +72,14 @@ data class AcSelection(val tempC: Int, val mode: AcMode, val power: Boolean) { /** Modes offered by the pad; unsupported modes stay disabled. */ fun presetModes(): List = AcMode.entries.toList() + + /** + * How many preset modes a remote must carry before the mode row + * shows presets at all. A remote with a bare `Mode` cycle key + * supports none of the five presets individually — it just walks + * its own list — so the row would render five dead buttons. + */ + const val MODE_ROW_MIN_SUPPORTED: Int = 1 } } diff --git a/app/src/main/java/com/erfanbagheri/controlix/data/ButtonNames.kt b/app/src/main/java/com/erfanbagheri/controlix/data/ButtonNames.kt index af05069..31d4f0f 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/data/ButtonNames.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/data/ButtonNames.kt @@ -14,7 +14,7 @@ package com.erfanbagheri.controlix.data object ButtonNames { /** lowercase, keep alphanumerics and +/-. */ - private fun norm(s: String): String = + fun norm(s: String): String = s.lowercase().filter { it.isLetterOrDigit() || it == '+' || it == '-' } fun power(n: String): Boolean { @@ -167,4 +167,201 @@ object ButtonNames { /** A swing / louver key. */ fun acSwing(n: String): Boolean = norm(n).contains("swing") + + // ── Non-TV families (fans, purifiers, humidifiers, heaters, …) ──────── + // ponytail: these are label heuristics validated against the DB's own + // vocabulary (see docs/DB.md). Upgrade path: per-brand metadata. + + fun speedUp(n: String): Boolean { + val x = norm(n) + return (x.contains("speed") || x.contains("fan")) && + (x.contains("up") || x.contains("+") || x.contains("faster") || x.contains("higher")) + } + fun speedDown(n: String): Boolean { + val x = norm(n) + return (x.contains("speed") || x.contains("fan")) && + (x.contains("down") || x.contains("dn") || x.contains("-") || x.contains("slower") || x.contains("lower")) + } + /** A discrete speed/fan level key (SPEED 1, FAN HIGH, LOW, MEDIUM, …). */ + fun speedLevel(n: String): Boolean { + val x = norm(n) + if (x == "speed" || x == "fan" || x == "fanonly") return false + if (x.startsWith("speed") || x.startsWith("fan")) { + val tail = x.removePrefix("speed").removePrefix("fan").removePrefix("speed_").removePrefix("fan_").trim() + val levelWords = setOf("low", "med", "medium", "mid", "high", "max", "turbo", "quiet", + "slow", "normal", "1", "2", "3", "4", "5", "6", "7", "8", "9") + return tail in levelWords || tail.all { it.isDigit() } + } + return false + } + /** + * A mode key (Mode, Auto, Turbo, Sleep, Night, Eco, Quiet, Natural, …), + * plus compound mode+duration labels like "Heat_5m" or "Dry_1h": a mode + * word at the front followed by digits and an optional unit. + */ + fun modeKey(n: String): Boolean { + val x = norm(n) + if (x == "mode" || x.startsWith("mode")) return true + if (x in setOf("auto", "turbo", "sleep", "night", "eco", "quiet", "natural", "wind", + "ionizer", "plasma", "purify", "dry", "cool", "heat", "warm", "vent", + "fanonly", "breeze", "nightmode", "moon", "snow", "freeze")) { + return true + } + // mode prefix + a duration tail: Heat_5m, Cool_30, Vent_1h. + val m = compoundTail(n) ?: return false + return setOf("heat", "dry", "vent", "cool", "warm", "auto", "fan", "night", "snow", "freeze") + .any { m.first.startsWith(it) } + } + + /** + * A duration tail on a compound label, e.g. 5m / 30 / 1h / 3h in + * "Heat_5m", or null when the label has none. + */ + internal fun compoundTail(n: String): Pair? { + val i = n.indexOfAny(charArrayOf('_', '-')) + if (i <= 0) return null + val tail = n.substring(i + 1).trim() + if (tail.isEmpty() || tail.length > 8) return null + val digits = tail.filter { it.isDigit() } + val unit = tail.filterNot { it.isDigit() }.lowercase() + // Digit-less tails are only "on"/"off" ("Vent_On"): a mode toggle, not a duration. + if (digits.isEmpty() && unit !in setOf("on", "off")) return null + if (unit != "" && unit !in setOf("m", "min", "mins", "minute", "h", "hr", "hrs", "hour", "hours", "s", "sec", "on", "off")) return null + return n.substring(0, i).lowercase() to tail + } + + /** + * The mode half of a compound label — "heat" for "Heat_5m", "vent" for + * "Vent_On" — or null when the label is not compound. + * + * The pad uses this to group a fan's 22 mode keys by what they actually + * do: Heat / Vent / Dry / HeatDry each get their own row instead of one + * 22-chip wall. Without it every duration variant is a separate-looking + * control and the row is unreadable. + * + * ponytail: grouping is a string split on the first separator, so a brand + * that writes "5mHeat" groups under a junk head. Upgrade path: per-brand + * button maps carrying the real (mode, duration) pair. + */ + fun modeHead(n: String): String? = compoundTail(n)?.first + + /** + * The duration half of a compound label — "5m" for "Heat_5m", "On" for + * "Vent_On" — or null when the label is not compound. The pad shows this + * as the chip text once the head has been promoted to the row label, so + * a grouped row reads "Heat: 5m 15m 30m 1h" instead of four "Heat_5m"s. + */ + fun modeTail(n: String): String? = compoundTail(n)?.second + + /** An oscillation / swing / rotation / louver key. */ + fun oscillate(n: String): Boolean { + val x = norm(n) + return x.contains("osc") || x.contains("rotat") || x.contains("swing") || + x.contains("louver") || x.contains("turn") || x.contains("wide") || + x.contains("vertical") || x.contains("horizontal") + } + /** A timer key. */ + fun timerKey(n: String): Boolean { + val x = norm(n) + return x.contains("timer") || x == "time" || x.startsWith("hour") || x.contains("ontimer") || + x.contains("offtimer") + } + /** A light / lamp key. */ + fun lightKey(n: String): Boolean { + val x = norm(n) + return x.contains("light") || x.contains("lamp") || x.contains("mood") + } + /** A temperature step up (+) key. */ + fun tempUp(n: String): Boolean { + val x = norm(n) + return (x.contains("temp") || x.contains("temperature")) && + (x.contains("up") || x.contains("+") || x.contains("plus")) + } + /** A temperature step down (−) key. */ + fun tempDown(n: String): Boolean { + val x = norm(n) + return (x.contains("temp") || x.contains("temperature")) && + (x.contains("down") || x.contains("dn") || x.contains("-") || x.contains("minus")) + } + /** A color key (lighting). Multi-word names ("Ice Blue", "Dark Green") match + * on their last word; "R"/"G"/"B"/"W" single letters count. */ + fun colorKey(n: String): Boolean { + val words = norm(n).split(' ', '_').filter { it.isNotEmpty() } + return words.any { it in COLORS } && words.size <= 3 + } + + private val COLORS = setOf( + "red", "green", "blue", "white", "yellow", "orange", "purple", "pink", "cyan", + "lime", "amber", "violet", "indigo", "teal", "aqua", "navy", "rainbow", "warm", + "cool", "neutral", "cozy", "pastel", "r", "g", "b", "w", "c", "y", "o", "p", + ) + /** An effect key (lighting). */ + fun effectKey(n: String): Boolean { + val x = norm(n) + return x in setOf("flash", "fade", "strobe", "smooth", "jump", "quick", "wave", + "blink", "sparkle", "glow") + } + /** A brightness key. */ + fun brightnessKey(n: String): Boolean { + val x = norm(n) + return x.contains("bright") || x.startsWith("dim") || x.contains("darker") + } + /** A humidity / mist key. */ + fun humidityKey(n: String): Boolean { + val x = norm(n) + return x.contains("hum") || x.contains("mist") || x.contains("vapor") + } + /** A cleaning / dock / spot key (vacuums). */ + fun cleaningKey(n: String): Boolean { + val x = norm(n) + return x.contains("clean") || x.contains("spot") || x.contains("edge") || + x.contains("suction") || x.contains("spiral") || x.contains("zigzag") || + x.contains("square") || x.contains("zone") + } + /** A dock / home / return key (vacuums). */ + fun dockKey(n: String): Boolean { + val x = norm(n) + return x == "home" || x == "dock" || x.contains("recharge") || x.contains("return") + } + /** A start / stop / pause key (vacuums). */ + fun startStopKey(n: String): Boolean { + val x = norm(n) + return x.contains("start") || x.contains("pause") || x == "stop" || x.contains("stopstart") + } + /** An audio source / input key. */ + fun audioSourceKey(n: String): Boolean { + val x = norm(n) + return x.contains("source") || x.contains("input") || x.contains("bluetooth") || + x == "bt" || x.contains("optical") || x.contains("opt") || x.contains("hdmi") || + x == "aux" || x.contains("usb") || x == "tv" || x == "pc" || x == "fm" || + x.contains("cd") || x.contains("phono") || x.contains("dvd") || x.contains("sat") + } + /** An audio sound-mode key. */ + fun audioModeKey(n: String): Boolean { + val x = norm(n) + return x in setOf("music", "movie", "cinema", "standard", "surround", "night", + "game", "stereo", "theater", "news", "speech", "voice", "nightmode", "sports", + "pop", "rock", "jazz", "classical", "flat", "user") + } + /** A bass / treble key. */ + fun bassTrebleKey(n: String): Boolean { + val x = norm(n) + return x.contains("bass") || x.contains("treble") || x.contains("eq") || + x.contains("equalizer") || x.contains("sub") + } + /** A transport key (playback). */ + fun transportKey(n: String): Boolean { + val x = norm(n) + return x.contains("play") || x == "stop" || x.contains("pause") || x == "next" || + x == "prev" || x.contains("previous") || x.contains("rewind") || + x.contains("fastforward") || x.contains("forward") || x.contains("record") + } + /** A freeze / blank / aspect key (projectors). */ + fun projectorKey(n: String): Boolean { + val x = norm(n) + return x.contains("freeze") || x.contains("blank") || x.contains("aspect") || + x.contains("keystone") || x.contains("zoom") || x.contains("focus") + } + /** A lock / child-lock key. */ + fun lockKey(n: String): Boolean = norm(n).contains("lock") } diff --git a/app/src/main/java/com/erfanbagheri/controlix/data/PadOverflow.kt b/app/src/main/java/com/erfanbagheri/controlix/data/PadOverflow.kt new file mode 100644 index 0000000..50352ff --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/data/PadOverflow.kt @@ -0,0 +1,21 @@ +package com.erfanbagheri.controlix.data + +/** + * Splits a pad's keys into the row shown on the pad and the "More keys" sheet. + * Pure data; ordering decisions belong to the caller. + */ +object PadOverflow { + const val VISIBLE_LIMIT = 8 + + data class Split(val visible: List, val overflow: List) + + fun split(keys: List): Split = + if (keys.size <= VISIBLE_LIMIT) { + Split(keys, emptyList()) + } else { + Split(keys.take(VISIBLE_LIMIT), keys.drop(VISIBLE_LIMIT)) + } + + // ponytail: stateless split, no grouping of overflow keys; if a remote ever + // carries >20 keys, group the overflow by its own heading inside the sheet. +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/AcPad.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/AcPad.kt index 1805d77..5c5af68 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/ui/AcPad.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/AcPad.kt @@ -4,6 +4,11 @@ import com.erfanbagheri.controlix.data.FontScale import androidx.compose.ui.platform.LocalDensity import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.ui.draw.clip import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -83,6 +88,11 @@ fun AcPadScreen( .distinctBy { it.name }.take(6) } val swingKey = remember(available) { available.firstOrNull { ButtonNames.acSwing(it.name) } } + val tempUpKey = remember(available) { available.firstOrNull { ButtonNames.tempUp(it.name) } } + val tempDownKey = remember(available) { available.firstOrNull { ButtonNames.tempDown(it.name) } } + val modeCycleKey = remember(available) { + available.firstOrNull { ButtonNames.norm(it.name) == "mode" } + } val powerOnKey = remember(available) { available.firstOrNull { ButtonNames.power(it.name) && !ButtonNames.powerOff(it.name) } } @@ -141,65 +151,101 @@ fun AcPadScreen( return@Column } - // ── Temperature: only values this remote stores for this mode ──── - SectionHead(tr(R.string.ac_target)) - Hairline() - Row( - Modifier.fillMaxWidth().heightIn(min = 76.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)), verticalAlignment = Alignment.CenterVertically, - ) { - FlatKey("−", enabled = target > (temps.firstOrNull() ?: target)) { - val idx = temps.indexOf(target) - val next = temps.getOrNull(idx - 1) ?: return@FlatKey - target = next - send(AcSelection(next, mode, true)) - } - Spacer(Modifier.width(12.dp)) - Text( - tr(R.string.ac_temp, target), - style = MaterialTheme.typography.headlineMedium, - color = MaterialTheme.colorScheme.onSurface, - textAlign = TextAlign.Center, - modifier = Modifier.weight(1f), - ) - Spacer(Modifier.width(12.dp)) - FlatKey("+", enabled = target < (temps.lastOrNull() ?: target)) { - val idx = temps.indexOf(target) - val next = temps.getOrNull(idx + 1) ?: return@FlatKey - target = next - send(AcSelection(next, mode, true)) + // ── Temperature ────────────────────────────────────────────────── + // Two sources of truth, never fake: + // - stored (mode, temp) states: the stepper walks the remote's own + // temperature ladder and the readout names the state we will send + // - no stored states but real TEMP+/TEMP− keys: the remote decides + // its own step size, we just transmit them + // Neither → no temperature section at all; saying "16°C" for a remote + // with no device temperature would be synthesize-the-world UI. + val stepKeys = tempUpKey != null || tempDownKey != null + if (temps.isNotEmpty() || stepKeys) { + SectionHead(tr(R.string.ac_target)) + Hairline() + Row( + Modifier.fillMaxWidth().heightIn(min = 76.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)), verticalAlignment = Alignment.CenterVertically, + ) { + if (temps.isNotEmpty()) { + FlatKey("−", enabled = target > (temps.firstOrNull() ?: target)) { + val idx = temps.indexOf(target) + val next = temps.getOrNull(idx - 1) ?: return@FlatKey + target = next + send(AcSelection(next, mode, true)) + } + } else { + FlatKey("−", enabled = tempDownKey != null) { + tempDownKey?.let { transmit(it, "temp-") } + ?: toast.show(explainPower(available, on = false)) + } + } + Spacer(Modifier.width(12.dp)) + Text( + tr(R.string.ac_temp, target), + style = MaterialTheme.typography.headlineMedium, + color = if (temps.isEmpty()) PaperFaint else MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + modifier = Modifier.weight(1f), + ) + Spacer(Modifier.width(12.dp)) + if (temps.isNotEmpty()) { + FlatKey("+", enabled = target < (temps.lastOrNull() ?: target)) { + val idx = temps.indexOf(target) + val next = temps.getOrNull(idx + 1) ?: return@FlatKey + target = next + send(AcSelection(next, mode, true)) + } + } else { + FlatKey("+", enabled = tempUpKey != null) { + tempUpKey?.let { transmit(it, "temp+") } + ?: toast.show(explainPower(available, on = false)) + } + } } - } - Hairline() - if (temps.isEmpty()) { - Text( - tr(R.string.ac_no_temps, Copy.mode(mode)), - style = MaterialTheme.typography.labelSmall, color = PaperFaint, - modifier = Modifier.padding(vertical = 10.dp), - ) - } else { - TempRow(temps, target) { picked -> - target = picked - send(AcSelection(picked, mode, true)) + Hairline() + if (temps.isEmpty()) { + Text( + tr(R.string.ac_no_temps, Copy.mode(mode)), + style = MaterialTheme.typography.labelSmall, color = PaperFaint, + modifier = Modifier.padding(vertical = 10.dp), + ) + } else { + TempRow(temps, target) { picked -> + target = picked + send(AcSelection(picked, mode, true)) + } } } // ── Mode ───────────────────────────────────────────────────────── - SectionHead(tr(R.string.ac_mode)) - Hairline() - ModeRow(AcSelection.presetModes(), modes, mode) { picked -> - val pickedTemps = AcSelection.supportedTemps(available, picked) - if (pickedTemps.isNotEmpty()) target = pickedTemps.first() - mode = picked - send(AcSelection(target, picked, true)) + // The remote's own Mode cycle key: reachable even when it carries no + // individual preset modes (a bare `Mode` walks its own list). + if (modeCycleKey != null && modes.isEmpty()) { + SectionHead(tr(R.string.ac_mode)) + Hairline() + Row(Modifier.fillMaxWidth().heightIn(min = 56.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)), verticalAlignment = Alignment.CenterVertically) { + FlatKey(modeCycleKey.name) { transmit(modeCycleKey, modeCycleKey.name) } + } + Hairline() } - Hairline() - val missingModes = AcSelection.presetModes().filterNot { it in modes } - if (missingModes.isNotEmpty()) { - Text( - tr(R.string.ac_disabled_modes, missingModes.joinToString { it.label }), - style = MaterialTheme.typography.labelSmall, color = PaperFaint, - modifier = Modifier.padding(vertical = 10.dp), - ) + if (modes.isNotEmpty()) { + SectionHead(tr(R.string.ac_mode)) + Hairline() + ModeRow(AcSelection.presetModes(), modes, mode) { picked -> + val pickedTemps = AcSelection.supportedTemps(available, picked) + if (pickedTemps.isNotEmpty()) target = pickedTemps.first() + mode = picked + send(AcSelection(target, picked, true)) + } + Hairline() + val missingModes = AcSelection.presetModes().filterNot { it in modes } + if (missingModes.isNotEmpty()) { + Text( + tr(R.string.ac_disabled_modes, missingModes.joinToString { it.label }), + style = MaterialTheme.typography.labelSmall, color = PaperFaint, + modifier = Modifier.padding(vertical = 10.dp), + ) + } } // ── Power ──────────────────────────────────────────────────────── @@ -228,14 +274,24 @@ fun AcPadScreen( Hairline() Row( Modifier.fillMaxWidth().padding(vertical = 12.dp), - horizontalArrangement = Arrangement.spacedBy(18.dp), + horizontalArrangement = Arrangement.spacedBy(10.dp), ) { fanKeys.forEach { key -> - Text( - key.name, - style = MaterialTheme.typography.titleSmall, color = Accent, - modifier = Modifier.pressable { transmit(key, key.name) }, - ) + Box( + Modifier + .weight(1f) + .height(52.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)) + .clip(RoundedCornerShape(14.dp)) + .background(MaterialTheme.colorScheme.surfaceVariant) + .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(14.dp)) + .pressable { transmit(key, key.name) }, + contentAlignment = Alignment.Center, + ) { + Text( + key.name, style = MaterialTheme.typography.titleSmall, + color = Accent, textAlign = TextAlign.Center, maxLines = 1, + ) + } } } Hairline() @@ -251,6 +307,53 @@ fun AcPadScreen( Hairline() } + // Every key this remote carries that the sections above did not + // surface (Timer, Ion, Turbo, ...) — a pad that drops codes silently + // makes the remote's own buttons unreachable. + val claimed = setOfNotNull( + powerOnKey, swingKey, tempUpKey, tempDownKey, modeCycleKey, + ) + fanKeys + + (if (temps.isNotEmpty()) emptySet() else emptySet()) + + available.filter { ButtonNames.power(it.name) } + val rest = remember(available, claimed) { + available.filter { it !in claimed } + .distinctBy { it.name } + } + if (rest.isNotEmpty()) { + SectionHead(tr(R.string.appliance_more)) + Hairline() + Row( + Modifier.fillMaxWidth().padding(vertical = 12.dp), + horizontalArrangement = Arrangement.spacedBy(10.dp), + ) { + rest.take(6).forEach { key -> + Box( + Modifier + .weight(1f) + .height(52.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)) + .clip(RoundedCornerShape(14.dp)) + .background(MaterialTheme.colorScheme.surfaceVariant) + .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(14.dp)) + .pressable { transmit(key, key.name) }, + contentAlignment = Alignment.Center, + ) { + Text( + key.name, style = MaterialTheme.typography.titleSmall, + color = Accent, textAlign = TextAlign.Center, maxLines = 1, + ) + } + } + } + Hairline() + if (rest.size > 6) { + Text( + tr(R.string.appliance_more_count, rest.size - 6), + style = MaterialTheme.typography.labelSmall, color = PaperFaint, + modifier = Modifier.padding(vertical = 10.dp), + ) + } + } + if (lastSent != null) { Text( lastSent.orEmpty(), style = MaterialTheme.typography.labelSmall, color = PaperFaint, @@ -290,6 +393,13 @@ private fun TempRow(temps: List, target: Int, onPick: (Int) -> Unit) { } } +/** + * Mode row: only the modes this remote actually carries. + * + * A mode the remote lacks isn't a disabled button, it's a control that + * doesn't exist on this unit, so it's omitted; the footnote below the row + * still names what's missing so nothing is silently hidden. + */ @Composable private fun ModeRow( presets: List, @@ -297,22 +407,49 @@ private fun ModeRow( selected: AcMode, onPick: (AcMode) -> Unit, ) { + // Only the presets this remote actually carries. A remote with a bare + // `Mode` cycle key supports none of them individually, so its row would + // be five dead buttons — hide the row and say why in the temperature + // footnote instead. + val shown = presets.filter { it in supported } + if (shown.isEmpty()) return Row( Modifier.fillMaxWidth().padding(vertical = 12.dp), - horizontalArrangement = Arrangement.spacedBy(18.dp), + horizontalArrangement = Arrangement.spacedBy(10.dp), ) { - presets.forEach { m -> + shown.forEach { m -> val on = m in supported - Text( - m.label, - style = MaterialTheme.typography.titleSmall, - color = when { - !on -> PaperFaint - m == selected -> Accent - else -> MaterialTheme.colorScheme.onSurface - }, - modifier = Modifier.pressable(on) { onPick(m) }, - ) + val picked = m == selected + Box( + Modifier + .weight(1f) + .height(52.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)) + .clip(RoundedCornerShape(14.dp)) + .background( + if (picked) MaterialTheme.colorScheme.surfaceVariant + else MaterialTheme.colorScheme.surface, + ) + .border( + 1.dp, + if (picked) Accent else MaterialTheme.colorScheme.outline, + RoundedCornerShape(14.dp), + ) + .pressable(on) { onPick(m) } + .padding(horizontal = 6.dp), + contentAlignment = Alignment.Center, + ) { + Text( + m.label, + style = MaterialTheme.typography.titleSmall, + color = when { + !on -> PaperFaint + picked -> Accent + else -> MaterialTheme.colorScheme.onSurface + }, + textAlign = TextAlign.Center, + maxLines = 1, + ) + } } } } diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/DPad.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/DPad.kt new file mode 100644 index 0000000..4c42f20 --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/DPad.kt @@ -0,0 +1,63 @@ +package com.erfanbagheri.controlix.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.unit.dp +import androidx.compose.ui.platform.LocalDensity +import com.erfanbagheri.controlix.data.FontScale +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.ui.theme.PaperFaint + +/** Cross layout with a circular center. Tiles = bg-tiled, radius 16dp. */ +@Composable +fun DPad(keys: List, onTap: (EffectiveButtons.Resolved) -> Unit) { + val up = keys.getOrNull(0) + val left = keys.getOrNull(1) + val ok = keys.getOrNull(2) + val right = keys.getOrNull(3) + val down = keys.getOrNull(4) + @Composable + fun cell(key: EffectiveButtons.Resolved?, enabled: Boolean, modifier: Modifier) { + val h = 56.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale) + Box( + modifier = modifier + .height(h) + .clip(CircleShape) + .background(MaterialTheme.colorScheme.surfaceVariant) + .then(if (enabled && key != null) Modifier.pressable { onTap(key) } else Modifier), + contentAlignment = Alignment.Center, + ) { + Text( + key?.name ?: "·", + style = MaterialTheme.typography.titleMedium, + color = if (key != null) MaterialTheme.colorScheme.onSurface else PaperFaint.copy(alpha = 0.4f), + ) + } + } + Column( + Modifier.fillMaxWidth().padding(vertical = 10.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Row(Modifier.fillMaxWidth(0.62f)) { cell(up, true, Modifier.weight(1f)) } + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) { + cell(left, true, Modifier.weight(1f)) + cell(ok, ok != null, Modifier.weight(1f)) + cell(right, true, Modifier.weight(1f)) + } + Row(Modifier.fillMaxWidth(0.62f)) { cell(down, true, Modifier.weight(1f)) } + } +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePad.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePad.kt new file mode 100644 index 0000000..c2d8a18 --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePad.kt @@ -0,0 +1,443 @@ +package com.erfanbagheri.controlix.ui + +import com.erfanbagheri.controlix.R +import com.erfanbagheri.controlix.data.ButtonNames +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.data.PadOverflow +import com.erfanbagheri.controlix.data.FontScale + +/** + * Pad for every device family that is neither TV-like nor AC. + * + * The TV pad (d-pad + VOL/CH + keypad) and the AC pad (mode/temperature + * state machine) are both wrong for a fan, a soundbar or an LED strip: + * those remotes have no channel, no d-pad, and no (mode,temp) grid. This + * pad renders rows straight from the codes the remote actually carries, so + * one layout serves all of them honestly. + * + * Data-driven: [sectionsFor] turns (family, buttons) into labelled rows and + * [DevicePadScreen] renders whatever comes back. Adding a family is a slug + * in [familyFor] plus a row order — not a new screen. + * + * Honest rules (same as AcPad): + * - a key that does not exist is never shown as sendable + * - every section is omitted when the remote carries no key for it + * - codes are never borrowed from sibling remotes — a sibling's state + * machine is not this remote's + * + * ponytail: family is inferred from the category slug alone; no per-brand + * metadata. Upgrade path: a `family` column on remote/brand once the DB + * carries it. + */ +enum class PadFamily { + /** Fans, heaters, fireplaces: speed + swing + timer + light. */ + CLIMATE, + + /** Purifiers, humidifiers: mode + fan + mist/humidity + timer + light. */ + AIR_TREATMENT, + + /** Soundbars, speakers, receivers, CD/DVD/laserdisc, head units. */ + AUDIO, + + /** Projectors, monitors, displays: d-pad + menu + source + tools. */ + DISPLAY, + + /** LED strips and lighting: colours + effects + brightness. */ + LIGHTING, + + /** Vacuums, dust collectors, window cleaners: cleaning + suction + dock. */ + CLEANING, + + /** Set-top boxes, cable, streaming, consoles, KVM, everything TV-shaped. */ + TV, + ; + + companion object { + fun familyFor(categorySlug: String): PadFamily = when { + categorySlug.startsWith("acs") -> CLIMATE + categorySlug.startsWith("fans") || + categorySlug.startsWith("heaters") || + categorySlug.startsWith("fireplaces") -> CLIMATE + categorySlug.startsWith("air_purifiers") || + categorySlug.startsWith("humidifiers") -> AIR_TREATMENT + categorySlug.startsWith("soundbars") || + categorySlug.startsWith("speakers") || + categorySlug.startsWith("audio_and_video_receivers") || + categorySlug.startsWith("cd_players") || + categorySlug.startsWith("minidisc") || + categorySlug.startsWith("laserdisc") || + categorySlug.startsWith("head_units") -> AUDIO + categorySlug.startsWith("projectors") || + categorySlug.startsWith("monitors") || + categorySlug.startsWith("touchscreen_displays") || + categorySlug.startsWith("digital_signs") || + categorySlug.startsWith("whiteboards") -> DISPLAY + categorySlug.startsWith("led_lighting") || + categorySlug.startsWith("clocks") || categorySlug.startsWith("blinds") -> LIGHTING + categorySlug.startsWith("vacuum_cleaners") || + categorySlug.startsWith("dust_collectors") || + categorySlug.startsWith("window_cleaners") -> CLEANING + else -> TV + } + } +} + +/** How a row draws. Stepper is the only one that pairs two keys. */ +enum class PadRowStyle { STEPPER, CHIPS, D_PAD, KEYPAD, OVERFLOW } + +/** + * How big a chip row's keys draw. + * + * Mi Remote and every other universal remote give the primary action a + * bigger target than the secondary ones — a fan's Speed row reads as a + * control, not as a list of links. Text-only chips gave all 47 keys of a + * projector the same visual weight, which is why the pad looked like a + * table of contents rather than a remote. + */ +enum class PadKeySize { + /** Half-width tiles — the pad's main actions (speed, mode, colours). */ + LARGE, + /** Narrow pills — supporting keys (timers, effects, navigation). */ + SMALL, + /** Square, one per grid cell — numeric pads and colour swatches. */ + SQUARE, +} + +/** One labelled row: the remote's own keys, in the order the pad shows them. */ +data class PadRow( + val labelRes: Int, + val style: PadRowStyle, + /** Left key of a STEPPER, or null. */ + val downKey: EffectiveButtons.Resolved? = null, + /** Right key of a STEPPER, or null. */ + val upKey: EffectiveButtons.Resolved? = null, + /** Read-out between a stepper's two keys, if any. */ + val readout: String? = null, + /** Row contents for CHIPS / D_PAD / KEYPAD. */ + val keys: List = emptyList(), + /** How the keys draw. Only CHIPS reads it. */ + val keySize: PadKeySize = PadKeySize.SMALL, + /** + * Overrides the section heading with the remote's own word. + * + * A compound mode row is labelled by the mode half it was grouped under + * ("Heat", "Vent") rather than the generic "Mode" string — the label the + * DB carries is more specific than anything we can localize, and one + * generic heading over four groups is how the fan pad ended up with 22 + * identical-looking chips. + */ + val labelOverride: String? = null, + /** + * Text drawn on each chip instead of the raw DB label. + * + * Parallel to [keys]. A grouped mode row shows only the duration ("5m") + * because the heading already says "Heat"; repeating it on every chip + * doubles the row's width for no information. + */ + val chipLabels: List? = null, +) + +/** + * Turns "+/−" and "On/Off" key pairs into single controls. + * + * A remote labels a rocker as two keys ("Bass+", "Bass−") and a switch as two + * ("Surround On", "Surround Off"). Rendered as chips that is a wall of + * near-identical labels with no hint that they are halves of one control. + * Grouping them by their shared stem gives the pad the shape the remote has: + * one rocker per feature, one toggle per switch. + * + * Anything without a partner is left unclaimed for the later rows — a lone + * "Bass+" is still a key, just not half a stepper. + */ +private fun pairRows( + available: List, + claimed: MutableSet, +): List { + val rows = mutableListOf() + // Only keys no earlier rule took. A speed row that already claimed + // "Speed UP"/"Speed DOWN" must not reappear as a rocker below it. + val free = available.filter { it.name !in claimed } + + // A key name is only a stem worth pairing when both halves are real + // separate keys. "Source Up" is one button that raises the source, not + // half of a rocker — a "Source Down" does not exist to pair with, so the + // pair never forms and the key stays a chip. Requiring a separator or a + // sign between the two halves is what makes "Bass Up"/"Bass Down" and + // "FanPower+"/"FanPower-" pairs while leaving single keys alone. + fun splitPair(n: String): Pair? { + val t = n.trim() + val half = listOf("up", "down", "on", "off").firstOrNull { t.endsWith(" $it", true) || t.endsWith("_$it", true) } + ?: return null + val stem = t.dropLast(half.length + 1).trim().trimEnd('_') + return if (stem.isNotBlank()) stem to half.lowercase() else null + } + + // Rockers exist in two shapes on these remotes: a plus/minus sign + // ("FanPower+") and a word ("Bass Up"). Match whichever half the label + // ends with, then look for the opposite half under the same stem. + fun stemOf(n: String): String { + splitPair(n)?.let { return it.first } + val t = n.trim() + val cut = listOf("+", "−", "-").firstOrNull { t.endsWith(it) && t.length > 1 } + return (cut?.let { t.dropLast(it.length) } ?: t).trim().trimEnd('_', ' ') + } + + // These rocks are stereo pairs, so they get the "balance" side of the + // word, not "level" — a soundbar's Surround rocker swings left/right. + fun take(stem: String, upWord: String, downWord: String): PadRow? { + val up = free.firstOrNull { stemOf(it.name).equals(stem, true) && it.name.trim().endsWith(upWord, true) } + val dn = free.firstOrNull { stemOf(it.name).equals(stem, true) && it.name.trim().endsWith(downWord, true) } + if (up == null || dn == null || up.name == dn.name) return null + claimed += up.name + claimed += dn.name + return PadRow( + labelRes = R.string.appliance_more, + labelOverride = stem, + style = PadRowStyle.STEPPER, + downKey = dn, + upKey = up, + ) + } + + // A sign rocker has no space between the halves ("Bass+"), a word rocker + // has a space ("Bass Up"). Try the sign forms first so "Speed UP" is read + // as a word pair (Up/Down) rather than a sign pair against "Speed U". + // + // Navigation words are not rockers. "CURSOR UP"/"CURSOR DOWN" are two arms + // of a d-pad; pairing them prints a CURSOR stepper above a cross that has + // no up or down arm left. Leave them for the d-pad rule. + val navStems = setOf("cursor", "arrow", "direction", "nav", "dpad") + free.map { stemOf(it.name) }.distinct().forEach { stem -> + if (stem.isBlank() || stem.length < 3 || stem.lowercase() in navStems) return@forEach + val row = take(stem, "+", "−") ?: take(stem, "+", "-") + ?: take(stem, "Up", "Down") + if (row != null) rows += row + } + return rows +} + +/** + * Builds the pad's rows for one remote. + * + * Every predicate comes from [ButtonNames] and is matched against the + * remote's own labels only. Order matters: the first predicate that claims + * a label wins, so broad ones (power, timer) are tested before narrow ones. + */ +fun sectionsFor( + family: PadFamily, + available: List, +): List { + if (available.isEmpty()) return emptyList() + val claimed = HashSet() + val rows = mutableListOf() + + // Claim by predicate; a label can only land in one row. + fun claim(pred: (String) -> Boolean): List { + val hits = available.filter { pred(it.name) && claimed.add(it.name) } + return hits.distinctBy { it.name } + } + + // Power first — every family leads with it. A bare "Off" is an off key, + // never the on key (same rule the AC pad uses). + val powerKeys = claim { ButtonNames.power(it) && !ButtonNames.powerOff(it) } + val offKeys = claim { ButtonNames.powerOff(it) } + if (powerKeys.isNotEmpty() || offKeys.isNotEmpty()) { + // A stepper only when the remote really has both directions; a lone + // Off key is a plain key, not half a control. + if (powerKeys.isNotEmpty() && offKeys.isNotEmpty()) { + rows += PadRow( + labelRes = R.string.ac_power, + style = PadRowStyle.STEPPER, + downKey = offKeys.first(), + upKey = powerKeys.first(), + ) + } else { + rows += PadRow( + labelRes = R.string.ac_power, + style = PadRowStyle.CHIPS, + keys = (powerKeys + offKeys).take(24), + ) + } + } + + // Temperature: a real +/- pair only when both keys exist. + val tUp = claim { ButtonNames.tempUp(it) } + val tDown = claim { ButtonNames.tempDown(it) } + if (tUp.isNotEmpty() && tDown.isNotEmpty()) { + rows += PadRow( + labelRes = R.string.appliance_temp, + style = PadRowStyle.STEPPER, + downKey = tDown.first(), + upKey = tUp.first(), + ) + } + + // Mode keys: group compound labels by their mode head ("Heat", "Vent", "Dry", + // "HeatDry") so a fan with 22 mode+duration keys reads as four short rows + // instead of one 22-chip wall. A bare mode word (or a non-compound label) + // keeps the generic "Mode" heading and the raw label, as before. + val modeKeys = claim { ButtonNames.modeKey(it) } + if (modeKeys.isNotEmpty()) { + val groups = linkedMapOf>() + for (k in modeKeys) { + val head = ButtonNames.modeHead(k.name)?.replaceFirstChar { it.uppercase() } + if (head == null) { + groups.getOrPut("Mode") { mutableListOf() } += k + } else { + groups.getOrPut(head) { mutableListOf() } += k + } + } + for ((head, ks) in groups) { + val isGrouped = head != "Mode" && ks.all { ButtonNames.compoundTail(it.name) != null } + rows += PadRow( + labelRes = R.string.appliance_mode, + style = PadRowStyle.CHIPS, + keys = ks.take(24), + keySize = PadKeySize.LARGE, + labelOverride = head, + chipLabels = if (isGrouped) ks.map { ButtonNames.modeTail(it.name) ?: it.name } else null, + ) + } + } + + // Paired keys become ONE control, before any family rule can swallow them + // as loose chips. A soundbar carries six "+/−" feature pairs (Bass, + // Treble, Centre, Surround, Subwoofer, A/V delay) and four On/Off pairs; + // as chips that is twelve controls that each look unrelated. The remote + // has a rocker per feature and a toggle per switch — so does the pad. + rows += pairRows(available, claimed) + + val speedKeys = claim { + ButtonNames.speedLevel(it) || ButtonNames.speedUp(it) || ButtonNames.speedDown(it) + } + if (speedKeys.isNotEmpty()) rows += PadRow(R.string.appliance_speed, PadRowStyle.CHIPS, keys = speedKeys.take(24), keySize = PadKeySize.LARGE) + + val oscKeys = claim { ButtonNames.oscillate(it) } + if (oscKeys.isNotEmpty()) rows += PadRow(R.string.appliance_oscillate, PadRowStyle.CHIPS, keys = oscKeys.take(24), keySize = PadKeySize.LARGE) + + val timerKeys = claim { ButtonNames.timerKey(it) } + if (timerKeys.isNotEmpty()) rows += PadRow(R.string.appliance_timer, PadRowStyle.CHIPS, keys = timerKeys.take(24), keySize = PadKeySize.LARGE) + + val lightKeys = claim { ButtonNames.lightKey(it) } + if (lightKeys.isNotEmpty()) rows += PadRow(R.string.appliance_light, PadRowStyle.CHIPS, keys = lightKeys.take(24), keySize = PadKeySize.LARGE) + + // Family-specific middle sections. + when (family) { + PadFamily.AIR_TREATMENT -> { + val mist = claim { ButtonNames.humidityKey(it) } + if (mist.isNotEmpty()) rows += PadRow(R.string.appliance_humidity, PadRowStyle.CHIPS, keys = mist.take(24), keySize = PadKeySize.LARGE) + } + + PadFamily.AUDIO -> { + val vol = claim { ButtonNames.volUp(it) } + val volDn = claim { ButtonNames.volDown(it) } + val mute = claim { ButtonNames.mute(it) } + if (vol.isNotEmpty() && volDn.isNotEmpty()) { + rows += PadRow(R.string.appliance_volume, PadRowStyle.STEPPER, downKey = volDn.first(), upKey = vol.first()) + } + if (mute.isNotEmpty()) rows += PadRow(R.string.appliance_mute, PadRowStyle.CHIPS, keys = mute.take(24), keySize = PadKeySize.LARGE) + val src = claim { ButtonNames.audioSourceKey(it) } + if (src.isNotEmpty()) rows += PadRow(R.string.appliance_input, PadRowStyle.CHIPS, keys = src.take(24), keySize = PadKeySize.LARGE) + val sound = claim { ButtonNames.audioModeKey(it) } + if (sound.isNotEmpty()) rows += PadRow(R.string.appliance_sound_modes, PadRowStyle.CHIPS, keys = sound.take(24), keySize = PadKeySize.LARGE) + val tone = claim { ButtonNames.bassTrebleKey(it) } + if (tone.isNotEmpty()) rows += PadRow(R.string.appliance_sound_modes, PadRowStyle.CHIPS, keys = tone.take(24), keySize = PadKeySize.LARGE) + val play = claim { ButtonNames.transportKey(it) } + if (play.isNotEmpty()) rows += PadRow(R.string.appliance_playback, PadRowStyle.CHIPS, keys = play.take(24), keySize = PadKeySize.LARGE) + } + + PadFamily.DISPLAY -> { + val dpad = listOfNotNull( + claim { ButtonNames.up(it) }.firstOrNull(), + claim { ButtonNames.left(it) }.firstOrNull(), + claim { ButtonNames.ok(it) }.firstOrNull(), + claim { ButtonNames.right(it) }.firstOrNull(), + claim { ButtonNames.down(it) }.firstOrNull(), + ) + if (dpad.size >= 3) rows += PadRow(R.string.appliance_navigation, PadRowStyle.D_PAD, keys = dpad) + val nav = claim { + ButtonNames.home(it) || ButtonNames.menu(it) || ButtonNames.back(it) || ButtonNames.guide(it) + } + if (nav.isNotEmpty()) rows += PadRow( + if (dpad.isEmpty()) R.string.appliance_navigation else R.string.appliance_menu, + PadRowStyle.CHIPS, keys = nav.take(24), keySize = PadKeySize.LARGE, + ) + val src = claim { ButtonNames.source(it) } + if (src.isNotEmpty()) rows += PadRow(R.string.appliance_input, PadRowStyle.CHIPS, keys = src.take(24), keySize = PadKeySize.LARGE) + val vol = claim { ButtonNames.volUp(it) } + val volDn = claim { ButtonNames.volDown(it) } + val mute = claim { ButtonNames.mute(it) } + if (vol.isNotEmpty() && volDn.isNotEmpty()) { + rows += PadRow(R.string.appliance_volume, PadRowStyle.STEPPER, downKey = volDn.first(), upKey = vol.first()) + } + if (mute.isNotEmpty()) rows += PadRow(R.string.appliance_mute, PadRowStyle.CHIPS, keys = mute.take(24), keySize = PadKeySize.LARGE) + val tools = claim { ButtonNames.projectorKey(it) } + if (tools.isNotEmpty()) rows += PadRow(R.string.appliance_effects, PadRowStyle.CHIPS, keys = tools.take(24), keySize = PadKeySize.LARGE) + } + + PadFamily.LIGHTING -> { + val colors = claim { ButtonNames.colorKey(it) } + if (colors.isNotEmpty()) rows += PadRow(R.string.appliance_colors, PadRowStyle.CHIPS, keys = colors.take(24), keySize = PadKeySize.LARGE) + val bright = claim { ButtonNames.brightnessKey(it) } + if (bright.isNotEmpty()) rows += PadRow(R.string.appliance_brightness, PadRowStyle.CHIPS, keys = bright.take(24), keySize = PadKeySize.LARGE) + val fx = claim { ButtonNames.effectKey(it) } + if (fx.isNotEmpty()) rows += PadRow(R.string.appliance_effects, PadRowStyle.CHIPS, keys = fx.take(24), keySize = PadKeySize.LARGE) + } + + PadFamily.CLEANING -> { + val start = claim { ButtonNames.startStopKey(it) } + if (start.isNotEmpty()) rows += PadRow(R.string.ac_power, PadRowStyle.CHIPS, keys = start.take(24), keySize = PadKeySize.LARGE) + val clean = claim { ButtonNames.cleaningKey(it) } + if (clean.isNotEmpty()) rows += PadRow(R.string.appliance_cleaning, PadRowStyle.CHIPS, keys = clean.take(24), keySize = PadKeySize.LARGE) + val dock = claim { ButtonNames.dockKey(it) } + if (dock.isNotEmpty()) rows += PadRow(R.string.appliance_cleaning, PadRowStyle.CHIPS, keys = dock.take(24), keySize = PadKeySize.LARGE) + } + + PadFamily.CLIMATE -> Unit + PadFamily.TV -> Unit + } + + // Keypad, then leftovers. A remote's odd keys must stay reachable — but + // they arrive as several separate `claim` results that all used to render + // as their own "More keys" row, so a projector showed the same heading + // three times. Collect them into one row so the heading appears once. + // A keypad only when the remote really is a numeric pad. Colour keys on a + // light strip are named B1..B4/G1..G4, which `digit()` also accepts — that + // is not a keypad, so require most of 0-9 to be present. Otherwise the + // digit-ish labels stay unclaimed and fall through to the leftovers row. + val numeric = available.mapNotNull { it.name.lastOrNull { c -> c.isDigit() } }.toSet() + if (numeric.size >= 8) { + val digits = claim { ButtonNames.digit(it) } + rows += PadRow(R.string.appliance_keypad, PadRowStyle.KEYPAD, keys = digits.take(12)) + } + // A remote's odd keys must stay reachable, but dumping 24 of them as one + // "More keys" wall buries the pad's real controls (the projector's seven + // input chips, the vacuum's nine unmapped rows). Cap the visible tail + // and put the rest behind a single "···" tile that opens a sheet — Mi + // Remote's own pattern for exactly this problem. + // ponytail: capped at 8 visible. Upgrade path: group overflow keys by + // their own heading inside the sheet once a remote has >20 of them. + val rest = claim { true } + if (rest.isNotEmpty()) { + val split = PadOverflow.split(rest) + rows += PadRow(R.string.appliance_more, PadRowStyle.CHIPS, keys = split.visible) + if (split.overflow.isNotEmpty()) { + rows += PadRow(R.string.appliance_more, PadRowStyle.OVERFLOW, keys = split.overflow) + } + } + + // Two rules can land on the same heading — a vacuum has a bare "Mode" key + // and mode presets, a projector has a d-pad and menu keys that both call + // themselves "navigation". Printed twice it reads as a bug. Fold any + // consecutive pair that shares a heading into one row. + return rows.fold(mutableListOf()) { acc, row -> + val prev = acc.lastOrNull() + if (prev != null && prev.style == PadRowStyle.CHIPS && row.style == PadRowStyle.CHIPS && + prev.labelRes == row.labelRes && prev.labelOverride == row.labelOverride + ) { + acc[acc.lastIndex] = prev.copy(keys = (prev.keys + row.keys).distinctBy { it.name }.take(24)) + } else acc += row + acc + } +} + diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePadScreen.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePadScreen.kt new file mode 100644 index 0000000..329d021 --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/DevicePadScreen.kt @@ -0,0 +1,211 @@ +package com.erfanbagheri.controlix.ui + +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import com.erfanbagheri.controlix.R +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.data.FontScale +import com.erfanbagheri.controlix.data.IrCodeRepository +import com.erfanbagheri.controlix.data.SendLog +import com.erfanbagheri.controlix.data.SentEntry +import com.erfanbagheri.controlix.ir.IrTransmitter +import com.erfanbagheri.controlix.tr +import com.erfanbagheri.controlix.ui.theme.Accent +import com.erfanbagheri.controlix.ui.theme.PaperFaint +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll + +/** + * Renders a [PadRow] list built by [sectionsFor]. + * + * Composed to read like the TV pad (ui/Pad.kt), which is this app's own + * reference: same header pill with the emit pulse, same filled rounded key + * tiles with no stroke, same hairlines between sections, and the same + * pressable feel. What it does NOT copy is the TV layout — a fan has no + * d-pad and no channel rocker, so the body is still one row per real control. + * + * Key sizes: LARGE = two per line (primary actions), SMALL = three per line + * (supporting keys), SQUARE = one per cell (keypad, colour swatches). + */ +@Composable +fun DevicePadScreen( + deviceName: String?, + family: PadFamily, + remoteId: Int, + repo: IrCodeRepository?, + transmitter: IrTransmitter, + toast: ToastState, + sendLog: SendLogModel, + onBack: () -> Unit, +) { + var lastSent by remember(remoteId) { mutableStateOf(null) } + var emitKey by remember(remoteId) { mutableStateOf(null) } + var overflowKeys by remember(remoteId) { mutableStateOf?>(null) } + val view = LocalView.current + + // Own codes only. No sibling borrow: an appliance's keys are per-remote. + val available = remember(remoteId) { + runCatching { repo?.buttons(remoteId) }.getOrNull().orEmpty().map { + EffectiveButtons.Resolved(it.name, it.name, it.carrierHz, it.pattern, it.remoteId, 1, false) + } + } + val rows = remember(available, family) { sectionsFor(family, available) } + + fun transmit(key: EffectiveButtons.Resolved) { + val result = transmitter.transmitButtonResult(key.carrierHz, key.pattern) + sendLog.record( + if (result is SendResult.Sent) { + SentEntry( + deviceName ?: tr(R.string.pad_fallback), key.name, + key.carrierHz, key.pattern, System.currentTimeMillis(), + ) + } else { + SendLog.nothingSent( + deviceName ?: tr(R.string.pad_fallback), key.name, + sendFailureReason(result), System.currentTimeMillis(), + ) + }, + ) + if (result is SendResult.Sent) { + Feedback.send(view) + lastSent = tr(R.string.ac_sent, key.name) + emitKey = Any() + } else { + lastSent = tr(R.string.pad_not_sent) + toast.show( + if (!transmitter.hasIrEmitter()) tr(R.string.toast_no_ir_blaster) + else tr(R.string.toast_couldnt_send), + ) + } + } + + Column( + Modifier.fillMaxSize().applyTopInset().applyBottomInset().padding(horizontal = 24.dp), + ) { + Spacer(Modifier.height(12.dp)) + Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { + ActionIconView( + ActionIcon.Back, 26.dp, MaterialTheme.colorScheme.onSurface, autoMirror = true, + modifier = Modifier.pressable(onBack).padding(9.dp), + ) + Spacer(Modifier.weight(1f)) + Row( + Modifier + .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(24.dp)) + .padding(horizontal = 14.dp, vertical = 9.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Box(Modifier.size(20.dp), contentAlignment = Alignment.Center) { + EmitPulse(emitKey, Modifier.size(20.dp)) + Canvas(Modifier.size(8.dp)) { drawCircle(Accent) } + } + Text( + deviceName ?: tr(R.string.appliance_remote_title), + style = MaterialTheme.typography.titleMedium, + ) + } + Spacer(Modifier.weight(1f)) + Spacer(Modifier.size(44.dp)) + } + + Spacer(Modifier.height(20.dp)) + + if (rows.isEmpty()) { + Text( + tr(R.string.appliance_no_usable), + style = MaterialTheme.typography.bodyMedium, color = PaperFaint, + ) + return@Column + } + + Column(Modifier.weight(1f).verticalScroll(rememberScrollState())) { + rows.forEach { row -> + val label = row.labelOverride ?: tr(row.labelRes) + // A stepper carries its own label between the two keys, the + // way a rocker is silk-screened on a remote. Giving it a + // heading too would print the same word twice and turn six + // soundbar rockers into twelve stacked blocks. + if (row.style == PadRowStyle.STEPPER || row.style == PadRowStyle.OVERFLOW) { + // A stepper carries its own label between the two keys, the + // way a rocker is silk-screened on a remote. Giving it a + // heading too would print the same word twice and turn six + // soundbar rockers into twelve stacked blocks. + if (row.style == PadRowStyle.STEPPER) { + StepperRow( + row, label, + Modifier.fillMaxWidth().padding(vertical = 8.dp), + ::transmit, + ) + PadRowDivider() + } else { + OverflowTile(row.keys.size) { overflowKeys = row.keys } + PadRowDivider() + } + } else { + SectionHead(label) + PadRowDivider() + when (row.style) { + PadRowStyle.CHIPS -> KeyGrid(row.keys, row.keySize, ::transmit, row.chipLabels) + PadRowStyle.D_PAD -> DPad(row.keys, ::transmit) + PadRowStyle.KEYPAD -> DigitGrid(row.keys, ::transmit) + // Both handled above, alongside STEPPER: an untitled + // rows share the "no heading, just the control" branch. + PadRowStyle.STEPPER, PadRowStyle.OVERFLOW -> Unit + } + PadRowDivider() + } + } + if (lastSent != null) { + Text( + lastSent.orEmpty(), + style = MaterialTheme.typography.labelSmall, color = PaperFaint, + modifier = Modifier.padding(top = 10.dp), + ) + } + Spacer(Modifier.height(16.dp)) + } + } + + // Sheet lives outside the scrolling column: a ModalBottomSheet inside a + // verticalScroll parent measures against the scrolled content, not the + // window, and lands wherever the user stopped scrolling. + overflowKeys?.let { keys -> + ExtraKeysSheet( + keys = keys, + onKey = ::transmit, + onDismiss = { overflowKeys = null }, + ) + } +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/ExtraKeysSheet.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/ExtraKeysSheet.kt new file mode 100644 index 0000000..c8e4ff0 --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/ExtraKeysSheet.kt @@ -0,0 +1,63 @@ +package com.erfanbagheri.controlix.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.erfanbagheri.controlix.R +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.tr + +/** + * Overflow keys of an appliance remote that do not fit the main pad, listed + * in a bottom sheet. Reuses the pad's own [KeyGrid] so the tiles look like + * the rest of the product instead of a second key language. + * + * ponytail: a plain scrollable Column, not a LazyVerticalGrid — appliance + * overflow key counts are small (tens at most). Upgrade path: swap in + * LazyVerticalGrid if a remote ever ships hundreds of extra keys. + */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun ExtraKeysSheet( + keys: List, + onKey: (EffectiveButtons.Resolved) -> Unit, + onDismiss: () -> Unit, +) { + ModalBottomSheet( + onDismissRequest = onDismiss, + sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true), + containerColor = MaterialTheme.colorScheme.surface, + contentColor = MaterialTheme.colorScheme.onSurface, + ) { + Column( + Modifier + .fillMaxWidth() + .navigationBarsPadding() + .verticalScroll(rememberScrollState()) + .padding(horizontal = 24.dp, vertical = 20.dp), + ) { + SectionHead(tr(R.string.appliance_extra_keys)) + Spacer(Modifier.height(4.dp)) + Text( + tr(R.string.appliance_extra_keys_hint), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Spacer(Modifier.height(8.dp)) + KeyGrid(keys, PadKeySize.SMALL, onKey) + } + } +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/KeyGrid.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/KeyGrid.kt new file mode 100644 index 0000000..3e9740d --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/KeyGrid.kt @@ -0,0 +1,208 @@ +package com.erfanbagheri.controlix.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextDirection +import androidx.compose.ui.unit.dp +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.R +import com.erfanbagheri.controlix.data.FontScale +import com.erfanbagheri.controlix.tr + +/** + * A grid of real keys. + * + * Drawn exactly like the TV pad's [KeyTile] in ui/Pad.kt: a filled + * surfaceVariant tile at 20dp radius, no stroke, titleMedium label, minimum + * height that grows with the system font scale. That is the app's own + * remote language — appliance pads borrow it instead of inventing a second + * one, so a fan and a TV feel like the same product. + * + * LARGE = two per line (primary actions), SMALL = three per line + * (supporting keys), SQUARE = three per line at full height (keypads). + */ +@Composable +fun KeyGrid( + keys: List, + keySize: PadKeySize, + onTap: (EffectiveButtons.Resolved) -> Unit, + labels: List? = null, +) { + // A row holding one or two keys should not leave two thirds of the width + // empty with a stray pill floating at the edge — which is exactly what a + // fireplace (Power, Timer) looked like. One key fills the row; two split + // it. Only three or more fall back to the tile size's own column count. + val perRow = when { + keys.size == 1 -> 1 + keys.size == 2 -> 2 + keySize == PadKeySize.LARGE -> 2 + else -> 3 + } + val gap = 10.dp + Column( + Modifier.fillMaxWidth().padding(vertical = 10.dp), + verticalArrangement = Arrangement.spacedBy(gap), + ) { + // A projector lists "SOURCE VIDEO" and "INPUT VIDEO" — two codes, one + // visible label. Two identical tiles are a coin flip for the user, so + // the first wins and the twin is dropped. Pair each key with its label + // first so a dropped twin cannot shift the rest of the labels. + // ponytail: drops the duplicate code, not the label. Upgrade path: a + // long-press "all keys" sheet if a dropped code ever matters. + val items = keys.mapIndexed { i, k -> k to (labels?.getOrNull(i) ?: k.name) } + .distinctBy { prettyKey(it.second) } + items.chunked(perRow).forEach { chunk -> + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(gap)) { + chunk.forEach { (key, label) -> + KeyTile( + label = label, + keySize = keySize, + modifier = Modifier.weight(1f), + onClick = { onTap(key) }, + ) + } + // Keep a short last row aligned to the grid instead of letting + // two keys stretch across a three-column row. + repeat(perRow - chunk.size) { Spacer(Modifier.weight(1f)) } + } + } + } +} + +/** + * The DB writes key labels as `Subwf_Down`, `AVDelay_`, `VZTVRem`. Shown raw + * they read as source code. Underscores become spaces and the handful of + * abbreviations every soundbar remote uses get their full word back. + * + * ponytail: a fixed word map, not a translation layer — the ceiling is + * English-only appliance keys, which is what the DB carries. Upgrade path: + * per-brand label maps once a second brand needs different words. + */ +private val KEY_WORDS = mapOf( + "subwf" to "Subwoofer", "surr" to "Surround", "bal" to "Balance", + "vol" to "Volume", "avdelay" to "A/V Delay", "ch" to "Channel", + "temp" to "Temperature", "src" to "Source", "eq" to "EQ", + // A bare "Mode" key does not name a mode, it steps to the next one. + // Printed under a "Mode" heading the label would read "Mode / Mode". + "mode" to "Cycle", "humididier" to "Humidifier", +) + +fun prettyKey(raw: String): String { + val words = raw.replace('_', ' ').trim().split(' ').filter { it.isNotBlank() } + // "Source HDMI In" and "INPUT HDMI" are the same socket named twice — one + // key is the remote's menu entry, the other a direct input. Two tiles read + // the same in the hand, so the redundant word goes and the socket name + // stays: the row is already headed "Input". + val socket = words.size > 1 && (words[0].equals("Source", true) || words[0].equals("Input", true)) + // The same socket is spelled "SOURCE INPUT A" on one key and "INPUT A" on + // another, so every leading source/input word goes. What is left is often + // a bare letter ("A", "B", "D4") that means nothing on a tile — the row is + // headed "Input", so a short token gets that word back. + var drop = 0 + while (drop < words.size - 1 && + (words[drop].equals("Source", true) || words[drop].equals("Input", true)) + ) drop++ + val core = if (socket) words.drop(drop) else words + val kept = if (socket && core.size == 1 && core[0].length <= 3) listOf("Input") + core else core + val out = kept.joinToString(" ") { w -> + KEY_WORDS[w.lowercase()] ?: w.replaceFirstChar { it.uppercase() } + }.replace(Regex("\\s+"), " ").trim().ifBlank { raw } + // A duration like "5m" is a number followed by a Latin unit. In an RTL + // paragraph the bidi algorithm flips that run and the tile reads "m5" — + // the fan's whole mode grid came out backwards in Farsi. An LTR isolate + // keeps the run intact whatever the paragraph direction. + // ponytail: only digit-led labels need it. Upgrade path: full bidi + // formatting per key once a label mixes scripts mid-word. + return if (out.firstOrNull()?.isDigit() == true) "\u2066$out\u2069" else out +} + +/** One key: filled tile, 20dp radius, no border — the TV pad's own look. */ +@Composable +private fun KeyTile( + label: String, + keySize: PadKeySize, + modifier: Modifier = Modifier, + onClick: () -> Unit, +) { + val min = when (keySize) { + PadKeySize.LARGE -> 58.dp + PadKeySize.SMALL -> 50.dp + PadKeySize.SQUARE -> 62.dp + } + Box(modifier.heightIn(min = min * FontScale.heightMultiplier(LocalDensity.current.fontScale))) { + Box( + Modifier.fillMaxSize().bgTile(20.dp, MaterialTheme.colorScheme.surfaceVariant) + .pressable(onClick = onClick).padding(horizontal = 8.dp, vertical = 6.dp), + contentAlignment = Alignment.Center, + ) { + Text( + prettyKey(label), + style = MaterialTheme.typography.titleMedium.copy( + textDirection = + if (prettyKey(label).firstOrNull()?.isDigit() == true) TextDirection.Ltr + else TextDirection.Content, + ), + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + maxLines = 2, + ) + } + } +} + +/** Keypad: sorted 0-9, three per row, digits on square keys. */ +@Composable +fun DigitGrid(keys: List, onTap: (EffectiveButtons.Resolved) -> Unit) { + val sorted = keys.sortedBy { it.name.lastOrNull { c -> c.isDigit() } ?: ' ' } + KeyGrid(sorted, PadKeySize.SQUARE, onTap) +} + +/** + * The tail of a remote, one tap away. + * + * A projector carries twenty input codes and a vacuum a dozen unmapped ones. + * Printed as chips they push the pad's real controls off the first screen, so + * the extra keys live behind this tile — the same "···" cell Mi Remote puts at + * the end of an appliance grid. The count is shown because a bare ellipsis + * hides how much is behind it. + */ +@Composable +fun OverflowTile(count: Int, onClick: () -> Unit) { + Row(Modifier.fillMaxWidth().padding(vertical = 10.dp)) { + Box( + Modifier.weight(1f) + .heightIn(min = 58.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)) + .bgTile(20.dp, MaterialTheme.colorScheme.surfaceVariant) + .pressable(onClick = onClick), + contentAlignment = Alignment.Center, + ) { + Text( + "··· " + tr(R.string.appliance_more_count, count), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + maxLines = 1, + ) + } + } +} + +@Composable +fun PadRowDivider() { + HorizontalDivider(thickness = 1.dp, color = MaterialTheme.colorScheme.outline) +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/Nav.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/Nav.kt index acc8c8b..669638d 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/ui/Nav.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/Nav.kt @@ -438,7 +438,11 @@ fun ControlixNav(ir: IrTransmitter, repo: IrCodeRepository?, coldStart: Boolean // whichever pad was opened last. Opening a pad no longer // writes the tile's slot; the picker is its only writer. // AC remotes are stateful: their pad is a separate climate - // layout. Every other category keeps the normal TV pad. + // layout. Appliance families (fans, purifiers, audio, + // projectors, lighting, vacuums) have neither a channel + // nor a d-pad, so they get the data-driven appliance pad. + // TV-shaped categories keep the normal TV pad. + val family = saved?.let { PadFamily.familyFor(it.categorySlug) } if (saved?.isAc() == true) { AcPadScreen( deviceName = saved.name, @@ -449,6 +453,17 @@ fun ControlixNav(ir: IrTransmitter, repo: IrCodeRepository?, coldStart: Boolean sendLog = sendLogModel, onBack = { route = Route.Home }, ) + } else if (family != null && family != PadFamily.TV) { + DevicePadScreen( + deviceName = saved.name, + family = family, + remoteId = r.remoteId, + repo = repo, + transmitter = ir, + toast = toast, + sendLog = sendLogModel, + onBack = { route = Route.Home }, + ) } else PadScreen( deviceName = saved?.name, onRename = { newName -> saved?.let { model.rename(it.key, newName) } }, diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/StepperRow.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/StepperRow.kt new file mode 100644 index 0000000..356f5ac --- /dev/null +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/StepperRow.kt @@ -0,0 +1,74 @@ +package com.erfanbagheri.controlix.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import com.erfanbagheri.controlix.data.EffectiveButtons +import com.erfanbagheri.controlix.data.FontScale +import com.erfanbagheri.controlix.ui.theme.Accent +import com.erfanbagheri.controlix.ui.theme.PaperFaint + +/** A stepper row: − | label | + with bg-tiled, rounded tiles. */ +@Composable +fun StepperRow( + row: PadRow, + label: String, + modifier: Modifier = Modifier, + transmit: (EffectiveButtons.Resolved) -> Unit, +) { + val dn = row.downKey + val up = row.upKey + Row( + modifier.heightIn(min = 56.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + StepKey("−", dn != null, Modifier.weight(1f)) { dn?.let(transmit) } + Text( + prettyKey(label).ifBlank { "·" }, + style = MaterialTheme.typography.titleSmall, + color = Accent, + textAlign = TextAlign.Center, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1.4f), + ) + StepKey("+", up != null, Modifier.weight(1f)) { up?.let(transmit) } + } +} + +/** One tile of a stepper: filled surface, corner radius 14dp, titleSmall. */ +@Composable +fun StepKey(label: String, enabled: Boolean, modifier: Modifier = Modifier, onClick: () -> Unit) { + Box( + modifier = modifier + .height(56.dp * FontScale.heightMultiplier(LocalDensity.current.fontScale)) + .clip(RoundedCornerShape(14.dp)) + .background(MaterialTheme.colorScheme.surfaceVariant) + .then(if (enabled) Modifier.pressable(onClick) else Modifier), + contentAlignment = Alignment.Center, + ) { + Text( + label, + style = MaterialTheme.typography.titleMedium, + color = if (enabled) MaterialTheme.colorScheme.onSurface else PaperFaint.copy(alpha = 0.4f), + textAlign = TextAlign.Center, + ) + } +} diff --git a/app/src/main/java/com/erfanbagheri/controlix/ui/theme/Theme.kt b/app/src/main/java/com/erfanbagheri/controlix/ui/theme/Theme.kt index ab247d8..0322034 100644 --- a/app/src/main/java/com/erfanbagheri/controlix/ui/theme/Theme.kt +++ b/app/src/main/java/com/erfanbagheri/controlix/ui/theme/Theme.kt @@ -9,9 +9,12 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.unit.LayoutDirection import androidx.core.view.WindowCompat import com.erfanbagheri.controlix.isFa +import com.erfanbagheri.controlix.languageState private val DarkScheme = darkColorScheme( primary = Accent, onPrimary = Color(0xFF003312), @@ -64,11 +67,25 @@ fun ControlixTheme(content: @Composable () -> Unit) { WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !ThemeState.isDark } - MaterialTheme(colorScheme = scheme, typography = if (isFa()) AppTypographyFa else AppTypography) { - androidx.compose.material3.Surface( - color = scheme.background, - contentColor = scheme.onBackground, - ) { content() } + // languageState() is the Compose-observable mirror of the in-app choice, so + // this re-derives typography and direction in place when the language is + // switched; isFa() covers the follow-system case ("" override). + val lang = languageState() + val fa = if (lang.isNotEmpty()) lang == "fa" else isFa() + MaterialTheme(colorScheme = scheme, typography = if (fa) AppTypographyFa else AppTypography) { + // Pin layout direction to the in-app language. The activity's wrapped + // context sets it on creation, but every later configuration delivery + // (insets, font scale, the recreate() after a language switch) carries + // the *system* locale, which reverts Compose to LTR until the next + // cold start. Providing it here makes RTL follow the language instead + // of the framework's config, so the drawer and chrome stay mirrored. + val direction = if (fa) LayoutDirection.Rtl else LayoutDirection.Ltr + androidx.compose.runtime.CompositionLocalProvider(LocalLayoutDirection provides direction) { + androidx.compose.material3.Surface( + color = scheme.background, + contentColor = scheme.onBackground, + ) { content() } + } } } diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index 83f049d..f160b73 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -349,6 +349,30 @@ ریموت کولر روشن غیرفعال است: این ریموت کلید روشنِ جدا ندارد. خاموش از کلید خاموشی خودِ این ریموت استفاده می‌کند. + + ریموت + دما + سرعت + حالت + پرتاب باد + زمان‌سنج + نور + صدا + ورودی + رنگ‌ها + افکت‌ها + روشنایی + حالت‌های صدا + تمیزکاری + جهت‌ها + پخش + رطوبت + صفحه کلید + دیگر کلیدها + +%1$d کلید دیگر + کلیدهای بیشتر + کلیدهایی که پد نمایش نمی‌دهد. + این ریموت کد قابل استفاده‌ای در پایگاه داده ندارد. شامل: %1$s این ریموت کلید روشن ندارد. شامل: %1$s این ریموت کلید خاموش ندارد. شامل: %1$s @@ -608,4 +632,6 @@ کنفرانس تصویری تخته‌های سفید شوینده‌های شیشه - دستگاه مادون‌قرمز (جامعه) + دستگاه مادون‌قرمز (جامعه) بی‌صدا + منو + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6d4bb21..4d89735 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -349,6 +349,30 @@ AC remote On is disabled: this remote has no separate power-on key. Off uses this remote\'s own off key. + + Remote + Temperature + Speed + Mode + Oscillation + Timer + Light + Volume + Input + Colors + Effects + Brightness + Sound modes + Cleaning + Navigation + Playback + Humidity + Keypad + More keys + +%1$d more + Extra keys + Keys this pad leaves out. + This remote has no usable codes in the database. It carries: %1$s This remote has no power-on key. It carries: %1$s This remote has no power-off key. It carries: %1$s @@ -608,4 +632,6 @@ Videoconferencing Whiteboards Window cleaners - IR Blaster (community) + IR Blaster (community) Mute + Menu + diff --git a/app/src/test/java/com/erfanbagheri/controlix/data/PadOverflowTest.kt b/app/src/test/java/com/erfanbagheri/controlix/data/PadOverflowTest.kt new file mode 100644 index 0000000..030cb2e --- /dev/null +++ b/app/src/test/java/com/erfanbagheri/controlix/data/PadOverflowTest.kt @@ -0,0 +1,36 @@ +package com.erfanbagheri.controlix.data + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +/** PadOverflow.split: visible-row cap vs "More keys" sheet. */ +class PadOverflowTest { + + @Test fun emptyKeysLeaveBothListsEmpty() { + val s = PadOverflow.split(emptyList()) + assertTrue(s.visible.isEmpty()) + assertTrue(s.overflow.isEmpty()) + } + + @Test fun atTheLimitEverythingIsVisible() { + val keys = (1..PadOverflow.VISIBLE_LIMIT).map { "k$it" } + val s = PadOverflow.split(keys) + assertEquals(keys, s.visible) + assertTrue(s.overflow.isEmpty()) + } + + @Test fun oneOverTheLimitSpillsIntoOverflow() { + val keys = (1..PadOverflow.VISIBLE_LIMIT + 1).map { "k$it" } + val s = PadOverflow.split(keys) + assertEquals(keys.take(PadOverflow.VISIBLE_LIMIT), s.visible) + assertEquals(listOf("k9"), s.overflow) + } + + @Test fun duplicatesArePreservedNotDeduped() { + val s = PadOverflow.split(listOf("vol+", "vol+", "mute", "vol+", "vol+", "vol+", "vol+", "vol+", "vol+")) + assertEquals(listOf("vol+", "vol+", "mute", "vol+", "vol+", "vol+", "vol+", "vol+"), s.visible) + assertEquals(1, s.overflow.size) + assertEquals(listOf("vol+"), s.overflow) + } +} diff --git a/docs/PRIVACY-POLICY.md b/docs/PRIVACY-POLICY.md new file mode 100644 index 0000000..ae4fcab --- /dev/null +++ b/docs/PRIVACY-POLICY.md @@ -0,0 +1,113 @@ +# Privacy Policy — Controlix + +**Last updated:** 15 October 2026 + +## Summary + +Controlix collects nothing. It does not send, store or share any personal data. +There is no server, no analytics, no advertising, no account and no crash +reporting. The app has no `INTERNET` permission at all, which means it is +technically incapable of transmitting anything off the device. + +## Data we do not collect + +- **No personal information.** The app has no sign-up, no login, no profile. + It never asks for your name, email address, phone number, or payment details. +- **No usage analytics.** We do not track screen views, taps, session length, + retention, or any behavioural telemetry. There is no third-party analytics + SDK (Google Analytics, Firebase, Mixpanel, Amplitude, Facebook SDK, etc.) + anywhere in the app or its dependencies. +- **No advertising identifiers.** The app contains no ads and no ad SDK. It + never reads the Google Advertising ID, AAID, IDFA or any device identifier. +- **No device identifiers.** We do not read the IMEI, serial number, MAC + address, Android ID or build fingerprint. +- **No location.** The app has no `ACCESS_FINE_LOCATION` or + `ACCESS_COARSE_LOCATION` permission. It never knows where you are. + (A coarse location permission is only ever requested by Android itself on + some devices as a prerequisite for Wi-Fi name scanning — this app performs + no Wi-Fi scanning at all.) +- **No crash logs.** Nothing reports crashes back to us. If the app crashes, + only you see it. +- **No network access whatsoever in the published build.** The release manifest + declares only `android.permission.TRANSMIT_IR` and + `android.permission.CAMERA`. There is no `INTERNET` permission, so the + operating system itself blocks any outbound connection. + +## Where your data actually lives + +Everything you create stays on your device, in the app's private storage +directory (`/data/data/com.erfanbagheri.controlix/`), which other apps cannot +read. + +| Data | Where it is stored | Does it leave the device | +| --- | --- | --- | +| Remote configurations you pick | App-private database | No | +| Favourite devices / pins | App-private database | No | +| Macros you record | App-private database | No | +| Custom IR codes you import | App-private database | No | +| App settings and preferences | App-private shared preferences | No | + +The remote-control code database bundled with the app is a read-only database +file inside the APK. It contains device categories and IR commands, nothing +about you. + +## The two permissions we do use, and what they are for + +**`android.permission.TRANSMIT_IR`** — Used for exactly one thing: emitting +infrared light through your phone's IR blaster to control a TV, set-top box, +fan, air conditioner or similar device. This is the entire purpose of the app. +It is granted automatically at install time and cannot be revoked. Your phone +can send IR only while you are actively pressing a control in the app, or +running an automation (Tasker / Shortcuts) you set up yourself. + +**`android.permission.CAMERA`** — Used for one thing only: scanning a QR code +to import a shared remote configuration. The permission is requested at +runtime via the standard Android permission dialog, and only when you open +the scanner yourself. Images from the camera are processed entirely on-device +and are never saved, never uploaded and never stored. You can deny the +permission and use every other feature of the app. + +The permission `android.hardware.camera` is declared `required="false"`, so +the app installs and works on tablets, TVs and phones without any camera. +Similarly `android.hardware.consumerir` is `required="false"`, so the app +installs on phones without an IR blaster — those screens stay fully browsable, +only transmission is unavailable. + +## Sharing and exporting + +Controlix can share a remote configuration you have explicitly chosen, via the +standard Android share sheet. That is always a conscious action by you: tapping +a share button, then choosing where to send it. The app itself never posts, +uploads or transmits anything on its own. An optional database refresh +feature, if you ever enable it, is the only code path that could contact a +network, and it is off by default in the published build. + +## Third-party services + +None. Controlix has no third-party services, SDKs, servers or APIs of any +kind. There is no one we could share data with even if we wanted to. + +## Data retention and deletion + +Because no data leaves your device, retention is entirely under your control: +**uninstalling the app deletes everything.** Every remote, macro, pin and +setting is stored in the app's private directory and is removed by Android on +uninstall. There is no cloud backup of your data anywhere. + +## Children + +Controlix is a universal remote control. It contains no ads, no in-app +purchases, no social features and no user-generated content, and it collects +no data of any kind from anyone, including children. The app is suitable for +all ages. + +## Changes to this policy + +If this policy ever changes, the revised version will be published on the +app's page and in the project's release notes, with an updated date. + +## Contact + +- **Developer:** Erfan Bagheri +- **Email:** +- **Source repository:** diff --git a/docs/img/icon-512.png b/docs/img/icon-512.png new file mode 100644 index 0000000..9c594b8 Binary files /dev/null and b/docs/img/icon-512.png differ diff --git a/docs/store/LISTING.md b/docs/store/LISTING.md new file mode 100644 index 0000000..7d2a534 --- /dev/null +++ b/docs/store/LISTING.md @@ -0,0 +1,149 @@ +# Controlix — Store listing (Myket, Cafe Bazar, other Iranian stores) + +Prepared for: Myket Publishing Rules of 15 October 2026, checked against +. + +--- + +## ⚠️ Myket hard requirement — Target SDK + +Myket's notice *"الزام به‌روزرسانی Target SDK Version به API Level 34"* +(published 1405/04/21) says: **from 1 Aban 1405 (= 23 October 2026) Myket +will not publish new apps or new updates whose targetSdk is below 34.** + +**Status: PASS.** `targetSdk = 35`, `compileSdk = 35`, `buildToolsVersion = 35.0.0`. +No action needed. (This is 8 days away, so we are safe.) + +--- + +## ✓ Verified good to go + +| Check | Requirement | Our value | Verdict | +| --- | --- | --- | --- | +| targetSdk | ≥ 34 (Myket, from 23 Oct 2026) | **35** | PASS | +| minSdk | no rule | 26 (Android 8.0) | PASS | +| Signing | release key + `zipalign` | Gradle `release` build, minified (R8), enums | PASS | +| Permissions match function | Myket rejects apps requesting unrelated permissions | only `TRANSMIT_IR` + `CAMERA`, both core features | PASS | +| INTERNET permission | must match functionality | **none declared at all** | PASS | +| Ads / analytics / tracking SDKs | must be disclosed, none present | none — no SDKs beyond AndroidX/Compose/ZXing | PASS | +| Spyware / malware classification | Myket runs Kaspersky, Bitdefender, McAfee before publishing | offline-first, no network | PASS | +| Users' sensitive data handling | privacy rules | nothing collected, nothing stored off-device | PASS | +| Copyright | must own or license content | GPL-3.0 project; IrpTransmogrifier used **read-only**, no Mi Remote codes | PASS | +| App title (fa + en) | required | `Controlix` | PASS | +| App icon | square, high quality, no copyright marks, no excessive text | adaptive icon, 1024×1024 foreground, themed, monochrome layer for Android 13 themed icons | PASS | +| Descriptions (fa + en) | required | below | PASS | +| Screenshots | **at least 3, from inside the app** | **7 captured** from the running app — `docs/store/screenshots/` | PASS | +| Package name | reserved, unique | `com.erfanbagheri.controlix` | PASS | +| Age rating | required | 3+ (no violence, no social content) | PASS | +| Price | required | Free | PASS | +| Category | required | ابزار / ابزارهای کاربردی (Tools / Utilities) | PASS | + +## 🔴 Action needed before publishing + +1. **Screenshots (mine).** Myket requires ≥3 real screenshots taken from + inside the app. I will generate these by driving the app on an emulator. +2. **Signing keystore.** Confirm the release build is signed with your + production keystore and **back it up offline** — if you lose it you can + never publish an update again. +3. **Store account + developer profile** — Myket requires 2FA and a completed + developer profile (phone verification + legal information). +4. **Sign in on panel:** → ثبت نام → «برنامه جدید» + → reserve the package name `com.erfanbagheri.controlix`. + +--- + +## Titles + +| Language | Title | +| --- | --- | +| فارسی | **Controlix — کنترلر هوشمند** | +| English | **Controlix — Smart Remote** | + +Myket requires a **Persian title and an English title** (choose-app-title rules: +must be relevant, must not be too long, must not contain copyright marks). + +## Tagline / short description + +**فارسی:** کنترلر اینفرارد را روی گوشی ات ببر — بدون حساب، بدون تبلیغ، بدون اینترنت. + +**English:** Universal IR remote on your phone — no account, no ads, no internet. + +Myket's tagline guidance: a short one-line summary shown under the title. +Keep under ~80 chars. ✓ + +## Full description + +### فارسی (Persian) + +Controlix یک کنترلر اینفراردی است که روی گوشی ایران راه می‌اندازد — بدون حساب کاربری، بدون تبلیغ، بدون دسترسی به اینترنت، بدون ردیابی. کدهای دستگاه‌ها را از پایگاه داده حمل‌شده به صورت محلی جستجو کنید، روی ریموت بزنید و دستگاه روشن یا خاموش می‌شود. ادامهٔ کار همان نیاز است: یک گوشی دارای فلش مادون‌قرمز. + +مایکیت یا هر فروشگاه دیگر، حساب کاربری نمی‌خواهد. هیچ‌چیز از گوشی شما بیرون نمی‌رود. + +— ایمن و بسته: برنامه هیچ مجوز اینترنتی ندارد، پس از نظر فنی ارسال داده از دستگاه شما غیرممکن است. بدون آنالیز، بدون تبلیغ، بدون شناسه دستگاه. + +— فارسی کامل و از راست به چپ: کل محیط برنامه فارسی است و چیدمان کاملاً راست‌به‌چپ است. انگلیسی هم در دسترس است، با کم‌رنگ‌سازی فارسی. + +— پایگاه داده محلی بزرگ: دسته‌ها و کدهای دستگاه‌ها (تلویزیون، گیرنده، پخش‌کننده، کولر، فن، پروژکتور) همراه با خود اپ عرضه می‌شود. جستجو از پوشه یا نام دستگاه. + +— کدهای سفارشی: کدهای IR را به صورت دستی وارد کنید یا با اسکن QR کد وارد کنید. همهٔ چیزار اپ-محلی می‌ماند. + +— ماکرو و کاشی‌ها: چند فرمان را در یک ماکرو هماهنگ کنید و آن را روی کاشی سریع یا ویجت خانهٔ خود بگذارید. یک ویجت نمایشگر و یک ویجت ماکرو هم موجود است. + +— خودکارسازی: با Tasker یا Intent_dispatcher اندروید دستگاه‌ها را کنترل کنید. پیش‌فرض شما خودتان کنترل می‌کنید. + +— همه روی دستگاه بدون فلش IR هم کار می‌کند: همهٔ صفحه‌ها باز و قابل مرور است، فقط ارسال خاموش است. یک باگ یا خطای بازگشتی وجود ندارد. + +— منبع باز تحت GPL-3.0: کد برنامه را ببینید و با آن نسخهٔ خودتان را بسازید. + +### English (full) + +Controlix is an infrared remote that runs on your phone — no account, no ads, no internet, no tracking. Search the bundled device database locally, press a button on the remote, and the device responds. Nothing leaves your phone. + +— Private and closed: the app declares no INTERNET permission, so transmitting anything off your device is technically impossible. No analytics, no ads, no device identifiers. + +— Farsi-first with real RTL: the whole interface is Persian and fully right-to-left. English is available too. + +— Large local database: categories and codes for TVs, set-top boxes, players, air conditioners, fans and projectors ship inside the APK. Search by folder or by device name. + +— Custom codes: enter IR codes manually or scan a QR code to import a shared remote. Everything stays local. + +— Macros and widgets: chain several commands into one macro, pin it to a quick control or a home-screen widget. A remote widget and a macro widget are included. + +— Automation: drive devices from Tasker or the Android shortcut dispatcher. Off by default — you are always in control. + +— Works on phones without an IR blaster: every screen stays fully browsable, only transmission is unavailable. + +— Open source under GPL-3.0. + +## App page details to fill in the Myket panel + +| Field | Value | +| --- | --- | +| عنوان فارسی | Controlix — کنترلر هوشمند | +| عنوان انگلیسی | Controlix — Smart Remote | +| نوع و دسته‌بندی | ابزار ← ابزارهای کاربردی (Utilities) | +| قیمت | رایگان (Free) | +| رده سنی | 3+ | +| وضعیت قیمت‌گذاری | بدون پرداخت درون‌برنامه‌ای | +| نام بسته (reserve now) | `com.erfanbagheri.controlix` | +| توضیحات نسخه فارسی | نسخهٔ ۱٫۰٫۰: انتشار اول | +| توضیحات نسخه انگلیسی | 1.0.0: first release | + +## Contact info (Myket requires it) + +- Email: +- Website: +- Telegram: *(fill in if you have one)* + +## Release checklist before the first upload + +- [ ] Download the signed APK from the GitHub release — **do not** upload an + unsigned debug build. +- [ ] Sign the APK with the production keystore (`keytool -list -v -keystore ...`). +- [ ] `zipalign -p -v 4 in.apk out.apk` and verify with `apksigner verify`. +- [ ] Confirm `targetSdkVersion` is 34+ in the merged manifest. +- [ ] Screenshots taken from inside the app (≥3, 1080×1920 or larger). +- [ ] Store icon 512×512 PNG square. +- [ ] Developer profile complete + 2FA enabled. +- [ ] Store notice: no INTERNET permission → the "data collection" questions + are all "no", including "does your app share data with third parties". diff --git a/docs/store/README.md b/docs/store/README.md new file mode 100644 index 0000000..f8482bf --- /dev/null +++ b/docs/store/README.md @@ -0,0 +1,59 @@ +# Controlix — Store Publishing Checklist + +Status as of **16 October 2026**, before the v0.0.32 release. +Everything here has been verified against Myket's published rules +(). + +## Files in this folder + +| File | What it is | +| --- | --- | +| `LISTING.md` | Ready-to-paste Persian + English title, tagline, description, category, contact info, and the panel fields for Myket. | +| `../PRIVACY-POLICY.md` | Full privacy policy. Publish it somewhere reachable by URL (GitHub Pages, your site, or a GitHub blob link) and paste that URL into Myket's privacy field. | +| `../img/icon-512.png` | 512x512 store icon, rendered from `docs/img/icon.png` (1024x1024 source). | +| `screenshots/*.png` | Seven real in-app screenshots, 1344x2992 (Pixel 8 Pro class), captured from the running app on an emulator. Myket requires at least 3. | + +## Technical verdict + +| Requirement | Value in the project | Verdict | +| --- | --- | --- | +| targetSdk (Myket: **≥ 34, enforced 1 Aban 1405 = 23 Oct 2026**) | **35** | PASS | +| minSdk | 26 | PASS | +| Signing | `signingConfigs.release` wired to `KEYSTORE_FILE` / `KEYSTORE_PASSWORD` / `KEY_ALIAS` / `KEY_PASSWORD`, all four present as GitHub Actions secrets; release build runs R8 minification | PASS | +| Release APK is signed | enforced by a new gate in `release.yml` that fails the job on any `*unsigned*` APK | PASS | +| Published APK signature, verified against the real downloaded v0.0.32 asset | `apksigner verify` → **Verifies**; APK Signature Scheme v2, 1 signer, `CN=Controlix, O=ErfanBagheri, C=IR`, RSA 2048, cert SHA-256 `86247d84e91289a23cb0fb49f287c1481994b7f3100a1a33a38256f1df1b07f1` | PASS | +| Permissions vs functionality | only `android.permission.TRANSMIT_IR` and `android.permission.CAMERA` (plus the platform-generated `DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION`) | PASS | +| INTERNET permission | **not declared** — the app cannot transmit anything | PASS | +| Ads / analytics / tracking SDKs | none in the dependency tree | PASS | +| Hardware features declared optional | `android.hardware.consumerir` and `android.hardware.camera` are both `required="false"`, so the app installs on every device, not just IR-equipped phones (IR blasters are rare on 2024+ flagships) | PASS | +| Package name | `com.erfanbagheri.controlix` | PASS | +| Age rating / price / category | 3+ / free / ابزارهای کاربردی (Utilities) | PASS | +| Farsi + RTL | whole UI localised, RTL-first | PASS | +| Open-source licence | GPL-3.0 | PASS | + +## Still needed from you (manual) + +1. **Developer account** on — complete the profile, phone + verification and legal info, enable 2FA. +2. **Reserve the app page** and the package name before uploading anything. +3. **Publish the privacy policy** at a stable URL and paste that URL into the + Myket panel (the `راهنمای حریم خصوصی` section). +4. **Upload the signed APK** from the latest GitHub release + () — never an + unsigned local build. Local `./gradlew assembleRelease` on a machine with + no keystore produces `app-release-unsigned.apk`; that file is **not** + publishable, which is why the workflow now hard-fails on it. +5. **Back up the release keystore offline** (outside this repo, off the cloud + drive). If it is lost, no future update can ever be published to the same + package name. +6. In Myket's "data sharing / privacy security" questionnaire, everything is + "no": the app collects no data, shares no data with third parties, and has + no encryption-in-transit requirement because it has no transit at all. + +## Other Iranian stores + +The same APK, description and privacy policy apply to Cafe Bazaar, Iran Apps, +Jhoobin, Sakht Afzar and Market Up. Cafe Bazaar additionally wants an "app +authorization" declaration; answer that with the same two permissions +(`TRANSMIT_IR` for control, `CAMERA` for QR import) and note that both are +core features and that `INTERNET` is absent. diff --git a/docs/store/screenshots/01-home.png b/docs/store/screenshots/01-home.png new file mode 100644 index 0000000..a1917b5 Binary files /dev/null and b/docs/store/screenshots/01-home.png differ diff --git a/docs/store/screenshots/02-categories.png b/docs/store/screenshots/02-categories.png new file mode 100644 index 0000000..f16c6af Binary files /dev/null and b/docs/store/screenshots/02-categories.png differ diff --git a/docs/store/screenshots/03-brands.png b/docs/store/screenshots/03-brands.png new file mode 100644 index 0000000..41195e3 Binary files /dev/null and b/docs/store/screenshots/03-brands.png differ diff --git a/docs/store/screenshots/04-aoc-tvs.png b/docs/store/screenshots/04-aoc-tvs.png new file mode 100644 index 0000000..6b40930 Binary files /dev/null and b/docs/store/screenshots/04-aoc-tvs.png differ diff --git a/docs/store/screenshots/05-menu.png b/docs/store/screenshots/05-menu.png new file mode 100644 index 0000000..d044bf2 Binary files /dev/null and b/docs/store/screenshots/05-menu.png differ diff --git a/docs/store/screenshots/06-tools.png b/docs/store/screenshots/06-tools.png new file mode 100644 index 0000000..7d26860 Binary files /dev/null and b/docs/store/screenshots/06-tools.png differ diff --git a/docs/store/screenshots/07-ir-test.png b/docs/store/screenshots/07-ir-test.png new file mode 100644 index 0000000..63a9c42 Binary files /dev/null and b/docs/store/screenshots/07-ir-test.png differ