From 542c5fa091538dad51f08a8b0f9c5b60735823ee Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Mon, 26 Jun 2023 22:53:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B5=E9=9D=A2=E6=94=B9?= =?UTF-8?q?=E4=B8=BAMd3=E9=A3=8E=E6=A0=BC=EF=BC=8C=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E7=9A=84=E5=8F=98=E6=9B=B4=E4=BC=9A=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E7=94=9F=E6=95=88=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 17 +++++-- .../coldmint/rust/pro/FileManagerActivity.kt | 6 +-- .../com/coldmint/rust/pro/MainActivity.kt | 18 ++++++- .../com/coldmint/rust/pro/SettingsActivity.kt | 49 ++++++++++++------ app/src/main/res/values/themes.xml | 2 + app/src/main/res/xml/root_preferences.xml | 50 +++++++++---------- 6 files changed, 93 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7b3ec8a..3ce6ace 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,12 +24,12 @@ android { keyAlias 'coldmint' } } - compileSdkVersion 32 + compileSdkVersion 33 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.coldmint.rust.pro" - minSdkVersion 21 + minSdkVersion 23 targetSdkVersion 33 versionCode 27 versionName "2.1 Bata5(2023-4-21)" @@ -72,6 +72,13 @@ android { dependencies { + configurations.all { + exclude group: 'androidx.appcompat', module: 'appcompat' + } + implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0') { + exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib' + } + implementation platform('com.google.firebase:firebase-bom:31.1.1') implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-crashlytics-ktx' @@ -92,6 +99,7 @@ dependencies { kapt "androidx.room:room-compiler:2.4.0" implementation "dev.rikka.rikkax.preference:simplemenu-preference:1.0.3" + implementation "dev.rikka.rikkax.material:material-preference:2.0.0" //沉浸式状态栏 implementation 'com.gyf.immersionbar:immersionbar:3.0.0' @@ -113,8 +121,9 @@ dependencies { implementation 'com.github.florent37:glidepalette:2.1.2' implementation 'cat.ereza:customactivityoncrash:2.3.0' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" - implementation 'androidx.appcompat:appcompat:1.5.0' - implementation 'com.google.android.material:material:1.9.0-beta01' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'dev.rikka.rikkax.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 19f4591..97e18d8 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -638,11 +638,11 @@ class FileManagerActivity : BaseActivity() { */ fun loadMineBookmarksMenu() { if (this::menuBinding.isInitialized) { - menuBinding.mineBookmarksMenu.subMenu.clear() + menuBinding.mineBookmarksMenu.subMenu?.clear() viewModel.getBookmarkManager().fromList(object : BookmarkListener { override fun find(path: String, name: String) { - val item = menuBinding.mineBookmarksMenu.subMenu.add(name) - item.setOnMenuItemClickListener { + val item = menuBinding.mineBookmarksMenu.subMenu?.add(name) + item?.setOnMenuItemClickListener { viewModel.currentPathLiveData.value = path true } diff --git a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt index bdd3592..f0444b5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/MainActivity.kt @@ -41,6 +41,7 @@ import com.coldmint.rust.pro.databinding.HeadLayoutBinding import com.coldmint.rust.pro.fragments.UserGroupFragment import com.coldmint.rust.pro.tool.EventRecord import com.coldmint.rust.pro.viewmodel.StartViewModel +import com.google.android.material.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.tabs.TabLayout import com.google.gson.Gson @@ -56,6 +57,7 @@ class MainActivity : BaseActivity() { private lateinit var appBarConfiguration: AppBarConfiguration private var oldLanguage: String? = null private var first = true + var oldDynamicColor = false var tabLayout: TabLayout? = null val headLayout by lazy { HeadLayoutBinding.inflate(layoutInflater) @@ -238,6 +240,14 @@ class MainActivity : BaseActivity() { if (first) { first = false } else { + val newDynamicColor = AppSettings.getValue( + AppSettings.Setting.DynamicColor, + DynamicColors.isDynamicColorAvailable() + ); + if (oldDynamicColor != newDynamicColor) { + recreate() + return + } val newLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en") if (oldLanguage != newLanguage) { recreate() @@ -269,7 +279,7 @@ class MainActivity : BaseActivity() { // } val gitHub = menu.findItem(R.id.github) gitHub.setOnMenuItemClickListener { - AppOperator.useBrowserAccessWebPage(this,"https://github.com/Cold-Mint/RustAssistant") + AppOperator.useBrowserAccessWebPage(this, "https://github.com/Cold-Mint/RustAssistant") false } // val help = menu.findItem(R.id.help) @@ -315,11 +325,13 @@ class MainActivity : BaseActivity() { intent.putExtra("type", "mod") startActivity(intent) } + templateItem -> { val intent = Intent(this, CreationWizardActivity::class.java) intent.putExtra("type", "template") startActivity(intent) } + else -> { } } @@ -721,6 +733,10 @@ class MainActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { oldLanguage = AppSettings.getValue(AppSettings.Setting.AppLanguage, "en") + oldDynamicColor = AppSettings.getValue( + AppSettings.Setting.DynamicColor, + DynamicColors.isDynamicColorAvailable() + ); useToolbarSetSupportActionBar() initNav() observeStartViewModel() diff --git a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt index 8bfd43b..54b45d5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SettingsActivity.kt @@ -18,9 +18,11 @@ import com.coldmint.rust.pro.databinding.ActivitySettingsBinding import com.coldmint.rust.pro.tool.GlobalMethod import com.google.android.material.color.DynamicColors import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import rikka.material.preference.MaterialSwitchPreference import java.io.File import java.util.* import kotlin.collections.ArrayList @@ -53,49 +55,58 @@ class SettingsActivity : BaseActivity() { } val english_editing_mode = - manager.findPreference(requireContext().getString(R.string.setting_english_editing_mode)) + manager.findPreference(requireContext().getString(R.string.setting_english_editing_mode)) - val customizeEdit = manager.findPreference("customize_edit") + val customizeEdit = manager.findPreference("customize_edit") customizeEdit!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = Intent(requireContext(), CustomizeEditTextActivity::class.java) startActivity(intent) true } - val clipboardCue = manager.findPreference(requireContext().getString(R.string.setting_clipboard_cue)) + val clipboardCue = + manager.findPreference(requireContext().getString(R.string.setting_clipboard_cue)) // Only show a toast for Android 12 and lower. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2){ + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) { //如果是安卓12或更低 clipboardCue?.isEnabled = false } val dynamicColor = - manager.findPreference(requireContext().getString(R.string.setting_dynamic_color)) + manager.findPreference(requireContext().getString(R.string.setting_dynamic_color)) if (!DynamicColors.isDynamicColorAvailable()) { //动态颜色不可用 dynamicColor?.summary = getString(R.string.dynamic_color_disabled) dynamicColor?.isEnabled = false } + dynamicColor?.setOnPreferenceChangeListener { preference, newValue -> + if (newValue is Boolean) { + if (AppSettings.getValue(AppSettings.Setting.DynamicColor, DynamicColors.isDynamicColorAvailable()) != newValue) { + activity?.recreate() + } + } + true + } val errorInfo = - manager.findPreference(requireContext().getString(R.string.setting_see_error_info)) + manager.findPreference(requireContext().getString(R.string.setting_see_error_info)) errorInfo!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { startActivity(Intent(context, ErrorInfoActivity::class.java)) true } -// val obtainSourceCode = manager.findPreference(requireContext().getString(R.string.setting_obtain_source_code)) +// val obtainSourceCode = manager.findPreference(requireContext().getString(R.string.setting_obtain_source_code)) // obtainSourceCode!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { // AppOperator.useBrowserAccessWebPage(requireContext(),"https://github.com/Cold-Mint/RustAssistant") // true // } - val game = manager.findPreference("set_game_pack") + val game = manager.findPreference("set_game_pack") game!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { startActivity(Intent(context, ApplicationListActivity::class.java)) true } val valueTypeManager = - manager.findPreference("value_type_manager") + manager.findPreference("value_type_manager") valueTypeManager!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { val intent = Intent(context, ValueTypeActivity::class.java) @@ -103,7 +114,7 @@ class SettingsActivity : BaseActivity() { true } val openRecoveryStation = - manager.findPreference("open_recovery_station") + manager.findPreference("open_recovery_station") openRecoveryStation!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { startActivity(Intent(context, RecyclingStationActivity::class.java)) @@ -111,7 +122,7 @@ class SettingsActivity : BaseActivity() { } val clearCache = - manager.findPreference(getString(R.string.setting_clear_cache)) + manager.findPreference(getString(R.string.setting_clear_cache)) clearCache!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { val items = ArrayList() @@ -143,10 +154,12 @@ class SettingsActivity : BaseActivity() { Glide.get(requireContext()).clearMemory() } } + getString(R.string.code_cache) -> { FileOperator.delete_files(requireContext().codeCacheDir) FileOperator.delete_files(requireContext().cacheDir) } + getString(R.string.history_cache) -> { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { FileOperator.delete_files(File(requireActivity().applicationContext.dataDir.absolutePath + "/databases")) @@ -179,8 +192,8 @@ class SettingsActivity : BaseActivity() { true } - val nightMode: SwitchPreference? = - manager.findPreference(getString(R.string.setting_night_mode)) + val nightMode: MaterialSwitchPreference? = + manager.findPreference(getString(R.string.setting_night_mode)) nightMode?.setOnPreferenceChangeListener { preference, newValue -> val booleanValue = newValue as Boolean if (booleanValue) { @@ -192,8 +205,8 @@ class SettingsActivity : BaseActivity() { } - val nightModeFollowSystem: SwitchPreference? = - manager.findPreference(getString(R.string.setting_night_mode_follow_system)) + val nightModeFollowSystem: MaterialSwitchPreference? = + manager.findPreference(getString(R.string.setting_night_mode_follow_system)) nightModeFollowSystem?.setOnPreferenceChangeListener { preference, newValue -> if (nightMode != null) { val useValue = newValue as Boolean @@ -232,7 +245,7 @@ class SettingsActivity : BaseActivity() { } val useCommunity = - manager.findPreference(getString(R.string.setting_use_the_community_as_the_launch_page)) + manager.findPreference(getString(R.string.setting_use_the_community_as_the_launch_page)) if (useCommunity != null) { useCommunity.isVisible = false } @@ -252,6 +265,10 @@ class SettingsActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { + this.getTheme().applyStyle( + rikka.material.preference.R.style.ThemeOverlay_Rikka_Material3_Preference, + true + ); title = getString(R.string.set_up) setReturnButton() val settingsFragment = SettingsFragment() diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 583ca55..b263ec6 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -41,6 +41,7 @@ @color/md_theme_light_inverseSurface @color/md_theme_light_inversePrimary @style/Widget.Material3.PopupMenu + @style/PreferenceThemeOverlay.Rikka.Material3 @@ -71,6 +72,7 @@ @color/md_theme_dark_inverseOnSurface @color/md_theme_dark_inverseSurface @color/md_theme_dark_inversePrimary + @style/PreferenceThemeOverlay.Rikka.Material3 diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 68237a8..f8d6052 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -12,7 +12,7 @@ app:title="@string/reply_title" app:useSimpleSummaryProvider="true" /> - - - - - - - - - - - @@ -139,7 +139,7 @@ app:key="gamePackGroup" app:title="@string/game_pack"> - @@ -157,14 +157,14 @@ app:title="@string/mod_folder" app:useSimpleSummaryProvider="true" /> - - - - - @@ -225,14 +225,14 @@ app:key="templateGroup" app:title="@string/template_title"> - - - - - @@ -272,17 +272,17 @@ app:key="developerModeGroup" app:title="@string/sync_header"> - + - -