Skip to content

Commit

Permalink
update: use AndroidX Preference
Browse files Browse the repository at this point in the history
  • Loading branch information
TigerBeanst committed Aug 4, 2021
1 parent 6acca6f commit 58dfab6
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 274 deletions.
7 changes: 1 addition & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@
</provider>

<activity
android:name=".SettingsActivity"
android:name=".PreferenceActivity"
android:label="@string/setting_title"
android:screenOrientation="portrait"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MiscActivity"
android:label="@string/misc_title"
android:screenOrientation="portrait"
android:parentActivityName=".MainActivity" />
<activity
android:name=".AboutActivity"
android:screenOrientation="portrait"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jakting/shareclean/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class BaseActivity : LocalizationActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appContext = this
settingSharedPreferences = getSharedPreferences("settings", Context.MODE_PRIVATE)
settingSharedPreferences = getSharedPreferences("com.jakting.shareclean_preferences", Context.MODE_PRIVATE)
intentListSharedPreferences = getSharedPreferences("intent_list", Context.MODE_PRIVATE)
intentListSharedPreferencesEditor = intentListSharedPreferences.edit()
setLang()
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/jakting/shareclean/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ class MainActivity : BaseActivity(), View.OnClickListener {
clickBackupRestore()
}
R.id.misc_menu -> {
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 -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jakting/shareclean/ManageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
84 changes: 0 additions & 84 deletions app/src/main/java/com/jakting/shareclean/MiscActivity.kt

This file was deleted.

33 changes: 33 additions & 0 deletions app/src/main/java/com/jakting/shareclean/PreferenceActivity.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}


}
}
99 changes: 0 additions & 99 deletions app/src/main/java/com/jakting/shareclean/SettingsActivity.kt

This file was deleted.

20 changes: 20 additions & 0 deletions app/src/main/java/com/jakting/shareclean/fragment/MiscFragment.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<FrameLayout
android:id="@+id/misc"
android:id="@+id/preference"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down
22 changes: 0 additions & 22 deletions app/src/main/res/layout/activity_settings.xml

This file was deleted.

13 changes: 0 additions & 13 deletions app/src/main/res/xml/misc.xml

This file was deleted.

13 changes: 13 additions & 0 deletions app/src/main/res/xml/preference_misc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/misc_disable">
<SwitchPreference
app:defaultValue="tr"
app:key="switch_disable_direct_share"
app:summaryOff="@string/misc_disable_direct_msgNo"
app:summaryOn="@string/misc_disable_direct_msg"
app:title="@string/misc_disable_direct" />

</PreferenceCategory>

</PreferenceScreen>
Loading

0 comments on commit 58dfab6

Please sign in to comment.