Loading app/build.gradle +1 −5 Original line number Diff line number Diff line Loading @@ -102,11 +102,7 @@ allprojects { dependencies { implementation 'org.unifiedpush.android:connector:3.0.4' playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') { exclude group: 'com.google.firebase', module: 'firebase-core' exclude group: 'com.google.firebase', module: 'firebase-analytics' exclude group: 'com.google.firebase', module: 'firebase-measurement-connector' } playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') implementation 'androidx.appcompat:appcompat:1.7.0' Loading app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java +17 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,23 @@ import retrofit2.converter.gson.GsonConverterFactory; public class PushNotifications { public static void unregisterPushNotifications(Context context, String slug) { new Thread(() -> { String[] slugArray = slug.split("@"); BaseAccount accountDb = null; try { accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]); } catch (DBException e) { e.printStackTrace(); } if (accountDb == null) { return; } MastodonNotificationsService mastodonNotificationsService = init(context, accountDb.instance); mastodonNotificationsService.deletePushsubscription(accountDb.token); }); } public static void registerPushNotifications(Context context, PushEndpoint pushEndpoint, String slug) { Loading app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java +13 −20 Original line number Diff line number Diff line package app.fedilab.android.mastodon.services; import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.content.SharedPreferences; import android.content.Context; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import org.unifiedpush.android.connector.FailedReason; import org.unifiedpush.android.connector.PushService; import org.unifiedpush.android.connector.data.PushEndpoint; import org.unifiedpush.android.connector.data.PushMessage; import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.NotificationsHelper; import app.fedilab.android.mastodon.helper.PushNotifications; Loading Loading @@ -49,17 +41,11 @@ public class PushServiceImpl extends PushService { @Override public void onNewEndpoint(@NonNull PushEndpoint pushEndpoint, @NonNull String slug) { if (getApplicationContext() != null) { Context context = getApplicationContext(); if (context != null) { synchronized (this) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String storedEnpoint = sharedpreferences.getString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, null); if (storedEnpoint == null || !storedEnpoint.equals(pushEndpoint.getUrl())) { PushNotifications .registerPushNotifications(getApplicationContext(), pushEndpoint, slug); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, pushEndpoint.getUrl()); editor.commit(); } .registerPushNotifications(context, pushEndpoint, slug); } } } Loading @@ -70,6 +56,13 @@ public class PushServiceImpl extends PushService { } @Override public void onUnregistered(@NonNull String s) { public void onUnregistered(@NonNull String slug) { Context context = getApplicationContext(); if (context != null) { synchronized (this) { PushNotifications .unregisterPushNotifications(context, slug); } } } } app/src/main/res/values/strings.xml +0 −1 Original line number Diff line number Diff line Loading @@ -1169,7 +1169,6 @@ <string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string> <string name="SET_TRANSLATOR_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string> <string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string> <string name="SET_STORED_ENDPOINT" translatable="false">SET_STORED_ENDPOINT</string> <string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string> <string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string> Loading Loading
app/build.gradle +1 −5 Original line number Diff line number Diff line Loading @@ -102,11 +102,7 @@ allprojects { dependencies { implementation 'org.unifiedpush.android:connector:3.0.4' playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') { exclude group: 'com.google.firebase', module: 'firebase-core' exclude group: 'com.google.firebase', module: 'firebase-analytics' exclude group: 'com.google.firebase', module: 'firebase-measurement-connector' } playstoreImplementation('org.unifiedpush.android:embedded-fcm-distributor:3.0.0') implementation 'androidx.appcompat:appcompat:1.7.0' Loading
app/src/main/java/app/fedilab/android/mastodon/helper/PushNotifications.java +17 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,23 @@ import retrofit2.converter.gson.GsonConverterFactory; public class PushNotifications { public static void unregisterPushNotifications(Context context, String slug) { new Thread(() -> { String[] slugArray = slug.split("@"); BaseAccount accountDb = null; try { accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]); } catch (DBException e) { e.printStackTrace(); } if (accountDb == null) { return; } MastodonNotificationsService mastodonNotificationsService = init(context, accountDb.instance); mastodonNotificationsService.deletePushsubscription(accountDb.token); }); } public static void registerPushNotifications(Context context, PushEndpoint pushEndpoint, String slug) { Loading
app/src/main/java/app/fedilab/android/mastodon/services/PushServiceImpl.java +13 −20 Original line number Diff line number Diff line package app.fedilab.android.mastodon.services; import static app.fedilab.android.mastodon.helper.Helper.TAG; import android.content.SharedPreferences; import android.content.Context; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import org.unifiedpush.android.connector.FailedReason; import org.unifiedpush.android.connector.PushService; import org.unifiedpush.android.connector.data.PushEndpoint; import org.unifiedpush.android.connector.data.PushMessage; import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.NotificationsHelper; import app.fedilab.android.mastodon.helper.PushNotifications; Loading Loading @@ -49,17 +41,11 @@ public class PushServiceImpl extends PushService { @Override public void onNewEndpoint(@NonNull PushEndpoint pushEndpoint, @NonNull String slug) { if (getApplicationContext() != null) { Context context = getApplicationContext(); if (context != null) { synchronized (this) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String storedEnpoint = sharedpreferences.getString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, null); if (storedEnpoint == null || !storedEnpoint.equals(pushEndpoint.getUrl())) { PushNotifications .registerPushNotifications(getApplicationContext(), pushEndpoint, slug); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(getApplicationContext().getString(R.string.SET_STORED_ENDPOINT) + slug, pushEndpoint.getUrl()); editor.commit(); } .registerPushNotifications(context, pushEndpoint, slug); } } } Loading @@ -70,6 +56,13 @@ public class PushServiceImpl extends PushService { } @Override public void onUnregistered(@NonNull String s) { public void onUnregistered(@NonNull String slug) { Context context = getApplicationContext(); if (context != null) { synchronized (this) { PushNotifications .unregisterPushNotifications(context, slug); } } } }
app/src/main/res/values/strings.xml +0 −1 Original line number Diff line number Diff line Loading @@ -1169,7 +1169,6 @@ <string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string> <string name="SET_TRANSLATOR_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string> <string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string> <string name="SET_STORED_ENDPOINT" translatable="false">SET_STORED_ENDPOINT</string> <string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string> <string name="SET_TRANSLATOR_API_KEY" translatable="false">SET_TRANSLATOR_API_KEY</string> Loading