|
|
@ -36,6 +36,18 @@ import java.io.File |
|
|
|
class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val setLightBgImage = registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
|
|
|
|
setBgFromUri(it, PreferKey.bgImage) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val setDarkBgImage = registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
|
|
|
|
setBgFromUri(it, PreferKey.bgImageN) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
addPreferencesFromResource(R.xml.pref_config_theme) |
|
|
|
addPreferencesFromResource(R.xml.pref_config_theme) |
|
|
|
if (Build.VERSION.SDK_INT < 26) { |
|
|
|
if (Build.VERSION.SDK_INT < 26) { |
|
|
@ -181,42 +193,26 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
"themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") |
|
|
|
"themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") |
|
|
|
"saveDayTheme", "saveNightTheme" -> saveThemeAlert(key) |
|
|
|
"saveDayTheme", "saveNightTheme" -> saveThemeAlert(key) |
|
|
|
PreferKey.bgImage -> if (getPrefString(PreferKey.bgImage).isNullOrEmpty()) { |
|
|
|
PreferKey.bgImage -> if (getPrefString(PreferKey.bgImage).isNullOrEmpty()) { |
|
|
|
registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
setLightBgImage.launch("image/*") |
|
|
|
setBgFromUri(it, PreferKey.bgImage) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.launch("image/*") |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> |
|
|
|
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> |
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
removePref(PreferKey.bgImage) |
|
|
|
removePref(PreferKey.bgImage) |
|
|
|
upTheme(false) |
|
|
|
upTheme(false) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
setLightBgImage.launch("image/*") |
|
|
|
setBgFromUri(it, PreferKey.bgImage) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.launch("image/*") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
PreferKey.bgImageN -> if (getPrefString(PreferKey.bgImageN).isNullOrEmpty()) { |
|
|
|
PreferKey.bgImageN -> if (getPrefString(PreferKey.bgImageN).isNullOrEmpty()) { |
|
|
|
registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
setDarkBgImage.launch("image/*") |
|
|
|
setBgFromUri(it, PreferKey.bgImageN) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.launch("image/*") |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> |
|
|
|
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> |
|
|
|
if (i == 0) { |
|
|
|
if (i == 0) { |
|
|
|
removePref(PreferKey.bgImageN) |
|
|
|
removePref(PreferKey.bgImageN) |
|
|
|
upTheme(true) |
|
|
|
upTheme(true) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
registerForActivityResult(ActivityResultContracts.GetContent()) { |
|
|
|
setDarkBgImage.launch("image/*") |
|
|
|
setBgFromUri(it, PreferKey.bgImageN) { |
|
|
|
|
|
|
|
upTheme(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.launch("image/*") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|