设置页面改为Md3风格,动态颜色的变更会立即生效了。

This commit is contained in:
Cold-Mint 2023-06-26 22:53:09 +08:00
parent 01715baa99
commit 542c5fa091
6 changed files with 93 additions and 49 deletions

View File

@ -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"

View File

@ -638,11 +638,11 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
*/
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
}

View File

@ -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<ActivityMainBinding>() {
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<ActivityMainBinding>() {
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<ActivityMainBinding>() {
// }
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<ActivityMainBinding>() {
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<ActivityMainBinding>() {
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()

View File

@ -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<ActivitySettingsBinding>() {
}
val english_editing_mode =
manager.findPreference<SwitchPreference>(requireContext().getString(R.string.setting_english_editing_mode))
manager.findPreference<MaterialSwitchPreference>(requireContext().getString(R.string.setting_english_editing_mode))
val customizeEdit = manager.findPreference<PreferenceScreen>("customize_edit")
val customizeEdit = manager.findPreference<Preference>("customize_edit")
customizeEdit!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val intent = Intent(requireContext(), CustomizeEditTextActivity::class.java)
startActivity(intent)
true
}
val clipboardCue = manager.findPreference<SwitchPreference>(requireContext().getString(R.string.setting_clipboard_cue))
val clipboardCue =
manager.findPreference<MaterialSwitchPreference>(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<SwitchPreference>(requireContext().getString(R.string.setting_dynamic_color))
manager.findPreference<MaterialSwitchPreference>(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<PreferenceScreen>(requireContext().getString(R.string.setting_see_error_info))
manager.findPreference<Preference>(requireContext().getString(R.string.setting_see_error_info))
errorInfo!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivity(Intent(context, ErrorInfoActivity::class.java))
true
}
// val obtainSourceCode = manager.findPreference<PreferenceScreen>(requireContext().getString(R.string.setting_obtain_source_code))
// val obtainSourceCode = manager.findPreference<Preference>(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<PreferenceScreen>("set_game_pack")
val game = manager.findPreference<Preference>("set_game_pack")
game!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivity(Intent(context, ApplicationListActivity::class.java))
true
}
val valueTypeManager =
manager.findPreference<PreferenceScreen>("value_type_manager")
manager.findPreference<Preference>("value_type_manager")
valueTypeManager!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
val intent = Intent(context, ValueTypeActivity::class.java)
@ -103,7 +114,7 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
true
}
val openRecoveryStation =
manager.findPreference<PreferenceScreen>("open_recovery_station")
manager.findPreference<Preference>("open_recovery_station")
openRecoveryStation!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
startActivity(Intent(context, RecyclingStationActivity::class.java))
@ -111,7 +122,7 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
}
val clearCache =
manager.findPreference<PreferenceScreen>(getString(R.string.setting_clear_cache))
manager.findPreference<Preference>(getString(R.string.setting_clear_cache))
clearCache!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
val items = ArrayList<String>()
@ -143,10 +154,12 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
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<ActivitySettingsBinding>() {
true
}
val nightMode: SwitchPreference? =
manager.findPreference<SwitchPreference>(getString(R.string.setting_night_mode))
val nightMode: MaterialSwitchPreference? =
manager.findPreference<MaterialSwitchPreference>(getString(R.string.setting_night_mode))
nightMode?.setOnPreferenceChangeListener { preference, newValue ->
val booleanValue = newValue as Boolean
if (booleanValue) {
@ -192,8 +205,8 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
}
val nightModeFollowSystem: SwitchPreference? =
manager.findPreference<SwitchPreference>(getString(R.string.setting_night_mode_follow_system))
val nightModeFollowSystem: MaterialSwitchPreference? =
manager.findPreference<MaterialSwitchPreference>(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<ActivitySettingsBinding>() {
}
val useCommunity =
manager.findPreference<SwitchPreference>(getString(R.string.setting_use_the_community_as_the_launch_page))
manager.findPreference<MaterialSwitchPreference>(getString(R.string.setting_use_the_community_as_the_launch_page))
if (useCommunity != null) {
useCommunity.isVisible = false
}
@ -252,6 +265,10 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
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()

View File

@ -41,6 +41,7 @@
<item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item>
<item name="popupMenuStyle">@style/Widget.Material3.PopupMenu</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Rikka.Material3</item>
</style>
@ -71,6 +72,7 @@
<item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Rikka.Material3</item>
</style>
<!--设置标签为小写-->

View File

@ -12,7 +12,7 @@
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:defaultValue="true"
android:summary="@string/clipboard_cue_tip"
android:title="@string/clipboard_cue"
@ -24,28 +24,28 @@
<PreferenceCategory android:title="@string/appearance">
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:defaultValue="true"
android:summary="@string/dynamic_color_tip"
android:title="@string/dynamic_color"
app:key="@string/setting_dynamic_color"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:title="@string/night_mode_follow_system"
app:defaultValue="true"
app:key="@string/setting_night_mode_follow_system"
app:summary="@string/night_mode_follow_system_tip"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:title="@string/night_mode"
app:defaultValue="false"
app:key="@string/setting_night_mode"
app:summary="@string/night_mode_auto"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:title="@string/use_the_community_as_the_launch_page"
app:defaultValue="true"
app:key="@string/setting_use_the_community_as_the_launch_page"
@ -72,7 +72,7 @@
<PreferenceCategory android:title="@string/data_transfer">
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:title="@string/using_mobile_networks"
app:defaultValue="false"
app:key="@string/setting_use_mobile_network"
@ -91,13 +91,13 @@
app:key="editGroup"
app:title="@string/edit_title">
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="false"
app:key="@string/setting_english_editing_mode"
app:summary="@string/english_editing_mode_describe"
app:title="@string/english_editing_mode" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_use_jetBrains_mono_font"
app:summary="@string/use_jetBrains_mono_font_describe"
@ -108,7 +108,7 @@
app:title="@string/custom_symbol"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:defaultValue="true"
android:key="@string/setting_simple_display_of_auto_complete_menu"
android:title="@string/simple_display_of_auto_complete_menu"
@ -122,13 +122,13 @@
app:title="@string/identifiers_prompt_number"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_auto_save"
app:summary="@string/auto_save_describe"
app:title="@string/auto_save" />
<PreferenceScreen
<Preference
app:key="customize_edit"
app:title="@string/customize_edit_text"
app:summary="@string/customize_edit_text_description"/>
@ -139,7 +139,7 @@
app:key="gamePackGroup"
app:title="@string/game_pack">
<PreferenceScreen
<Preference
app:key="set_game_pack"
app:summary="@string/select_the_game_package_description"
app:title="@string/select_the_game_pack" />
@ -157,14 +157,14 @@
app:title="@string/mod_folder"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_auto_create_nomedia"
app:summaryOff="@string/auto_create_nomedia_off"
app:summaryOn="@string/auto_create_nomedia_on"
app:title="@string/auto_create_nomedia" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_keep_rwmod_file"
app:summary="@string/keep_rwmod_file_description"
@ -176,7 +176,7 @@
app:useSimpleSummaryProvider="true" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_enable_recovery_station"
app:summary="@string/description_of_the_recovery_station"
@ -197,13 +197,13 @@
app:title="@string/recovery_station_file_save_days"
app:useSimpleSummaryProvider="true" />
<PreferenceScreen
<Preference
app:dependency="@string/setting_enable_recovery_station"
app:key="open_recovery_station"
app:summary="@string/description_of_manage_the_recovery_station"
app:title="@string/manage_the_recovery_station" />
<PreferenceScreen
<Preference
app:key="value_type_manager"
app:summary="@string/value_type_manager_describe"
app:title="@string/value_type_manager" />
@ -225,14 +225,14 @@
app:key="templateGroup"
app:title="@string/template_title">
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="false"
app:key="@string/setting_only_load_conant_language_temple"
app:summaryOff="@string/only_load_coniant_language_template_off"
app:summaryOn="@string/only_load_coniant_language_template_off"
app:title="@string/only_load_coniant_language_template" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="true"
app:key="@string/setting_independent_folder"
app:summary="@string/independent_folder_description"
@ -243,13 +243,13 @@
<PreferenceCategory
android:title="@string/update_and_iteration"
app:key="updateGroup">
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:defaultValue="false"
app:key="@string/setting_check_beta_update"
app:summary="@string/check_beta_update_describe"
app:title="@string/check_beta_update" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
android:defaultValue="true"
android:key="@string/setting_experience_the_plan"
app:summary="@string/experience_the_plan_describe"
@ -261,7 +261,7 @@
app:key="cacheGroup"
app:title="@string/cache">
<PreferenceScreen
<Preference
app:key="@string/setting_clear_cache"
app:summary="@string/clear_cache_description"
app:title="@string/clear_cache" />
@ -272,17 +272,17 @@
app:key="developerModeGroup"
app:title="@string/sync_header">
<!-- <PreferenceScreen-->
<!-- <Preference-->
<!-- app:key="@string/setting_obtain_source_code"-->
<!-- android:summary="@string/obtain_source_code_msg"-->
<!-- app:title="@string/obtain_source_code"/>-->
<PreferenceScreen
<Preference
app:key="@string/setting_see_error_info"
app:summary="@string/see_error_info_tip"
app:title="@string/see_error_info" />
<SwitchPreference
<rikka.material.preference.MaterialSwitchPreference
app:key="@string/setting_developer_mode"
app:summaryOff="@string/developers_mode_off"
app:summaryOn="@string/developers_mode_on"