From 5aceba64743f0f60a4c4aab8a5ac5356c79be4f7 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 4 Sep 2024 16:59:36 +0200 Subject: [PATCH 01/11] Start SubscriberService as background service --- .../java/io/heckel/ntfy/service/SubscriberService.kt | 11 ----------- .../heckel/ntfy/service/SubscriberServiceManager.kt | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 192cfc9..7fd6f93 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -88,17 +88,6 @@ class SubscriberService : Service() { Log.init(this) // Init logs in all entry points Log.d(TAG, "Subscriber service has been created") - - val title = getString(R.string.channel_subscriber_notification_title) - val text = if (BuildConfig.FIREBASE_AVAILABLE) { - getString(R.string.channel_subscriber_notification_instant_text) - } else { - getString(R.string.channel_subscriber_notification_noinstant_text) - } - notificationManager = createNotificationChannel() - serviceNotification = createNotification(title, text) - - startForeground(NOTIFICATION_SERVICE_ID, serviceNotification) } override fun onDestroy() { diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt index ed4dfda..f7573f2 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt @@ -55,7 +55,7 @@ class SubscriberServiceManager(private val context: Context) { Log.d(TAG, "ServiceStartWorker: Starting foreground service with action $action (work ID: ${id})") Intent(context, SubscriberService::class.java).also { it.action = action.name - ContextCompat.startForegroundService(context, it) + context.startService(it) } } return Result.success() From 95ab609d94bba1ab532d8bd525120aaa3639b0cb Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 4 Sep 2024 16:59:53 +0200 Subject: [PATCH 02/11] Make the app persistent so that it does not get killed --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0950b40..bb87844 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,7 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" + android:persistent="true" android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/AppTheme" From a4eb268aa0cc50fc4eb4e5a11520d3b9526789d8 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 4 Sep 2024 17:00:31 +0200 Subject: [PATCH 03/11] Exclude app from Android recents app view --- app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bb87844..e13cf37 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,7 +36,8 @@ + android:excludeFromRecents="true" + android:exported="true"> From 160c4cfd88653b92b0af6f34a3d26132de275663 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 4 Sep 2024 17:01:04 +0200 Subject: [PATCH 04/11] Don't show app on the launcher --- app/src/main/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e13cf37..5cccf5c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,7 +40,6 @@ android:exported="true"> - From fe86329af5da82048d94ef173cfc8fff76ed666a Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Wed, 11 Sep 2024 13:47:27 +0200 Subject: [PATCH 05/11] Add Preferences to enable Ntfy in the Settings app --- app/build.gradle | 6 ++++ app/src/main/AndroidManifest.xml | 30 ++++++++++++++++++- .../heckel/ntfy/service/SubscriberService.kt | 6 ++-- .../ntfy/service/SubscriberServiceManager.kt | 13 +++++--- .../io/heckel/ntfy/ui/MainSettingsActivity.kt | 24 +++++++++++++++ .../io/heckel/ntfy/ui/PreferencesFragment.kt | 29 ++++++++++++++++++ app/src/main/res/drawable/ic_notification.xml | 14 ++++----- .../res/layout/main_settings_activity.xml | 11 +++++++ app/src/main/res/values/strings.xml | 5 ++++ app/src/main/res/xml/settings_preferences.xml | 10 +++++++ build.gradle | 1 + 11 files changed, 135 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt create mode 100644 app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt create mode 100644 app/src/main/res/layout/main_settings_activity.xml create mode 100644 app/src/main/res/xml/settings_preferences.xml diff --git a/app/build.gradle b/app/build.gradle index 90dc1ed..a9d448f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,6 +27,10 @@ android { } } + buildFeatures { + viewBinding = true + } + buildTypes { release { minifyEnabled true @@ -128,4 +132,6 @@ dependencies { // Image viewer implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1' + + implementation 'foundation.e:elib:0.0.1-alpha11' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5cccf5c..348682f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools" + package="io.heckel.ntfy"> @@ -176,5 +177,32 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"/> + + + + + + + + + + diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 7fd6f93..4268e85 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -10,6 +10,7 @@ import android.os.PowerManager import android.os.SystemClock import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat +import androidx.preference.PreferenceManager import io.heckel.ntfy.BuildConfig import io.heckel.ntfy.R import io.heckel.ntfy.app.Application @@ -93,7 +94,9 @@ class SubscriberService : Service() { override fun onDestroy() { Log.d(TAG, "Subscriber service has been destroyed") stopService() - sendBroadcast(Intent(this, AutoRestartReceiver::class.java)) // Restart it if necessary! + if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("isEnabled", false)) { + sendBroadcast(Intent(this, AutoRestartReceiver::class.java)) + } super.onDestroy() } @@ -127,7 +130,6 @@ class SubscriberService : Service() { } } wakeLock = null - stopForeground(true) stopSelf() } catch (e: Exception) { Log.d(TAG, "Service stopped without being started: ${e.message}") diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt index f7573f2..8301363 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt @@ -2,7 +2,7 @@ package io.heckel.ntfy.service import android.content.Context import android.content.Intent -import androidx.core.content.ContextCompat +import androidx.preference.PreferenceManager import androidx.work.* import io.heckel.ntfy.app.Application import io.heckel.ntfy.util.Log @@ -43,11 +43,16 @@ class SubscriberServiceManager(private val context: Context) { Log.d(TAG, "ServiceStartWorker: Failed, no application found (work ID: ${id})") return Result.failure() } + withContext(Dispatchers.IO) { val app = context.applicationContext as Application - val subscriptionIdsWithInstantStatus = app.repository.getSubscriptionIdsWithInstantStatus() - val instantSubscriptions = subscriptionIdsWithInstantStatus.toList().filter { (_, instant) -> instant }.size - val action = if (instantSubscriptions > 0) SubscriberService.Action.START else SubscriberService.Action.STOP + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(app) + val action = if (sharedPreferences.getBoolean("isEnabled", false)) { + SubscriberService.Action.START + } else { + SubscriberService.Action.STOP + } + val serviceState = SubscriberService.readServiceState(context) if (serviceState == SubscriberService.ServiceState.STOPPED && action == SubscriberService.Action.STOP) { return@withContext Result.success() diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt new file mode 100644 index 0000000..6675363 --- /dev/null +++ b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt @@ -0,0 +1,24 @@ +package io.heckel.ntfy.ui + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import io.heckel.ntfy.R +import io.heckel.ntfy.databinding.MainSettingsActivityBinding + + +class MainSettingsActivity: AppCompatActivity() { + + private lateinit var mBinding: MainSettingsActivityBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + mBinding = MainSettingsActivityBinding.inflate(layoutInflater) + setContentView(mBinding.root) + + supportFragmentManager + .beginTransaction() + .replace(R.id.fragment_container, PreferencesFragment()) + .commit() + } +} \ No newline at end of file diff --git a/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt new file mode 100644 index 0000000..fac1ee1 --- /dev/null +++ b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt @@ -0,0 +1,29 @@ +package io.heckel.ntfy.ui + +import android.content.Intent +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreferenceCompat +import io.heckel.ntfy.R +import io.heckel.ntfy.service.SubscriberService + +class PreferencesFragment : PreferenceFragmentCompat() { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.settings_preferences, rootKey) + val preference: SwitchPreferenceCompat? = findPreference("isEnabled") + + preference?.setOnPreferenceChangeListener { _, newValue -> + val isChecked = newValue as Boolean + val intent = Intent(context, SubscriberService::class.java) + intent.action = if (isChecked) { + SubscriberService.Action.START.name + } else { + SubscriberService.Action.STOP.name + } + + requireContext().startService(intent) + true + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_notification.xml b/app/src/main/res/drawable/ic_notification.xml index d02140a..900100b 100644 --- a/app/src/main/res/drawable/ic_notification.xml +++ b/app/src/main/res/drawable/ic_notification.xml @@ -1,31 +1,31 @@ diff --git a/app/src/main/res/layout/main_settings_activity.xml b/app/src/main/res/layout/main_settings_activity.xml new file mode 100644 index 0000000..4d24822 --- /dev/null +++ b/app/src/main/res/layout/main_settings_activity.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c775990..81f918a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -391,4 +391,9 @@ Cancel Delete user Save + + + UnifiedPush + Enable UnifiedPush distributor + This will allow applications to receive UnifiedPush notifications diff --git a/app/src/main/res/xml/settings_preferences.xml b/app/src/main/res/xml/settings_preferences.xml new file mode 100644 index 0000000..55da1ee --- /dev/null +++ b/app/src/main/res/xml/settings_preferences.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index fd50800..8659258 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ allprojects { repositories { google() mavenCentral() + maven { url 'https://gitlab.e.foundation/api/v4/groups/9/-/packages/maven'} maven { url "https://jitpack.io" } // For StfalconImageViewer } } From 4f97fee55cb5fb12d7f737a71932d84607c684f0 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 19 Sep 2024 10:55:15 +0200 Subject: [PATCH 06/11] Adjust styles --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 2 +- app/src/main/res/values/styles.xml | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a9d448f..f229618 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { defaultConfig { applicationId "io.heckel.ntfy" - minSdkVersion 21 + minSdkVersion 23 targetSdkVersion 33 versionCode 33 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 348682f..1f9b952 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -180,7 +180,7 @@ rounded 5dp + + + From 35711e7c1b27901b1118aa6b86af76b0f147f48d Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 19 Sep 2024 15:21:33 +0200 Subject: [PATCH 07/11] Implement collapsing toolbar --- app/src/main/AndroidManifest.xml | 7 +-- .../io/heckel/ntfy/ui/MainSettingsActivity.kt | 4 ++ .../io/heckel/ntfy/ui/PreferencesFragment.kt | 6 +++ .../res/layout/main_settings_activity.xml | 46 +++++++++++++++++-- app/src/main/res/xml/settings_preferences.xml | 1 + 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1f9b952..3fbe559 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -181,18 +181,13 @@ + android:process=":ui"/> diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt index 6675363..dd7f6e7 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt @@ -16,6 +16,10 @@ class MainSettingsActivity: AppCompatActivity() { mBinding = MainSettingsActivityBinding.inflate(layoutInflater) setContentView(mBinding.root) + mBinding.toolbar.setNavigationOnClickListener { + onBackPressed() + } + supportFragmentManager .beginTransaction() .replace(R.id.fragment_container, PreferencesFragment()) diff --git a/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt index fac1ee1..d5f0a5f 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt @@ -1,11 +1,17 @@ package io.heckel.ntfy.ui +import android.content.Context import android.content.Intent import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem +import android.widget.Toolbar import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreferenceCompat import io.heckel.ntfy.R import io.heckel.ntfy.service.SubscriberService +import io.heckel.ntfy.util.Log class PreferencesFragment : PreferenceFragmentCompat() { diff --git a/app/src/main/res/layout/main_settings_activity.xml b/app/src/main/res/layout/main_settings_activity.xml index 4d24822..0673195 100644 --- a/app/src/main/res/layout/main_settings_activity.xml +++ b/app/src/main/res/layout/main_settings_activity.xml @@ -1,11 +1,49 @@ - - + android:layout_height="wrap_content" + android:fitsSystemWindows="true"> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/settings_preferences.xml b/app/src/main/res/xml/settings_preferences.xml index 55da1ee..489df1f 100644 --- a/app/src/main/res/xml/settings_preferences.xml +++ b/app/src/main/res/xml/settings_preferences.xml @@ -2,6 +2,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> Date: Thu, 19 Sep 2024 16:05:45 +0200 Subject: [PATCH 08/11] Add translations --- app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-es/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a9c38b9..3b0739f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -343,4 +343,6 @@ ntfy arbeitet nicht als UnifiedPush-Distributor UnifiedPush aktivieren ntfy arbeitet als UnifiedPush-Distributor + UnifiedPush-Distributor aktivieren + Es ermöglicht Drittanbieteranwendungen, UnifiedPush-Benachrichtigungen zu empfangen \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 0bda4a7..a08c19e 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -343,4 +343,6 @@ Activar UnifiedPush ntfy actuará como distribuidor UnifiedPush ntfy no actuará como distribuidor UnifiedPush + Habilitar el distribuidor de UnifiedPush + Permite a las aplicaciones de terceros recibir notificaciones de UnifiedPush \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 348eecc..0fa51ab 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -343,4 +343,6 @@ ntfy agira comme un distributeur UnifiedPush ntfy n\'agira pas comme un distributeur UnifiedPush Activer le \"UnifiedPush\" + Activer le distributeur UnifiedPush + Cela permet aux applications tierces de recevoir des notifications UnifiedPush \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 703806f..453967a 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -330,4 +330,6 @@ Default Dona 💸 Le app non possono più essere installate: devono essere scaricate via browser. Vedi l\'issue #531 per dettagli. + Abilita il distributore UnifiedPush + Consente alle applicazioni di terze parti di ricevere notifiche UnifiedPush \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 81f918a..2cdbb03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -395,5 +395,5 @@ UnifiedPush Enable UnifiedPush distributor - This will allow applications to receive UnifiedPush notifications + It allows 3rd party applications to receive UnifiedPush notifications From 5684aba36d78ff5ae9d07d78253f6cf2962c8731 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 20 Sep 2024 09:09:30 +0200 Subject: [PATCH 09/11] Implement NavigationBar theme --- .../io/heckel/ntfy/ui/MainSettingsActivity.kt | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt index dd7f6e7..07e9767 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt @@ -1,25 +1,60 @@ package io.heckel.ntfy.ui +import android.content.res.Configuration +import android.os.Build import android.os.Bundle +import android.view.WindowInsetsController +import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import io.heckel.ntfy.R import io.heckel.ntfy.databinding.MainSettingsActivityBinding - -class MainSettingsActivity: AppCompatActivity() { +class MainSettingsActivity : AppCompatActivity() { private lateinit var mBinding: MainSettingsActivityBinding + @RequiresApi(Build.VERSION_CODES.R) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mBinding = MainSettingsActivityBinding.inflate(layoutInflater) setContentView(mBinding.root) - mBinding.toolbar.setNavigationOnClickListener { - onBackPressed() - } + setupToolbar() + setSystemBarsAppearance() + showPreferencesFragment() + } + private fun setupToolbar() { + mBinding.toolbar.setNavigationOnClickListener { + onBackPressedDispatcher.onBackPressed() + } + } + + @RequiresApi(Build.VERSION_CODES.R) + private fun setSystemBarsAppearance() { + val insetsController = window.insetsController ?: return + + val isLightMode = isSystemInLightMode() + if (isLightMode) { + insetsController.setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } else { + insetsController.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } + } + + private fun isSystemInLightMode(): Boolean { + val nightModeFlags = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return nightModeFlags != Configuration.UI_MODE_NIGHT_YES + } + + private fun showPreferencesFragment() { supportFragmentManager .beginTransaction() .replace(R.id.fragment_container, PreferencesFragment()) From 78bf83acf46976c04759bee4e18b3c2eedeca8d6 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 20 Sep 2024 13:42:47 +0200 Subject: [PATCH 10/11] Extract isEnabled key as resource --- app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt | 4 +++- .../java/io/heckel/ntfy/service/SubscriberServiceManager.kt | 4 +++- app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt | 4 +++- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/settings_preferences.xml | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 4268e85..a70acf0 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -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() } diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt index 8301363..18ed4f9 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberServiceManager.kt @@ -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 diff --git a/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt index d5f0a5f..2bc5e30 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/PreferencesFragment.kt @@ -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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2cdbb03..1d08618 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -393,6 +393,7 @@ Save + isEnabled UnifiedPush Enable UnifiedPush distributor It allows 3rd party applications to receive UnifiedPush notifications diff --git a/app/src/main/res/xml/settings_preferences.xml b/app/src/main/res/xml/settings_preferences.xml index 489df1f..6b02c9c 100644 --- a/app/src/main/res/xml/settings_preferences.xml +++ b/app/src/main/res/xml/settings_preferences.xml @@ -3,7 +3,7 @@ From 3b1581a2ba5a9bdf8c416ccc8875c739aa2d6d84 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 20 Sep 2024 14:57:10 +0200 Subject: [PATCH 11/11] Set status bar theme programatically --- .../main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt | 8 ++++++++ app/src/main/res/values/styles.xml | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt index 07e9767..1aabb1a 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt @@ -37,11 +37,19 @@ class MainSettingsActivity : AppCompatActivity() { val isLightMode = isSystemInLightMode() if (isLightMode) { + insetsController.setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS + ) insetsController.setSystemBarsAppearance( WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS ) } else { + insetsController.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS + ) insetsController.setSystemBarsAppearance( 0, WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3238e49..e724494 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -49,7 +49,6 @@ @color/e_divider_color @android:color/transparent @color/e_background - ?attr/isLightTheme @style/ETheme.Switch