mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(input): keep full insets while the kit fits, restore the library after a failed save
This commit is contained in:
1 parent
10b21321b7
commit
cd5e824c1b
5 files changed
+42
-13
No files matched your search
@@ -284,11 +284,11 @@ class KitLayoutTest {
|
||||
|
||||
@Test fun insetsThatLeaveLessRoomShrinkTheKitInsteadOfOverlappingIt() {
|
||||
for (kit in PadKit.entries) for ((w, h, safe) in listOf(Triple(1600, 900, Rect(0, 60, 0, 0)), Triple(1600, 900, Rect(0, 730, 0, 0)),
|
||||
Triple(1600, 900, Rect(0, 200, 0, 0)), Triple(1600, 900, Rect(0, 200, 0, 150)),
|
||||
Triple(1600, 900, Rect(0, 200, 0, 0)), Triple(1600, 900, Rect(0, 200, 0, 150)), Triple(1600, 900, Rect(0, 390, 0, 0)),
|
||||
Triple(1920, 1080, Rect(80, 120, 80, 90)), Triple(2400, 1080, Rect(120, 30, 60, 40)))) {
|
||||
val elements = KitLayout.elements(context, kit, w, h, safe)
|
||||
assertEquals("$kit $w x $h $safe", emptyList<Pair<String, String>>(), overlapping(elements, w, h))
|
||||
if (safe.top + safe.bottom <= h * .4f) for (e in elements) {
|
||||
if (safe.top + safe.bottom <= 400) for (e in elements) {
|
||||
val (x, y, ew, eh) = px(e, w, h).toList()
|
||||
assertTrue("$kit $safe ${e.id}", x >= safe.left - .5f && y >= safe.top - .5f && x + ew <= w - safe.right + .5f && y + eh <= h - safe.bottom + .5f)
|
||||
}
|
||||
|
||||
@@ -178,4 +178,28 @@ class OnScreenControlPrefsTest {
|
||||
val noDpad = edited.withLayout(saved.copy(elements = saved.elements.filterNot { it.id == KitLayout.DPAD_ID }))
|
||||
assertNull(noDpad.preset(bindings.id).elements["legacy:up"])
|
||||
}
|
||||
|
||||
@Test fun aFailedRecoverySaveLeavesTheStoredLibraryAsItWas() {
|
||||
val stored = JSONObject().put("version", 1).put("profiles", "broken").toString()
|
||||
val real = context.getSharedPreferences("input-profiles", Context.MODE_PRIVATE)
|
||||
real.edit().clear().putString("library", stored).commit()
|
||||
val failing = object : android.content.ContextWrapper(context) {
|
||||
override fun getSharedPreferences(name: String, mode: Int): android.content.SharedPreferences {
|
||||
val prefs = super.getSharedPreferences(name, mode)
|
||||
return object : android.content.SharedPreferences by prefs {
|
||||
override fun edit(): android.content.SharedPreferences.Editor {
|
||||
val editor = prefs.edit()
|
||||
return object : android.content.SharedPreferences.Editor by editor {
|
||||
override fun putString(key: String?, value: String?) = apply { editor.putString(key, value) }
|
||||
override fun remove(key: String?) = apply { editor.remove(key) }
|
||||
override fun commit(): Boolean { editor.apply(); return false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(runCatching { InputLibraries.update(failing) { it } }.isFailure)
|
||||
assertEquals(stored, real.getString("library", null))
|
||||
assertTrue(real.all.keys.none { it.startsWith("library-recovery.") })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user