Compare commits

..

5 commits

Author SHA1 Message Date
Jonathan Klee
3fb7e6427f Merge branch '2585-u-change-package-name' into 'main'
Change Ntfy package name

See merge request e/os/ntfy-android!14
2024-10-24 11:26:08 +00:00
Jonathan Klee
afeebcc4d1 Change package name
So that in case the user had ntfy already installed, we don't
override it. Indeed, the Ntfy icon (which is actually a BlissLauncher3 cache)
would appear after the OTA and the user would not be able to remove it
without cleaning BlissLauncher3 cache.
2024-10-24 10:14:11 +02:00
Jonathan Klee
9add68ed1a Change preference wording 2024-10-10 14:42:34 +02:00
Jonathan Klee
18fb197507 Merge branch '0000-u-keep-same-process' into 'main'
Don't execute MainSettingsActivity in a different process

See merge request e/os/ntfy-android!13
2024-09-26 08:55:37 +00:00
Jonathan Klee
7c00376ae1 Don't execute MainSettingsActivity in a different process
so that share preferences work properly
2024-09-26 08:20:17 +02:00
10 changed files with 21 additions and 40 deletions

View file

@ -10,7 +10,7 @@ android {
compileSdkVersion 33 compileSdkVersion 33
defaultConfig { defaultConfig {
applicationId "io.heckel.ntfy" applicationId "foundation.e.ntfy"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 33 targetSdkVersion 33
@ -68,6 +68,7 @@ android {
'-Xjvm-default=all-compatibility' // https://stackoverflow.com/a/71234042/1440785 '-Xjvm-default=all-compatibility' // https://stackoverflow.com/a/71234042/1440785
] ]
} }
namespace "io.heckel.ntfy"
} }
// Disables GoogleServices tasks for F-Droid variant // Disables GoogleServices tasks for F-Droid variant

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
package="io.heckel.ntfy">
<!-- Permissions --> <!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
@ -12,8 +11,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/> <!-- Only required on SDK <= 28 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/> <!-- Only required on SDK <= 28 -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <!-- To reschedule the websocket retry --> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <!-- To reschedule the websocket retry -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- As of Android 13, we need to ask for permission to post notifications --> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- As of Android 13, we need to ask for permission to post notifications -->
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<!-- <!--
Permission REQUEST_INSTALL_PACKAGES (F-Droid only!): Permission REQUEST_INSTALL_PACKAGES (F-Droid only!):
@ -182,14 +179,12 @@
<activity <activity
android:name=".ui.MainSettingsActivity" android:name=".ui.MainSettingsActivity"
android:theme="@style/PreferenceTheme" android:theme="@style/PreferenceTheme"/>
android:process=":ui"/>
<activity-alias <activity-alias
android:name=".ui.SettingsActivityLink" android:name=".ui.SettingsActivityLink"
android:exported="true" android:exported="true"
android:label="@string/eos_settings_title" android:label="@string/eos_settings_title"
android:process=":ui"
android:targetActivity=".ui.MainSettingsActivity"> android:targetActivity=".ui.MainSettingsActivity">
<intent-filter> <intent-filter>
<action android:name="com.android.settings.action.EXTRA_SETTINGS" /> <action android:name="com.android.settings.action.EXTRA_SETTINGS" />

View file

@ -8,7 +8,6 @@ import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import android.os.SystemClock import android.os.SystemClock
import android.provider.Settings
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -95,14 +94,8 @@ class SubscriberService : Service() {
override fun onDestroy() { override fun onDestroy() {
Log.d(TAG, "Subscriber service has been destroyed") Log.d(TAG, "Subscriber service has been destroyed")
stopService() stopService()
val preferenceKey = getString(R.string.eos_preference_key_is_enabled)
val isEnabled = Settings.Global.getInt( if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(preferenceKey, false)) {
applicationContext.contentResolver,
applicationContext.getString(R.string.eos_preference_key_is_enabled),
0
)
if (isEnabled == 1) {
sendBroadcast(Intent(this, AutoRestartReceiver::class.java)) sendBroadcast(Intent(this, AutoRestartReceiver::class.java))
} }

View file

@ -2,7 +2,6 @@ package io.heckel.ntfy.service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.provider.Settings
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.work.* import androidx.work.*
import io.heckel.ntfy.app.Application import io.heckel.ntfy.app.Application
@ -23,7 +22,6 @@ import kotlinx.coroutines.withContext
class SubscriberServiceManager(private val context: Context) { class SubscriberServiceManager(private val context: Context) {
fun refresh() { fun refresh() {
Log.d(TAG, "Enqueuing work to refresh subscriber service") Log.d(TAG, "Enqueuing work to refresh subscriber service")
val workManager = WorkManager.getInstance(context) val workManager = WorkManager.getInstance(context)
val startServiceRequest = OneTimeWorkRequest.Builder(ServiceStartWorker::class.java).build() val startServiceRequest = OneTimeWorkRequest.Builder(ServiceStartWorker::class.java).build()
workManager.enqueueUniqueWork(WORK_NAME_ONCE, ExistingWorkPolicy.KEEP, startServiceRequest) // Unique avoids races! workManager.enqueueUniqueWork(WORK_NAME_ONCE, ExistingWorkPolicy.KEEP, startServiceRequest) // Unique avoids races!
@ -48,14 +46,10 @@ class SubscriberServiceManager(private val context: Context) {
} }
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val app = context.applicationContext as Application
val isEnabled = Settings.Global.getInt( val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(app)
context.contentResolver, val preferenceKey = context.getString(R.string.eos_preference_key_is_enabled)
context.getString(R.string.eos_preference_key_is_enabled), val action = if (sharedPreferences.getBoolean(preferenceKey, false)) {
0
)
val action = if (isEnabled == 1) {
SubscriberService.Action.START SubscriberService.Action.START
} else { } else {
SubscriberService.Action.STOP SubscriberService.Action.STOP

View file

@ -1,12 +1,17 @@
package io.heckel.ntfy.ui package io.heckel.ntfy.ui
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.provider.Settings import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.widget.Toolbar
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import io.heckel.ntfy.R import io.heckel.ntfy.R
import io.heckel.ntfy.service.SubscriberService import io.heckel.ntfy.service.SubscriberService
import io.heckel.ntfy.util.Log
class PreferencesFragment : PreferenceFragmentCompat() { class PreferencesFragment : PreferenceFragmentCompat() {
@ -18,13 +23,6 @@ class PreferencesFragment : PreferenceFragmentCompat() {
preference?.setOnPreferenceChangeListener { _, newValue -> preference?.setOnPreferenceChangeListener { _, newValue ->
val isChecked = newValue as Boolean val isChecked = newValue as Boolean
Settings.Global.putInt(
requireContext().contentResolver,
requireContext().getString(R.string.eos_preference_key_is_enabled),
if (isChecked) 1 else 0
)
val intent = Intent(context, SubscriberService::class.java) val intent = Intent(context, SubscriberService::class.java)
intent.action = if (isChecked) { intent.action = if (isChecked) {
SubscriberService.Action.START.name SubscriberService.Action.START.name

View file

@ -343,6 +343,6 @@
<string name="settings_advanced_unifiedpush_summary_disabled">ntfy arbeitet nicht als UnifiedPush-Distributor</string> <string name="settings_advanced_unifiedpush_summary_disabled">ntfy arbeitet nicht als UnifiedPush-Distributor</string>
<string name="settings_advanced_unifiedpush_title">UnifiedPush aktivieren</string> <string name="settings_advanced_unifiedpush_title">UnifiedPush aktivieren</string>
<string name="settings_advanced_unifiedpush_summary_enabled">ntfy arbeitet als UnifiedPush-Distributor</string> <string name="settings_advanced_unifiedpush_summary_enabled">ntfy arbeitet als UnifiedPush-Distributor</string>
<string name="eos_settings_enable_title">UnifiedPush-Distributor aktivieren</string> <string name="eos_settings_enable_title">Den Verteiler aktivieren</string>
<string name="eos_settings_enable_description">Es ermöglicht Drittanbieteranwendungen, UnifiedPush-Benachrichtigungen zu empfangen</string> <string name="eos_settings_enable_description">Es ermöglicht Drittanbieteranwendungen, UnifiedPush-Benachrichtigungen zu empfangen</string>
</resources> </resources>

View file

@ -343,6 +343,6 @@
<string name="settings_advanced_unifiedpush_title">Activar UnifiedPush</string> <string name="settings_advanced_unifiedpush_title">Activar UnifiedPush</string>
<string name="settings_advanced_unifiedpush_summary_enabled">ntfy actuará como distribuidor UnifiedPush</string> <string name="settings_advanced_unifiedpush_summary_enabled">ntfy actuará como distribuidor UnifiedPush</string>
<string name="settings_advanced_unifiedpush_summary_disabled">ntfy no actuará como distribuidor UnifiedPush</string> <string name="settings_advanced_unifiedpush_summary_disabled">ntfy no actuará como distribuidor UnifiedPush</string>
<string name="eos_settings_enable_title">Habilitar el distribuidor de UnifiedPush</string> <string name="eos_settings_enable_title">Habilitar el distribuidor</string>
<string name="eos_settings_enable_description">Permite a las aplicaciones de terceros recibir notificaciones de UnifiedPush</string> <string name="eos_settings_enable_description">Permite a las aplicaciones de terceros recibir notificaciones de UnifiedPush</string>
</resources> </resources>

View file

@ -343,6 +343,6 @@
<string name="settings_advanced_unifiedpush_summary_enabled">ntfy agira comme un distributeur UnifiedPush</string> <string name="settings_advanced_unifiedpush_summary_enabled">ntfy agira comme un distributeur UnifiedPush</string>
<string name="settings_advanced_unifiedpush_summary_disabled">ntfy n\'agira pas comme un distributeur UnifiedPush</string> <string name="settings_advanced_unifiedpush_summary_disabled">ntfy n\'agira pas comme un distributeur UnifiedPush</string>
<string name="settings_advanced_unifiedpush_title">Activer le \"UnifiedPush\"</string> <string name="settings_advanced_unifiedpush_title">Activer le \"UnifiedPush\"</string>
<string name="eos_settings_enable_title">Activer le distributeur UnifiedPush</string> <string name="eos_settings_enable_title">Activer le distributeur</string>
<string name="eos_settings_enable_description">Cela permet aux applications tierces de recevoir des notifications UnifiedPush</string> <string name="eos_settings_enable_description">Cela permet aux applications tierces de recevoir des notifications UnifiedPush</string>
</resources> </resources>

View file

@ -330,6 +330,6 @@
<string name="channel_notifications_group_default_name">Default</string> <string name="channel_notifications_group_default_name">Default</string>
<string name="main_menu_donate_title">Dona 💸</string> <string name="main_menu_donate_title">Dona 💸</string>
<string name="detail_item_cannot_open_apk">Le app non possono più essere installate: devono essere scaricate via browser. Vedi l\'issue #531 per dettagli.</string> <string name="detail_item_cannot_open_apk">Le app non possono più essere installate: devono essere scaricate via browser. Vedi l\'issue #531 per dettagli.</string>
<string name="eos_settings_enable_title">Abilita il distributore UnifiedPush</string> <string name="eos_settings_enable_title">Abilitare il distributore</string>
<string name="eos_settings_enable_description">Consente alle applicazioni di terze parti di ricevere notifiche UnifiedPush</string> <string name="eos_settings_enable_description">Consente alle applicazioni di terze parti di ricevere notifiche UnifiedPush</string>
</resources> </resources>

View file

@ -395,6 +395,6 @@
<!-- /e/OS integration preferences --> <!-- /e/OS integration preferences -->
<string name="eos_preference_key_is_enabled" translatable="false">isEnabled</string> <string name="eos_preference_key_is_enabled" translatable="false">isEnabled</string>
<string name="eos_settings_title" translatable="false">UnifiedPush</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_title" translatable="true">Enable the distributor</string>
<string name="eos_settings_enable_description" translatable="true">It allows 3rd party applications to receive UnifiedPush notifications</string> <string name="eos_settings_enable_description" translatable="true">It allows 3rd party applications to receive UnifiedPush notifications</string>
</resources> </resources>