2020-01-08 20:20:20 +01:00
|
|
|
package info.nightscout.androidaps.activities
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Bundle
|
2020-11-24 01:50:09 +01:00
|
|
|
import android.text.Editable
|
|
|
|
import android.text.TextWatcher
|
2020-01-08 20:20:20 +01:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
|
|
import androidx.preference.PreferenceScreen
|
|
|
|
import info.nightscout.androidaps.R
|
2020-05-23 15:39:05 +02:00
|
|
|
import info.nightscout.androidaps.utils.locale.LocaleHelper
|
2020-11-24 01:50:09 +01:00
|
|
|
import kotlinx.android.synthetic.main.activity_preferences.*
|
2020-01-08 20:20:20 +01:00
|
|
|
|
|
|
|
class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
|
|
|
|
|
|
|
|
var preferenceId = 0
|
2020-11-24 01:50:09 +01:00
|
|
|
var myPreferenceFragment: MyPreferenceFragment? = null
|
|
|
|
|
2020-01-08 20:20:20 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2020-11-24 01:50:09 +01:00
|
|
|
setContentView(R.layout.activity_preferences)
|
|
|
|
|
|
|
|
pref_filter.addTextChangedListener(object : TextWatcher {
|
|
|
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
|
|
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
|
|
|
filterPreferences()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun afterTextChanged(s: Editable) {}
|
|
|
|
})
|
|
|
|
|
2020-01-08 20:20:20 +01:00
|
|
|
title = resourceHelper.gs(R.string.nav_preferences)
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
2020-11-24 01:50:09 +01:00
|
|
|
myPreferenceFragment = MyPreferenceFragment()
|
2020-01-08 20:20:20 +01:00
|
|
|
preferenceId = intent.getIntExtra("id", -1)
|
2021-01-20 15:07:01 +01:00
|
|
|
myPreferenceFragment?.arguments = Bundle().also {
|
|
|
|
it.putInt("id", preferenceId)
|
|
|
|
it.putString("filter", pref_filter.text.toString())
|
|
|
|
}
|
|
|
|
if (savedInstanceState == null)
|
|
|
|
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, myPreferenceFragment!!).commit()
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPreferenceStartScreen(caller: PreferenceFragmentCompat, pref: PreferenceScreen): Boolean {
|
|
|
|
val fragment = MyPreferenceFragment()
|
2021-01-20 15:07:01 +01:00
|
|
|
fragment.arguments = Bundle().also {
|
|
|
|
it.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.key)
|
|
|
|
it.putInt("id", preferenceId)
|
|
|
|
}
|
|
|
|
supportFragmentManager.beginTransaction().replace(R.id.frame_layout, fragment, pref.key).addToBackStack(pref.key).commit()
|
2020-01-08 20:20:20 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun attachBaseContext(newBase: Context) {
|
|
|
|
super.attachBaseContext(LocaleHelper.wrap(newBase))
|
|
|
|
}
|
2020-11-24 01:50:09 +01:00
|
|
|
|
|
|
|
private fun filterPreferences() {
|
|
|
|
myPreferenceFragment?.setFilter(pref_filter.text.toString())
|
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|