diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 18885ad6..3d9d6f78 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,15 +39,10 @@ - { - val intent = Intent(this, MiscActivity::class.java) + val intent = Intent(this, PreferenceActivity::class.java) + intent.putExtra("preference","misc") startActivity(intent) } R.id.setting_menu -> { - val intent = Intent(this, SettingsActivity::class.java) + val intent = Intent(this, PreferenceActivity::class.java) + intent.putExtra("preference","setting") startActivity(intent) } R.id.about_menu -> { diff --git a/app/src/main/java/com/jakting/shareclean/ManageActivity.kt b/app/src/main/java/com/jakting/shareclean/ManageActivity.kt index b709a296..16b87de0 100644 --- a/app/src/main/java/com/jakting/shareclean/ManageActivity.kt +++ b/app/src/main/java/com/jakting/shareclean/ManageActivity.kt @@ -81,7 +81,7 @@ open class ManageActivity : BaseActivity() { intentDataList[intentDataIndex].check = true } } - intentDataList.sortWith(compareBy({ it.check }, { "${it.app_name} - ${it.activity_name}" })) + intentDataList.sortWith(compareBy({ !it.check }, { "${it.app_name} - ${it.activity_name}" })) (adapter as AppsAdapter).notifyDataSetChanged() apps_swipeLayout.finishRefresh() } diff --git a/app/src/main/java/com/jakting/shareclean/MiscActivity.kt b/app/src/main/java/com/jakting/shareclean/MiscActivity.kt deleted file mode 100644 index 566deccc..00000000 --- a/app/src/main/java/com/jakting/shareclean/MiscActivity.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.jakting.shareclean - -import android.content.Context -import android.content.SharedPreferences -import android.content.SharedPreferences.OnSharedPreferenceChangeListener -import android.os.Bundle -import com.jakting.shareclean.utils.setDirectShare -import moe.shizuku.preference.Preference -import moe.shizuku.preference.PreferenceFragment - - -class MiscActivity : BaseActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_misc) - if (savedInstanceState == null) { - val fragment = MiscFragment() - supportFragmentManager.beginTransaction().replace(R.id.misc, fragment).commit() - } - - setSupportActionBar(findViewById(R.id.toolbar)) - if (supportActionBar != null) { - supportActionBar!!.title = getString(R.string.misc_title) - //supportActionBar!!.subtitle = "v" + BuildConfig.VERSION_NAME - } -// if (!getDarkModeStatus(this)) { -// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR -// } - supportActionBar?.setDisplayHomeAsUpEnabled(true) - } - - internal class MiscFragment : PreferenceFragment(), - OnSharedPreferenceChangeListener, Preference.OnPreferenceChangeListener { - override fun onCreatePreferences(bundle: Bundle?, s: String?) { - preferenceManager.defaultPackages = arrayOf(BuildConfig.APPLICATION_ID + ".") - preferenceManager.sharedPreferencesName = "settings" - preferenceManager.sharedPreferencesMode = Context.MODE_PRIVATE - setPreferencesFromResource(R.xml.misc, null) - - } - - override fun onCreateItemDecoration(): DividerDecoration { - return CategoryDivideDividerDecoration() - //return new DefaultDividerDecoration(); - } - - override fun onPause() { - super.onPause() - preferenceScreen.sharedPreferences - .unregisterOnSharedPreferenceChangeListener(this) - } - - override fun onResume() { - super.onResume() - preferenceScreen.sharedPreferences - .registerOnSharedPreferenceChangeListener(this) - } - - override fun onSharedPreferenceChanged( - sharedPreferences: SharedPreferences, - key: String - ) { - //logd("onSharedPreferenceChanged $key") - val sp = activity!!.getSharedPreferences("settings", Context.MODE_PRIVATE) - when (key) { - "switch_disable_direct_share" -> setDirectShare(sp, context) - } - } - - override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { -// logd( -// getString( -// R.string.on_preference_change_toast_message, -// preference.key, -// newValue.toString() -// ) -// ) - return true - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/jakting/shareclean/PreferenceActivity.kt b/app/src/main/java/com/jakting/shareclean/PreferenceActivity.kt new file mode 100644 index 00000000..e96aa6d8 --- /dev/null +++ b/app/src/main/java/com/jakting/shareclean/PreferenceActivity.kt @@ -0,0 +1,33 @@ +package com.jakting.shareclean + +import android.os.Bundle +import com.jakting.shareclean.fragment.MiscFragment +import com.jakting.shareclean.fragment.SettingFragment + +class PreferenceActivity : BaseActivity() { + private val miscFragment = MiscFragment() + private val settingFragment = SettingFragment() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_preference) + setSupportActionBar(findViewById(R.id.toolbar)) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + when(intent.getStringExtra("preference")){ + "misc"->{ + supportFragmentManager.beginTransaction().replace(R.id.preference,miscFragment).commit() + if (supportActionBar != null) { + supportActionBar!!.title = getString(R.string.misc_title) + } + } + "setting"->{ + supportFragmentManager.beginTransaction().replace(R.id.preference,settingFragment).commit() + if (supportActionBar != null) { + supportActionBar!!.title = getString(R.string.setting_title) + } + } + } + + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/jakting/shareclean/SettingsActivity.kt b/app/src/main/java/com/jakting/shareclean/SettingsActivity.kt deleted file mode 100644 index d9dc3887..00000000 --- a/app/src/main/java/com/jakting/shareclean/SettingsActivity.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.jakting.shareclean - -import android.content.Context -import android.content.SharedPreferences -import android.content.SharedPreferences.OnSharedPreferenceChangeListener -import android.os.Bundle -import com.jakting.shareclean.utils.setDark -import com.jakting.shareclean.utils.setLang -import moe.shizuku.preference.ListPreference -import moe.shizuku.preference.Preference -import moe.shizuku.preference.PreferenceFragment - - -class SettingsActivity : BaseActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_settings) - if (savedInstanceState == null) { - val fragment = SettingsFragment() - supportFragmentManager.beginTransaction().replace(R.id.settings, fragment).commit() - } - - setSupportActionBar(findViewById(R.id.toolbar)) - if (supportActionBar != null) { - supportActionBar!!.title = getString(R.string.setting_title) - //supportActionBar!!.subtitle = "v" + BuildConfig.VERSION_NAME - } -// if (!getDarkModeStatus(this)) { -// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR -// } - supportActionBar?.setDisplayHomeAsUpEnabled(true) - } - - internal class SettingsFragment : PreferenceFragment(), - OnSharedPreferenceChangeListener, Preference.OnPreferenceChangeListener { - override fun onCreatePreferences(bundle: Bundle?, s: String?) { - preferenceManager.defaultPackages = arrayOf(BuildConfig.APPLICATION_ID + ".") - preferenceManager.sharedPreferencesName = "settings" - preferenceManager.sharedPreferencesMode = Context.MODE_PRIVATE - setPreferencesFromResource(R.xml.settings, null) - - //暗色模式 - val darkPreference = findPreference("drop_dark") as ListPreference - if (darkPreference.value == null) { - darkPreference.setValueIndex(0) - } - darkPreference.onPreferenceChangeListener = this - //多语言 - val langPreference = findPreference("drop_lang") as ListPreference - if (langPreference.value == null) { - langPreference.setValueIndex(0) - } - langPreference.onPreferenceChangeListener = this - } - - override fun onCreateItemDecoration(): DividerDecoration { - return CategoryDivideDividerDecoration() - //return new DefaultDividerDecoration(); - } - - override fun onPause() { - super.onPause() - preferenceScreen.sharedPreferences - .unregisterOnSharedPreferenceChangeListener(this) - } - - override fun onResume() { - super.onResume() - preferenceScreen.sharedPreferences - .registerOnSharedPreferenceChangeListener(this) - } - - override fun onSharedPreferenceChanged( - sharedPreferences: SharedPreferences, - key: String - ) { - //logd("onSharedPreferenceChanged $key") - val sp = activity!!.getSharedPreferences("settings", Context.MODE_PRIVATE) - when (key) { - "drop_dark" -> setDark(sp) - "drop_lang" -> setLang() - } - } - - override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { -// logd( -// getString( -// R.string.on_preference_change_toast_message, -// preference.key, -// newValue.toString() -// ) -// ) - return true - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/jakting/shareclean/fragment/MiscFragment.kt b/app/src/main/java/com/jakting/shareclean/fragment/MiscFragment.kt new file mode 100644 index 00000000..ed99207c --- /dev/null +++ b/app/src/main/java/com/jakting/shareclean/fragment/MiscFragment.kt @@ -0,0 +1,20 @@ +package com.jakting.shareclean.fragment + +import android.content.SharedPreferences +import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import com.jakting.shareclean.R +import com.jakting.shareclean.utils.setDirectShare + +class MiscFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.preference_misc, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + when(key){ + "switch_disable_direct_share" -> setDirectShare(sharedPreferences, context) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/jakting/shareclean/fragment/SettingFragment.kt b/app/src/main/java/com/jakting/shareclean/fragment/SettingFragment.kt new file mode 100644 index 00000000..6331fab5 --- /dev/null +++ b/app/src/main/java/com/jakting/shareclean/fragment/SettingFragment.kt @@ -0,0 +1,22 @@ +package com.jakting.shareclean.fragment + +import android.content.SharedPreferences +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import com.jakting.shareclean.R +import com.jakting.shareclean.utils.setDark +import com.jakting.shareclean.utils.setLang + +class SettingFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.preference_setting, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + when (key) { + "drop_dark" -> setDark(sharedPreferences) + "drop_lang" -> setLang() + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_misc.xml b/app/src/main/res/layout/activity_preference.xml similarity index 95% rename from app/src/main/res/layout/activity_misc.xml rename to app/src/main/res/layout/activity_preference.xml index be90ff35..ea8fb0f3 100644 --- a/app/src/main/res/layout/activity_misc.xml +++ b/app/src/main/res/layout/activity_preference.xml @@ -15,7 +15,7 @@ app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml deleted file mode 100644 index 2ad4d66d..00000000 --- a/app/src/main/res/layout/activity_settings.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/misc.xml b/app/src/main/res/xml/misc.xml deleted file mode 100644 index ffa374b9..00000000 --- a/app/src/main/res/xml/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/preference_misc.xml b/app/src/main/res/xml/preference_misc.xml new file mode 100644 index 00000000..867aa6a1 --- /dev/null +++ b/app/src/main/res/xml/preference_misc.xml @@ -0,0 +1,13 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/preference_setting.xml b/app/src/main/res/xml/preference_setting.xml new file mode 100644 index 00000000..d734f43a --- /dev/null +++ b/app/src/main/res/xml/preference_setting.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml deleted file mode 100644 index f95b61a2..00000000 --- a/app/src/main/res/xml/settings.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file