mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-01-30 18:44:52 +01:00
ブックマークボタンの表示をデフォルトONにする。デフォルト値の変化に追従しやすくするため、設定画面を開いた時や保存する時にスイッチの値がデフォルトと同じなら設定を削除する。
This commit is contained in:
parent
20d7f8dbfe
commit
3844f7247b
@ -704,9 +704,13 @@ class ActAppSettingChild : AppCompatActivity()
|
||||
private fun loadUIFromData() {
|
||||
load_busy = true
|
||||
|
||||
for(si in booleanViewList) {
|
||||
si.view.isChecked = si.info(pref)
|
||||
}
|
||||
pref.edit().also{ e->
|
||||
for(si in booleanViewList) {
|
||||
val curVal = si.info(pref)
|
||||
si.view.isChecked = curVal
|
||||
if( curVal == si.info.defVal) si.info.remove(e)
|
||||
}
|
||||
}.apply()
|
||||
|
||||
spBackButtonAction?.setSelection(Pref.ipBackButtonAction(pref))
|
||||
spRepliesCount?.setSelection(Pref.ipRepliesCount(pref))
|
||||
@ -834,7 +838,7 @@ class ActAppSettingChild : AppCompatActivity()
|
||||
val e = pref.edit()
|
||||
|
||||
for(si in booleanViewList) {
|
||||
e.putBoolean(si.info.key, si.view.isChecked)
|
||||
si.info.putOrRemove(e,si.view.isChecked)
|
||||
}
|
||||
|
||||
spDefaultAccount?.let {
|
||||
|
@ -40,7 +40,7 @@ fun SharedPreferences.Editor.remove(item : BasePref<*>) : SharedPreferences.Edit
|
||||
|
||||
class BooleanPref(
|
||||
key : String,
|
||||
private val defVal : Boolean,
|
||||
val defVal : Boolean,
|
||||
val id : Int =0
|
||||
) : BasePref<Boolean>(key) {
|
||||
|
||||
@ -51,6 +51,15 @@ class BooleanPref(
|
||||
override fun put(editor : SharedPreferences.Editor, v : Boolean) {
|
||||
editor.putBoolean(key, v)
|
||||
}
|
||||
|
||||
// put if value is not default, remove if value is same to default
|
||||
fun putOrRemove(editor : SharedPreferences.Editor, v : Boolean) {
|
||||
if( v != defVal) {
|
||||
editor.putBoolean(key, v)
|
||||
}else{
|
||||
editor.remove(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class IntPref(key : String, val defVal : Int) : BasePref<Int>(key) {
|
||||
@ -460,7 +469,7 @@ object Pref {
|
||||
|
||||
val bpShowBookmarkButton = BooleanPref(
|
||||
"ShowBookmarkButton",
|
||||
false,
|
||||
true,
|
||||
R.id.swShowBookmarkButton
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user