Skip to content

Commit

Permalink
Remove deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Dec 27, 2020
1 parent 0b338e0 commit b1dfb5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.github.shadowsocks:plugin:1.3.4'
implementation "androidx.preference:preference-ktx:1.1.1"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.github.shadowsocks.plugin.PluginOptions
class ConfigActivity : ConfigurationActivity(), Toolbar.OnMenuItemClickListener {

fun getChild(): ConfigFragment {
return getFragmentManager().findFragmentById(R.id.content) as ConfigFragment
return supportFragmentManager.findFragmentById(R.id.content) as ConfigFragment
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.shadowsocks.plugin.ck_client

import android.os.Bundle
import android.preference.EditTextPreference
import android.preference.ListPreference
import android.preference.Preference
import android.preference.PreferenceFragment
import android.view.View
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.github.shadowsocks.plugin.PluginContract
import com.github.shadowsocks.plugin.PluginOptions


class ConfigFragment : PreferenceFragment() {
class ConfigFragment : PreferenceFragmentCompat() {
var _options = PluginOptions()

fun onInitializePluginOptions(options: PluginOptions) {
Expand All @@ -22,20 +21,19 @@ class ConfigFragment : PreferenceFragment() {
for (element in ary) {
val key = element.first
val defaultValue = element.second
val pref = findPreference(key)
val current: String? = options.get(key)
val value = current ?: defaultValue
val pref: Preference? = findPreference(key)
val value: String? = options.get(key)?:defaultValue
when (pref) {
is ListPreference -> {
pref.setValue(value)
pref.value = value
}
is EditTextPreference -> {
pref.setText(value)
pref.text = value
}
}
// we want all preferences to be put into the options, not only the changed ones
options.put(key, value)
pref.setOnPreferenceChangeListener(
pref!!.setOnPreferenceChangeListener(
fun(_: Preference, value: Any): Boolean {
options.put(key, value.toString())
return true
Expand All @@ -49,8 +47,7 @@ class ConfigFragment : PreferenceFragment() {
outState.putString(PluginContract.EXTRA_OPTIONS, _options.toString())
}

override fun onViewCreated(vidw: View, savedInstanceState: Bundle?) {
super.onViewCreated(vidw, savedInstanceState)
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
if (savedInstanceState != null) {
_options = PluginOptions(savedInstanceState.getString(PluginContract.EXTRA_OPTIONS))
onInitializePluginOptions(_options)
Expand Down

0 comments on commit b1dfb5b

Please sign in to comment.