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
|
2021-01-22 14:04:32 +01:00
|
|
|
import info.nightscout.androidaps.databinding.ActivityPreferencesBinding
|
2020-05-23 15:39:05 +02:00
|
|
|
import info.nightscout.androidaps.utils.locale.LocaleHelper
|
2020-01-08 20:20:20 +01:00
|
|
|
|
|
|
|
class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
|
|
|
|
|
2021-01-22 14:04:32 +01:00
|
|
|
private var preferenceId = 0
|
|
|
|
private var myPreferenceFragment: MyPreferenceFragment? = null
|
|
|
|
|
|
|
|
private lateinit var binding: ActivityPreferencesBinding
|
2020-11-24 01:50:09 +01:00
|
|
|
|
2020-01-08 20:20:20 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2021-01-22 14:04:32 +01:00
|
|
|
binding = ActivityPreferencesBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
2020-11-24 01:50:09 +01:00
|
|
|
|
2021-01-22 14:04:32 +01:00
|
|
|
binding.prefFilter.addTextChangedListener(object : TextWatcher {
|
2020-11-24 01:50:09 +01:00
|
|
|
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) {}
|
|
|
|
})
|
|
|
|
|
2021-11-02 09:53:16 +01:00
|
|
|
title = rh.gs(R.string.nav_preferences)
|
2020-01-08 20:20:20 +01:00
|
|
|
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)
|
2021-01-22 14:04:32 +01:00
|
|
|
it.putString("filter", binding.prefFilter.text.toString())
|
2021-01-20 15:07:01 +01:00
|
|
|
}
|
|
|
|
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() {
|
2021-01-22 14:04:32 +01:00
|
|
|
myPreferenceFragment?.setFilter(binding.prefFilter.text.toString())
|
2020-11-24 01:50:09 +01:00
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|