Skip to content

Commit

Permalink
removida controlPreference
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Dec 25, 2024
1 parent 3165197 commit e780470
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 483 deletions.
43 changes: 0 additions & 43 deletions AnkiDroid/src/main/java/com/ichi2/anki/reviewer/MappableBinding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
package com.ichi2.anki.reviewer

import android.content.Context
import android.content.SharedPreferences
import androidx.annotation.CheckResult
import com.ichi2.anki.R
import com.ichi2.anki.cardviewer.Gesture
import com.ichi2.anki.cardviewer.ScreenAction
import com.ichi2.anki.cardviewer.ViewerCommand
import com.ichi2.anki.reviewer.Binding.AxisButtonBinding
import com.ichi2.anki.reviewer.Binding.GestureInput
import com.ichi2.anki.reviewer.Binding.KeyBinding
Expand Down Expand Up @@ -104,23 +102,6 @@ sealed class MappableBinding(
.mapNotNull { it.toPreferenceString() }
.joinToString(prefix = VERSION_PREFIX, separator = PREF_SEPARATOR.toString())

@CheckResult
fun fromString(s: String): MappableBinding? {
if (s.isEmpty()) {
return null
}
return try {
// the prefix of the serialized
when (s[0]) {
'r' -> ReviewerBinding.fromString(s.substring(1))
else -> null
}
} catch (e: Exception) {
Timber.w(e, "failed to deserialize binding")
null
}
}

@CheckResult
fun getPreferenceBindingStrings(string: String): List<String> {
if (string.isEmpty()) return emptyList()
Expand All @@ -130,30 +111,6 @@ sealed class MappableBinding(
}
return string.substring(VERSION_PREFIX.length).split(PREF_SEPARATOR).filter { it.isNotEmpty() }
}

@CheckResult
fun fromPreferenceString(string: String?): MutableList<MappableBinding> {
if (string.isNullOrEmpty()) return ArrayList()
try {
val version = string.takeWhile { x -> x != '/' }
val remainder = string.substring(version.length + 1) // skip the /
if (version != "1") {
Timber.w("cannot handle version '$version'")
return ArrayList()
}
return remainder.split(PREF_SEPARATOR).mapNotNull { fromString(it) }.toMutableList()
} catch (e: Exception) {
Timber.w(e, "Failed to deserialize preference")
return ArrayList()
}
}

@CheckResult
fun allMappings(prefs: SharedPreferences): MutableList<Pair<ViewerCommand, MutableList<MappableBinding>>> =
ViewerCommand.entries
.map {
Pair(it, it.getBindings(prefs).toMutableList<MappableBinding>())
}.toMutableList()
}
}

Expand Down
Loading

0 comments on commit e780470

Please sign in to comment.