Extract isEnabled key as resource
This commit is contained in:
parent
5684aba36d
commit
78bf83acf4
5 changed files with 11 additions and 4 deletions
|
@ -94,9 +94,11 @@ class SubscriberService : Service() {
|
|||
override fun onDestroy() {
|
||||
Log.d(TAG, "Subscriber service has been destroyed")
|
||||
stopService()
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("isEnabled", false)) {
|
||||
val preferenceKey = getString(R.string.eos_preference_key_is_enabled)
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(preferenceKey, false)) {
|
||||
sendBroadcast(Intent(this, AutoRestartReceiver::class.java))
|
||||
}
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.preference.PreferenceManager
|
|||
import androidx.work.*
|
||||
import io.heckel.ntfy.app.Application
|
||||
import io.heckel.ntfy.util.Log
|
||||
import io.heckel.ntfy.R
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
@ -47,7 +48,8 @@ class SubscriberServiceManager(private val context: Context) {
|
|||
withContext(Dispatchers.IO) {
|
||||
val app = context.applicationContext as Application
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(app)
|
||||
val action = if (sharedPreferences.getBoolean("isEnabled", false)) {
|
||||
val preferenceKey = context.getString(R.string.eos_preference_key_is_enabled)
|
||||
val action = if (sharedPreferences.getBoolean(preferenceKey, false)) {
|
||||
SubscriberService.Action.START
|
||||
} else {
|
||||
SubscriberService.Action.STOP
|
||||
|
|
|
@ -17,7 +17,9 @@ class PreferencesFragment : PreferenceFragmentCompat() {
|
|||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.settings_preferences, rootKey)
|
||||
val preference: SwitchPreferenceCompat? = findPreference("isEnabled")
|
||||
|
||||
val preference: SwitchPreferenceCompat? =
|
||||
findPreference(getString(R.string.eos_preference_key_is_enabled))
|
||||
|
||||
preference?.setOnPreferenceChangeListener { _, newValue ->
|
||||
val isChecked = newValue as Boolean
|
||||
|
|
|
@ -393,6 +393,7 @@
|
|||
<string name="user_dialog_button_save">Save</string>
|
||||
|
||||
<!-- /e/OS integration preferences -->
|
||||
<string name="eos_preference_key_is_enabled" translatable="false">isEnabled</string>
|
||||
<string name="eos_settings_title" translatable="false">UnifiedPush</string>
|
||||
<string name="eos_settings_enable_title" translatable="true">Enable UnifiedPush distributor</string>
|
||||
<string name="eos_settings_enable_description" translatable="true">It allows 3rd party applications to receive UnifiedPush notifications</string>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<SwitchPreferenceCompat
|
||||
app:icon="@drawable/ic_notification"
|
||||
app:key="isEnabled"
|
||||
app:key="@string/eos_preference_key_is_enabled"
|
||||
app:defaultValue="false"
|
||||
app:title="@string/eos_settings_enable_title"
|
||||
app:summary="@string/eos_settings_enable_description" />
|
||||
|
|
Loading…
Reference in a new issue