Browse Source

google fcm

unifiedpush
Thomas 2 months ago
parent
commit
cebce4bec6
13 changed files with 85 additions and 63 deletions
  1. +13
    -7
      app/build.gradle
  2. +41
    -1
      app/src/fdroidcommon/java/app/fedilab/android/helper/PushHelper.java
  3. +5
    -2
      app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java
  4. +1
    -5
      app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java
  5. +0
    -3
      app/src/main/java/app/fedilab/android/client/API.java
  6. +3
    -2
      app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java
  7. +0
    -22
      app/src/main/java/app/fedilab/android/helper/BaseHelper.java
  8. +4
    -9
      app/src/main/java/app/fedilab/android/services/UnifiedPushService.java
  9. +4
    -8
      app/src/playstore/AndroidManifest.xml
  10. +10
    -3
      app/src/playstore/java/app/fedilab/android/helper/PushHelper.java
  11. +1
    -1
      app/src/playstore/java/app/fedilab/android/services/FakeDistributor.java
  12. +2
    -0
      app/src/playstore/java/app/fedilab/android/services/HandlerFCM.java
  13. +1
    -0
      build.gradle

+ 13
- 7
app/build.gradle View File

@@ -1,5 +1,5 @@
apply plugin: 'com.android.application'
def flavor
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
@@ -42,6 +42,7 @@ android {
buildConfigField "boolean", "DONATIONS", "true"
buildConfigField "boolean", "lite", "false"
resValue "string", "app_name", "Fedilab"
flavor = "fdroid"
}
lite {
minSdkVersion 21
@@ -49,12 +50,14 @@ android {
buildConfigField "boolean", "DONATIONS", "true"
buildConfigField "boolean", "lite", "true"
resValue "string", "app_name", "Fedilab Lite"
flavor = "lite"
}
playstore {
applicationId "app.fedilab.android"
buildConfigField "boolean", "DONATIONS", "false"
buildConfigField "boolean", "lite", "false"
resValue "string", "app_name", "Fedilab"
flavor = "playstore"
}
}
buildFeatures {
@@ -62,6 +65,7 @@ android {
}
sourceSets {
playstore {

manifest.srcFile "src/common/AndroidManifest.xml"
assets.srcDirs = ['/src/mains/assets', 'src/common/assets']
java.srcDirs = ['src/main/java', 'src/playstore/java','src/common/java']
@@ -71,13 +75,13 @@ android {
fdroid {
manifest.srcFile "src/common/AndroidManifest.xml"
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']
}
lite {
manifest.srcFile "src/lite/AndroidManifest.xml"
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']
}
}
@@ -174,10 +178,8 @@ dependencies {
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 'org.bouncycastle:bcprov-jdk15on:1.64'

implementation 'com.github.p1gp1g:android-connector-1:1.1.0-beta1'
//Flavors

//Playstore
@@ -187,7 +189,7 @@ dependencies {
playstoreImplementation 'org.framagit.tom79:country-picker-android:1.2.0'
playstoreImplementation 'com.vanniktech:emoji-one:0.6.0'
playstoreImplementation 'ja.burhanrashid52:photoeditor:0.4.0'
playstoreImplementation 'com.github.UnifiedPush:android-connector_fcm_added:dev-SNAPSHOT'

//Fdroid
fdroidApi 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
@@ -196,4 +198,8 @@ dependencies {
fdroidImplementation 'com.vanniktech:emoji-one:0.6.0'
fdroidImplementation 'ja.burhanrashid52:photoeditor:0.4.0'



}

apply plugin: 'com.google.gms.google-services'

+ 41
- 1
app/src/fdroidcommon/java/app/fedilab/android/helper/PushHelper.java View File

@@ -1,4 +1,44 @@
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;
}
}
}

+ 5
- 2
app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java View File

@@ -136,6 +136,7 @@ import app.fedilab.android.helper.CrossActions;
import app.fedilab.android.helper.ExpandableHeightListView;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.MenuFloating;
import app.fedilab.android.helper.PushHelper;
import app.fedilab.android.interfaces.OnFilterActionInterface;
import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
import app.fedilab.android.interfaces.OnRetrieveFeedsInterface;
@@ -308,6 +309,7 @@ public abstract class BaseMainActivity extends BaseActivity
activity = this;
rateThisApp();


//Intialize Peertube information
//This task will allow to instance a static PeertubeInformation class
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
@@ -666,7 +668,7 @@ public abstract class BaseMainActivity extends BaseActivity
}
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false);
if (popupShown) {
Helper.startStreaming(BaseMainActivity.this);
PushHelper.startStreaming(BaseMainActivity.this);
}

if (hidde_menu != null)
@@ -1224,7 +1226,7 @@ public abstract class BaseMainActivity extends BaseActivity
case 0:
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, true);
editor.apply();
Helper.startStreaming(BaseMainActivity.this);
PushHelper.startStreaming(BaseMainActivity.this);
set_live_type_indication.setText(R.string.set_push_notifications);
break;
case 1:
@@ -1371,6 +1373,7 @@ public abstract class BaseMainActivity extends BaseActivity

protected abstract void rateThisApp();


@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);


+ 1
- 5
app/src/main/java/app/fedilab/android/asynctasks/PostStatusAsyncTask.java View File

@@ -30,6 +30,7 @@ import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.GNUAPI;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.PushHelper;
import app.fedilab.android.interfaces.OnPostStatusActionInterface;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.TagsCacheDAO;
@@ -125,11 +126,6 @@ public class PostStatusAsyncTask {
}
};
thread.start();
if (account != null) {
String key = account.getUsername() + "@" + account.getInstance();
Helper.sleeps.put(key, 30000);
Helper.startStreaming(contextReference.get());
}
};
mainHandler.post(myRunnable);
}).start();


+ 0
- 3
app/src/main/java/app/fedilab/android/client/API.java View File

@@ -22,7 +22,6 @@ import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.util.Log;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
@@ -49,7 +48,6 @@ import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.text.DateFormat;
import java.text.ParseException;
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.helper.ECDH;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.PushNotifications;
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.TimelineCacheDAO;


+ 3
- 2
app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java View File

@@ -84,6 +84,7 @@ import app.fedilab.android.drawers.AccountSearchDevAdapter;
import app.fedilab.android.filelister.FileListerDialog;
import app.fedilab.android.helper.ExpandableHeightListView;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.PushHelper;
import app.fedilab.android.interfaces.OnRetrieveRelationshipInterface;
import app.fedilab.android.interfaces.OnRetrieveRemoteAccountInterface;
import app.fedilab.android.services.DownloadTrackingDBScriptsService;
@@ -926,7 +927,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
} else {
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);
break;
}
Helper.startStreaming(context);
PushHelper.startStreaming(context);
} else {
liveNotificationCount++;
}


+ 0
- 22
app/src/main/java/app/fedilab/android/helper/BaseHelper.java View File

@@ -137,7 +137,6 @@ import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack;

import org.jetbrains.annotations.NotNull;
import org.unifiedpush.android.connector.Registration;

import java.io.ByteArrayInputStream;
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


+ 4
- 9
app/src/main/java/app/fedilab/android/services/UnifiedPushService.java View File

@@ -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,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
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.Sqlite;

import static android.content.Context.MODE_PRIVATE;

class handler implements MessagingReceiverHandler {

@@ -60,27 +58,24 @@ class handler implements MessagingReceiverHandler {

@Override
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SERVER_ENDPOINT, endpoint);
editor.apply();
Log.v(Helper.TAG, "onNewEndpoint: " + slug);
new PushNotifications()
.registerPushNotifications(context, endpoint, slug);
}

@Override
public void onRegistrationFailed(@Nullable Context context, @NotNull String s) {
Log.v(Helper.TAG, "onRegistrationFailed");
}

@Override
public void onRegistrationRefused(@Nullable Context context, @NotNull String s) {
Log.v(Helper.TAG, "onRegistrationFailed");
}

@Override
public void onUnregistered(@Nullable Context context, @NotNull String s) {
Log.v(Helper.TAG, "onRegistrationFailed");
}
}



+ 4
- 8
app/src/playstore/AndroidManifest.xml View File

@@ -21,17 +21,13 @@

<application>
<receiver
android:name=".services.UnifiedPushService"
android:name=".services.FakeDistributor"
android:enabled="true"
android:exported="true">
android:exported="false">
<intent-filter>
<action android:name="org.unifiedpush.android.connector.MESSAGE" />
<action android:name="org.unifiedpush.android.connector.UNREGISTERED" />
<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" />
<action android:name="org.unifiedpush.android.distributor.REGISTER" />
<action android:name="org.unifiedpush.android.distributor.UNREGISTER" />
</intent-filter>
</receiver>

</application>
</manifest>

+ 10
- 3
app/src/playstore/java/app/fedilab/android/helper/PushHelper.java View File

@@ -1,10 +1,14 @@
package app.fedilab.android.helper;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
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;

@@ -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.liveNotifType;


public class PushHelper {


public static void startStreaming(Context context) {
int liveNotifications = liveNotifType(context);
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();
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
((Activity) context).runOnUiThread(() -> {
RegistrationFCM registration = new RegistrationFCM();
for (Account account : accounts) {
new Registration().registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
registration.registerAppWithDialog(context, account.getUsername() + "@" + account.getInstance());
}
});
}).start();
break;
case NOTIF_NONE:
new Registration().unregisterApp(context);
new RegistrationFCM().unregisterApp(context);
break;
}
}


+ 1
- 1
app/src/playstore/java/app/fedilab/android/services/FakeDistributor.java View File

@@ -2,7 +2,7 @@ package app.fedilab.android.services;

import org.unifiedpush.android.connector_fcm_added.FakeDistributorReceiver;

class FakeDistributor extends FakeDistributorReceiver {
public class FakeDistributor extends FakeDistributorReceiver {
public FakeDistributor() {
super(new HandlerFCM());
}


+ 2
- 0
app/src/playstore/java/app/fedilab/android/services/HandlerFCM.java View File

@@ -13,4 +13,6 @@ public class HandlerFCM implements GetEndpointHandler {
public @NotNull String getEndpoint(@Nullable Context context, @NotNull String token, @NotNull String instance) {
return "https://gotify.fedilab.org/UP?token=" + token;
}


}

+ 1
- 0
build.gradle View File

@@ -7,6 +7,7 @@ buildscript {
}
dependencies {
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
// in the individual module build.gradle files


Loading…
Cancel
Save