google fcm
This commit is contained in:
parent
03b41c78b3
commit
cebce4bec6
|
@ -1,5 +1,5 @@
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
def flavor
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
buildToolsVersion "29.0.3"
|
buildToolsVersion "29.0.3"
|
||||||
|
@ -42,6 +42,7 @@ android {
|
||||||
buildConfigField "boolean", "DONATIONS", "true"
|
buildConfigField "boolean", "DONATIONS", "true"
|
||||||
buildConfigField "boolean", "lite", "false"
|
buildConfigField "boolean", "lite", "false"
|
||||||
resValue "string", "app_name", "Fedilab"
|
resValue "string", "app_name", "Fedilab"
|
||||||
|
flavor = "fdroid"
|
||||||
}
|
}
|
||||||
lite {
|
lite {
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
|
@ -49,12 +50,14 @@ android {
|
||||||
buildConfigField "boolean", "DONATIONS", "true"
|
buildConfigField "boolean", "DONATIONS", "true"
|
||||||
buildConfigField "boolean", "lite", "true"
|
buildConfigField "boolean", "lite", "true"
|
||||||
resValue "string", "app_name", "Fedilab Lite"
|
resValue "string", "app_name", "Fedilab Lite"
|
||||||
|
flavor = "lite"
|
||||||
}
|
}
|
||||||
playstore {
|
playstore {
|
||||||
applicationId "app.fedilab.android"
|
applicationId "app.fedilab.android"
|
||||||
buildConfigField "boolean", "DONATIONS", "false"
|
buildConfigField "boolean", "DONATIONS", "false"
|
||||||
buildConfigField "boolean", "lite", "false"
|
buildConfigField "boolean", "lite", "false"
|
||||||
resValue "string", "app_name", "Fedilab"
|
resValue "string", "app_name", "Fedilab"
|
||||||
|
flavor = "playstore"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
|
@ -62,6 +65,7 @@ android {
|
||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
playstore {
|
playstore {
|
||||||
|
|
||||||
manifest.srcFile "src/common/AndroidManifest.xml"
|
manifest.srcFile "src/common/AndroidManifest.xml"
|
||||||
assets.srcDirs = ['/src/mains/assets', 'src/common/assets']
|
assets.srcDirs = ['/src/mains/assets', 'src/common/assets']
|
||||||
java.srcDirs = ['src/main/java', 'src/playstore/java','src/common/java']
|
java.srcDirs = ['src/main/java', 'src/playstore/java','src/common/java']
|
||||||
|
@ -71,13 +75,13 @@ android {
|
||||||
fdroid {
|
fdroid {
|
||||||
manifest.srcFile "src/common/AndroidManifest.xml"
|
manifest.srcFile "src/common/AndroidManifest.xml"
|
||||||
assets.srcDirs = ['/src/mains/assets', 'src/common/assets']
|
assets.srcDirs = ['/src/mains/assets', 'src/common/assets']
|
||||||
java.srcDirs = ['src/main/java', 'src/fdroid/java','src/common/java']
|
java.srcDirs = ['src/main/java', 'src/fdroid/java','src/common/java', 'src/fdroidcommon/java']
|
||||||
res.srcDirs = ['src/main/res', 'src/fdroid/res','src/common/res']
|
res.srcDirs = ['src/main/res', 'src/fdroid/res','src/common/res']
|
||||||
}
|
}
|
||||||
lite {
|
lite {
|
||||||
manifest.srcFile "src/lite/AndroidManifest.xml"
|
manifest.srcFile "src/lite/AndroidManifest.xml"
|
||||||
assets.srcDirs = ['/src/mains/assets']
|
assets.srcDirs = ['/src/mains/assets']
|
||||||
java.srcDirs = ['src/main/java', 'src/lite/java']
|
java.srcDirs = ['src/main/java', 'src/lite/java', 'src/fdroidcommon/java']
|
||||||
res.srcDirs = ['src/main/res', 'src/lite/res']
|
res.srcDirs = ['src/main/res', 'src/lite/res']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,10 +178,8 @@ dependencies {
|
||||||
implementation 'com.huangyz0918:androidwm-light:0.1.2'
|
implementation 'com.huangyz0918:androidwm-light:0.1.2'
|
||||||
|
|
||||||
|
|
||||||
|
implementation 'com.github.UnifiedPush:android-connector:dev-SNAPSHOT'
|
||||||
implementation "com.madgag.spongycastle:bctls-jdk15on:1.58.0.0"
|
implementation "com.madgag.spongycastle:bctls-jdk15on:1.58.0.0"
|
||||||
//implementation 'org.bouncycastle:bcprov-jdk15on:1.64'
|
|
||||||
|
|
||||||
implementation 'com.github.p1gp1g:android-connector-1:1.1.0-beta1'
|
|
||||||
//Flavors
|
//Flavors
|
||||||
|
|
||||||
//Playstore
|
//Playstore
|
||||||
|
@ -187,7 +189,7 @@ dependencies {
|
||||||
playstoreImplementation 'org.framagit.tom79:country-picker-android:1.2.0'
|
playstoreImplementation 'org.framagit.tom79:country-picker-android:1.2.0'
|
||||||
playstoreImplementation 'com.vanniktech:emoji-one:0.6.0'
|
playstoreImplementation 'com.vanniktech:emoji-one:0.6.0'
|
||||||
playstoreImplementation 'ja.burhanrashid52:photoeditor:0.4.0'
|
playstoreImplementation 'ja.burhanrashid52:photoeditor:0.4.0'
|
||||||
|
playstoreImplementation 'com.github.UnifiedPush:android-connector_fcm_added:dev-SNAPSHOT'
|
||||||
|
|
||||||
//Fdroid
|
//Fdroid
|
||||||
fdroidApi 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
|
fdroidApi 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
|
||||||
|
@ -196,4 +198,8 @@ dependencies {
|
||||||
fdroidImplementation 'com.vanniktech:emoji-one:0.6.0'
|
fdroidImplementation 'com.vanniktech:emoji-one:0.6.0'
|
||||||
fdroidImplementation 'ja.burhanrashid52:photoeditor:0.4.0'
|
fdroidImplementation 'ja.burhanrashid52:photoeditor:0.4.0'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.google.gms.google-services'
|
||||||
|
|
|
@ -1,4 +1,44 @@
|
||||||
package app.fedilab.android.helper;
|
package app.fedilab.android.helper;
|
||||||
|
|
||||||
class PushHelper {
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import org.unifiedpush.android.connector.Registration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
import app.fedilab.android.jobs.ApplicationJob;
|
||||||
|
import app.fedilab.android.jobs.NotificationsSyncJob;
|
||||||
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
|
import static app.fedilab.android.helper.BaseHelper.NOTIF_NONE;
|
||||||
|
import static app.fedilab.android.helper.BaseHelper.NOTIF_PUSH;
|
||||||
|
import static app.fedilab.android.helper.BaseHelper.liveNotifType;
|
||||||
|
|
||||||
|
public class PushHelper {
|
||||||
|
|
||||||
|
public static void startStreaming(Context context) {
|
||||||
|
int liveNotifications = liveNotifType(context);
|
||||||
|
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
||||||
|
NotificationsSyncJob.schedule(false);
|
||||||
|
switch (liveNotifications) {
|
||||||
|
case NOTIF_PUSH:
|
||||||
|
new Thread(() -> {
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
||||||
|
((Activity) context).runOnUiThread(() -> {
|
||||||
|
for (Account account : accounts) {
|
||||||
|
new Registration().registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).start();
|
||||||
|
break;
|
||||||
|
case NOTIF_NONE:
|
||||||
|
new Registration().unregisterApp(context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,7 @@ import app.fedilab.android.helper.CrossActions;
|
||||||
import app.fedilab.android.helper.ExpandableHeightListView;
|
import app.fedilab.android.helper.ExpandableHeightListView;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.helper.MenuFloating;
|
import app.fedilab.android.helper.MenuFloating;
|
||||||
|
import app.fedilab.android.helper.PushHelper;
|
||||||
import app.fedilab.android.interfaces.OnFilterActionInterface;
|
import app.fedilab.android.interfaces.OnFilterActionInterface;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
|
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
|
||||||
|
@ -308,6 +309,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
activity = this;
|
activity = this;
|
||||||
rateThisApp();
|
rateThisApp();
|
||||||
|
|
||||||
|
|
||||||
//Intialize Peertube information
|
//Intialize Peertube information
|
||||||
//This task will allow to instance a static PeertubeInformation class
|
//This task will allow to instance a static PeertubeInformation class
|
||||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||||
|
@ -666,7 +668,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
}
|
}
|
||||||
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false);
|
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false);
|
||||||
if (popupShown) {
|
if (popupShown) {
|
||||||
Helper.startStreaming(BaseMainActivity.this);
|
PushHelper.startStreaming(BaseMainActivity.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hidde_menu != null)
|
if (hidde_menu != null)
|
||||||
|
@ -1224,7 +1226,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
case 0:
|
case 0:
|
||||||
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, true);
|
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, true);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
Helper.startStreaming(BaseMainActivity.this);
|
PushHelper.startStreaming(BaseMainActivity.this);
|
||||||
set_live_type_indication.setText(R.string.set_push_notifications);
|
set_live_type_indication.setText(R.string.set_push_notifications);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -1371,6 +1373,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
|
|
||||||
protected abstract void rateThisApp();
|
protected abstract void rateThisApp();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.Error;
|
import app.fedilab.android.client.Entities.Error;
|
||||||
import app.fedilab.android.client.GNUAPI;
|
import app.fedilab.android.client.GNUAPI;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.helper.PushHelper;
|
||||||
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
|
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
import app.fedilab.android.sqlite.TagsCacheDAO;
|
import app.fedilab.android.sqlite.TagsCacheDAO;
|
||||||
|
@ -125,11 +126,6 @@ public class PostStatusAsyncTask {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
thread.start();
|
thread.start();
|
||||||
if (account != null) {
|
|
||||||
String key = account.getUsername() + "@" + account.getInstance();
|
|
||||||
Helper.sleeps.put(key, 30000);
|
|
||||||
Helper.startStreaming(contextReference.get());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
mainHandler.post(myRunnable);
|
mainHandler.post(myRunnable);
|
||||||
}).start();
|
}).start();
|
||||||
|
|
|
@ -22,7 +22,6 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
@ -49,7 +48,6 @@ import java.net.URLEncoder;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.Security;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -107,7 +105,6 @@ import app.fedilab.android.client.Entities.TrendsHistory;
|
||||||
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
||||||
import app.fedilab.android.helper.ECDH;
|
import app.fedilab.android.helper.ECDH;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.helper.PushNotifications;
|
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
import app.fedilab.android.sqlite.TimelineCacheDAO;
|
import app.fedilab.android.sqlite.TimelineCacheDAO;
|
||||||
|
|
|
@ -84,6 +84,7 @@ import app.fedilab.android.drawers.AccountSearchDevAdapter;
|
||||||
import app.fedilab.android.filelister.FileListerDialog;
|
import app.fedilab.android.filelister.FileListerDialog;
|
||||||
import app.fedilab.android.helper.ExpandableHeightListView;
|
import app.fedilab.android.helper.ExpandableHeightListView;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.helper.PushHelper;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveRelationshipInterface;
|
import app.fedilab.android.interfaces.OnRetrieveRelationshipInterface;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveRemoteAccountInterface;
|
import app.fedilab.android.interfaces.OnRetrieveRemoteAccountInterface;
|
||||||
import app.fedilab.android.services.DownloadTrackingDBScriptsService;
|
import app.fedilab.android.services.DownloadTrackingDBScriptsService;
|
||||||
|
@ -926,7 +927,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
||||||
} else {
|
} else {
|
||||||
notification_container.setVisibility(View.GONE);
|
notification_container.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
Helper.startStreaming(context);
|
PushHelper.startStreaming(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -965,7 +966,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
||||||
set_live_type_indication.setText(R.string.no_live_indication);
|
set_live_type_indication.setText(R.string.no_live_indication);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Helper.startStreaming(context);
|
PushHelper.startStreaming(context);
|
||||||
} else {
|
} else {
|
||||||
liveNotificationCount++;
|
liveNotificationCount++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,6 @@ import net.gotev.uploadservice.UploadService;
|
||||||
import net.gotev.uploadservice.okhttp.OkHttpStack;
|
import net.gotev.uploadservice.okhttp.OkHttpStack;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.unifiedpush.android.connector.Registration;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -597,27 +596,6 @@ public class BaseHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startStreaming(Context context) {
|
|
||||||
int liveNotifications = liveNotifType(context);
|
|
||||||
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
|
||||||
NotificationsSyncJob.schedule(false);
|
|
||||||
switch (liveNotifications) {
|
|
||||||
case NOTIF_PUSH:
|
|
||||||
new Thread(() -> {
|
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
||||||
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
|
||||||
((Activity) context).runOnUiThread(() -> {
|
|
||||||
for (Account account : accounts) {
|
|
||||||
new Registration().registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).start();
|
|
||||||
break;
|
|
||||||
case NOTIF_NONE:
|
|
||||||
new Registration().unregisterApp(context);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Check if the user is connected to Internet
|
* Check if the user is connected to Internet
|
||||||
|
|
|
@ -14,7 +14,6 @@ package app.fedilab.android.services;
|
||||||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ import app.fedilab.android.helper.PushNotifications;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
import app.fedilab.android.sqlite.Sqlite;
|
import app.fedilab.android.sqlite.Sqlite;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
|
||||||
|
|
||||||
class handler implements MessagingReceiverHandler {
|
class handler implements MessagingReceiverHandler {
|
||||||
|
|
||||||
|
@ -60,27 +58,24 @@ class handler implements MessagingReceiverHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
|
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
Log.v(Helper.TAG, "onNewEndpoint: " + slug);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(Helper.SERVER_ENDPOINT, endpoint);
|
|
||||||
editor.apply();
|
|
||||||
new PushNotifications()
|
new PushNotifications()
|
||||||
.registerPushNotifications(context, endpoint, slug);
|
.registerPushNotifications(context, endpoint, slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRegistrationFailed(@Nullable Context context, @NotNull String s) {
|
public void onRegistrationFailed(@Nullable Context context, @NotNull String s) {
|
||||||
|
Log.v(Helper.TAG, "onRegistrationFailed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRegistrationRefused(@Nullable Context context, @NotNull String s) {
|
public void onRegistrationRefused(@Nullable Context context, @NotNull String s) {
|
||||||
|
Log.v(Helper.TAG, "onRegistrationFailed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUnregistered(@Nullable Context context, @NotNull String s) {
|
public void onUnregistered(@Nullable Context context, @NotNull String s) {
|
||||||
|
Log.v(Helper.TAG, "onRegistrationFailed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,17 +21,13 @@
|
||||||
|
|
||||||
<application>
|
<application>
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".services.UnifiedPushService"
|
android:name=".services.FakeDistributor"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.unifiedpush.android.connector.MESSAGE" />
|
<action android:name="org.unifiedpush.android.distributor.REGISTER" />
|
||||||
<action android:name="org.unifiedpush.android.connector.UNREGISTERED" />
|
<action android:name="org.unifiedpush.android.distributor.UNREGISTER" />
|
||||||
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT" />
|
|
||||||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED" />
|
|
||||||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_REFUSED" />
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
|
@ -1,10 +1,14 @@
|
||||||
package app.fedilab.android.helper;
|
package app.fedilab.android.helper;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.unifiedpush.android.connector.Registration;
|
import org.unifiedpush.android.connector_fcm_added.RegistrationFCM;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,8 +22,10 @@ import static app.fedilab.android.helper.BaseHelper.NOTIF_NONE;
|
||||||
import static app.fedilab.android.helper.BaseHelper.NOTIF_PUSH;
|
import static app.fedilab.android.helper.BaseHelper.NOTIF_PUSH;
|
||||||
import static app.fedilab.android.helper.BaseHelper.liveNotifType;
|
import static app.fedilab.android.helper.BaseHelper.liveNotifType;
|
||||||
|
|
||||||
|
|
||||||
public class PushHelper {
|
public class PushHelper {
|
||||||
|
|
||||||
|
|
||||||
public static void startStreaming(Context context) {
|
public static void startStreaming(Context context) {
|
||||||
int liveNotifications = liveNotifType(context);
|
int liveNotifications = liveNotifType(context);
|
||||||
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
||||||
|
@ -30,14 +36,15 @@ public class PushHelper {
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
||||||
((Activity) context).runOnUiThread(() -> {
|
((Activity) context).runOnUiThread(() -> {
|
||||||
|
RegistrationFCM registration = new RegistrationFCM();
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
new Registration().registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
|
registration.registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).start();
|
}).start();
|
||||||
break;
|
break;
|
||||||
case NOTIF_NONE:
|
case NOTIF_NONE:
|
||||||
new Registration().unregisterApp(context);
|
new RegistrationFCM().unregisterApp(context);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package app.fedilab.android.services;
|
||||||
|
|
||||||
import org.unifiedpush.android.connector_fcm_added.FakeDistributorReceiver;
|
import org.unifiedpush.android.connector_fcm_added.FakeDistributorReceiver;
|
||||||
|
|
||||||
class FakeDistributor extends FakeDistributorReceiver {
|
public class FakeDistributor extends FakeDistributorReceiver {
|
||||||
public FakeDistributor() {
|
public FakeDistributor() {
|
||||||
super(new HandlerFCM());
|
super(new HandlerFCM());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,6 @@ public class HandlerFCM implements GetEndpointHandler {
|
||||||
public @NotNull String getEndpoint(@Nullable Context context, @NotNull String token, @NotNull String instance) {
|
public @NotNull String getEndpoint(@Nullable Context context, @NotNull String token, @NotNull String instance) {
|
||||||
return "https://gotify.fedilab.org/UP?token=" + token;
|
return "https://gotify.fedilab.org/UP?token=" + token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||||
|
classpath 'com.google.gms:google-services:4.3.5'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
Loading…
Reference in New Issue