HapeLee 1 год назад
Родитель
Сommit
5bf4a21e69

+ 2 - 0
app/build.gradle

@@ -304,4 +304,6 @@ dependencies {
 
     //com.github.AmrDeveloper:CodeView代码编辑已集成到应用内
     //epubLib集成到应用内
+
+    implementation libs.androidx.datastore.preferences
 }

+ 0 - 31
app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt

@@ -120,24 +120,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
         preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this)
     }
 
-//    override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
-//        menuInflater.inflate(R.menu.theme_config, menu)
-//        menu.applyTint(requireContext())
-//    }
-
-//    override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
-//        when (menuItem.itemId) {
-//            R.id.menu_theme_mode -> {
-//                AppConfig.isNightTheme = !AppConfig.isNightTheme
-//                ThemeConfig.applyDayNight(requireContext())
-//                return true
-//            }
-//        }
-//        return false
-//    }
-        //不使用菜单
-
-
     override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
         sharedPreferences ?: return
         when (key) {
@@ -171,19 +153,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
     @SuppressLint("PrivateResource")
     override fun onPreferenceTreeClick(preference: Preference): Boolean {
         when (val key = preference.key) {
-//            PreferKey.barElevation -> NumberPickerDialog(requireContext())
-//                .setTitle(getString(R.string.bar_elevation))
-//                .setMaxValue(32)
-//                .setMinValue(0)
-//                .setValue(AppConfig.elevation)
-//                .setCustomButton((R.string.btn_default_s)) {
-//                    AppConfig.elevation = AppConst.sysElevation
-//                    recreateActivities()
-//                }
-//                .show {
-//                    AppConfig.elevation = it
-//                    recreateActivities()
-//                }
 
             PreferKey.fontScale -> NumberPickerDialog(requireContext())
                 .setTitle(getString(R.string.font_scale))

+ 4 - 1
app/src/main/java/io/legato/kazusa/utils/ContextExtensions.kt

@@ -34,6 +34,7 @@ import androidx.annotation.DrawableRes
 import androidx.core.content.ContextCompat
 import androidx.core.content.FileProvider
 import androidx.core.content.edit
+import androidx.datastore.preferences.preferencesDataStore
 import androidx.preference.PreferenceManager
 import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
 import io.legato.kazusa.R
@@ -76,7 +77,6 @@ fun Context.startActivityForBook(
     startActivity(intent)
 }
 
-
 inline fun <reified T : Service> Context.startService(configIntent: Intent.() -> Unit = {}) {
     startService(Intent(this, T::class.java).apply(configIntent))
 }
@@ -414,3 +414,6 @@ val Context.channel: String
 
 val Context.isDebuggable: Boolean
     get() = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0
+
+val Context.dataStore by preferencesDataStore(name = "settings")
+

+ 2 - 0
gradle/libs.versions.toml

@@ -1,5 +1,6 @@
 [versions]
 
+datastorePreferences = "1.0.0"
 kotlin = "2.1.21"
 ksp = "2.1.21-2.0.1"
 agp = "8.10.0"
@@ -63,6 +64,7 @@ androidx-annotation = { group = "androidx.annotation", name = "annotation", vers
 #androidx-annotation-experimental = { group = "androidx.annotation", name = "annotation-experimental", version = "1.3.1" }
 
 androidx-collection = { module = "androidx.collection:collection", version.ref = "collection" }
+androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
 appcompat-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
 androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }