mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
fix push
This commit is contained in:
parent
0f855c5ac2
commit
4767712fb0
16 changed files with 116 additions and 118 deletions
|
@ -30,16 +30,15 @@ import app.fedilab.android.helper.Helper;
|
||||||
@SuppressLint("Registered")
|
@SuppressLint("Registered")
|
||||||
public class BaseActivity extends CyaneaAppCompatActivity {
|
public class BaseActivity extends CyaneaAppCompatActivity {
|
||||||
|
|
||||||
|
static {
|
||||||
|
Helper.installProvider();
|
||||||
|
EmojiManager.install(new EmojiOneProvider());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Helper.setLocale(this);
|
Helper.setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
Helper.installProvider();
|
|
||||||
EmojiManager.install(new EmojiOneProvider());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,10 @@ public class ContextActivity extends BaseActivity {
|
||||||
|
|
||||||
public static boolean expand;
|
public static boolean expand;
|
||||||
public static boolean displayCW;
|
public static boolean displayCW;
|
||||||
|
public static Resources.Theme theme;
|
||||||
Fragment currentFragment;
|
Fragment currentFragment;
|
||||||
private Status focusedStatus;
|
private Status focusedStatus;
|
||||||
private ActivityConversationBinding binding;
|
private ActivityConversationBinding binding;
|
||||||
public static Resources.Theme theme;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
|
@ -93,21 +93,6 @@ public class Account implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all Account in db
|
|
||||||
*
|
|
||||||
* @return Account List<Account>
|
|
||||||
*/
|
|
||||||
public List<Account> getPushNotificationAccounts() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, "(" + Sqlite.COL_API + " = 'MASTODON' OR " + Sqlite.COL_API + " = 'PLEROMA') AND " + Sqlite.COL_TOKEN + " IS NOT NULL", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
|
||||||
return cursorToListUserWithOwner(c);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unserialized a Mastodon Account
|
* Unserialized a Mastodon Account
|
||||||
*
|
*
|
||||||
|
@ -123,6 +108,21 @@ public class Account implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all Account in db
|
||||||
|
*
|
||||||
|
* @return Account List<Account>
|
||||||
|
*/
|
||||||
|
public List<Account> getPushNotificationAccounts() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, "(" + Sqlite.COL_API + " = 'MASTODON' OR " + Sqlite.COL_API + " = 'PLEROMA') AND " + Sqlite.COL_TOKEN + " IS NOT NULL", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
||||||
|
return cursorToListUserWithOwner(c);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert or update a user
|
* Insert or update a user
|
||||||
*
|
*
|
||||||
|
|
|
@ -986,7 +986,13 @@ public class Helper {
|
||||||
.setContentIntent(pIntent)
|
.setContentIntent(pIntent)
|
||||||
.setContentText(message);
|
.setContentText(message);
|
||||||
int ledColour = Color.BLUE;
|
int ledColour = Color.BLUE;
|
||||||
switch (sharedpreferences.getInt(context.getString(R.string.SET_LED_COLOUR_VAL), LED_COLOUR)) {
|
int prefColor;
|
||||||
|
try {
|
||||||
|
prefColor = sharedpreferences.getInt(context.getString(R.string.SET_LED_COLOUR_VAL), LED_COLOUR);
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
prefColor = Integer.parseInt(sharedpreferences.getString(context.getString(R.string.SET_LED_COLOUR_VAL), String.valueOf(LED_COLOUR)));
|
||||||
|
}
|
||||||
|
switch (prefColor) {
|
||||||
case 0: // BLUE
|
case 0: // BLUE
|
||||||
ledColour = Color.BLUE;
|
ledColour = Color.BLUE;
|
||||||
break;
|
break;
|
||||||
|
@ -1280,6 +1286,32 @@ public class Helper {
|
||||||
return dateFormat.format(date);
|
return dateFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change locale
|
||||||
|
*
|
||||||
|
* @param activity - Activity
|
||||||
|
*/
|
||||||
|
public static void setLocale(Activity activity) {
|
||||||
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
String defaultLocaleString = sharedpreferences.getString(activity.getString(R.string.SET_DEFAULT_LOCALE_NEW), null);
|
||||||
|
if (defaultLocaleString != null) {
|
||||||
|
Locale locale;
|
||||||
|
if (defaultLocaleString.equals("zh-CN")) {
|
||||||
|
locale = Locale.SIMPLIFIED_CHINESE;
|
||||||
|
} else if (defaultLocaleString.equals("zh-TW")) {
|
||||||
|
locale = Locale.TRADITIONAL_CHINESE;
|
||||||
|
} else {
|
||||||
|
locale = new Locale(defaultLocaleString);
|
||||||
|
}
|
||||||
|
Locale.setDefault(locale);
|
||||||
|
Resources resources = activity.getResources();
|
||||||
|
Configuration config = resources.getConfiguration();
|
||||||
|
config.setLocale(locale);
|
||||||
|
resources.updateConfiguration(config, resources.getDisplayMetrics());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Enum that described actions to replace inside a toot content
|
//Enum that described actions to replace inside a toot content
|
||||||
public enum PatternType {
|
public enum PatternType {
|
||||||
MENTION,
|
MENTION,
|
||||||
|
@ -1362,30 +1394,4 @@ public class Helper {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Change locale
|
|
||||||
*
|
|
||||||
* @param activity - Activity
|
|
||||||
*/
|
|
||||||
public static void setLocale(Activity activity) {
|
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
|
||||||
String defaultLocaleString = sharedpreferences.getString(activity.getString(R.string.SET_DEFAULT_LOCALE_NEW), null);
|
|
||||||
if (defaultLocaleString != null) {
|
|
||||||
Locale locale;
|
|
||||||
if (defaultLocaleString.equals("zh-CN")) {
|
|
||||||
locale = Locale.SIMPLIFIED_CHINESE;
|
|
||||||
} else if (defaultLocaleString.equals("zh-TW")) {
|
|
||||||
locale = Locale.TRADITIONAL_CHINESE;
|
|
||||||
} else {
|
|
||||||
locale = new Locale(defaultLocaleString);
|
|
||||||
}
|
|
||||||
Locale.setDefault(locale);
|
|
||||||
Resources resources = activity.getResources();
|
|
||||||
Configuration config = resources.getConfiguration();
|
|
||||||
config.setLocale(locale);
|
|
||||||
resources.updateConfiguration(config, resources.getDisplayMetrics());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -69,12 +68,11 @@ public class NotificationsHelper {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(context);
|
.getDefaultSharedPreferences(context);
|
||||||
String[] slugArray = slug.split("@");
|
String[] slugArray = slug.split("@");
|
||||||
Log.v(Helper.TAG, "slug: " + slug);
|
|
||||||
Account accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]);
|
Account accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]);
|
||||||
if (accountDb == null) {
|
if (accountDb == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String last_notifid = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + slug, null);
|
String last_notifid = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + slug, null);
|
||||||
//Check which notifications the user wants to see
|
//Check which notifications the user wants to see
|
||||||
boolean notif_follow = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FOLLOW), true);
|
boolean notif_follow = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FOLLOW), true);
|
||||||
boolean notif_mention = prefs.getBoolean(context.getString(R.string.SET_NOTIF_MENTION), true);
|
boolean notif_mention = prefs.getBoolean(context.getString(R.string.SET_NOTIF_MENTION), true);
|
||||||
|
@ -98,11 +96,12 @@ public class NotificationsHelper {
|
||||||
try {
|
try {
|
||||||
Response<List<Notification>> notificationsResponse = notificationsCall.execute();
|
Response<List<Notification>> notificationsResponse = notificationsCall.execute();
|
||||||
if (notificationsResponse.isSuccessful()) {
|
if (notificationsResponse.isSuccessful()) {
|
||||||
List<Notification> notFilteredNotifications = notificationsResponse.body();
|
notifications.notifications = notificationsResponse.body();
|
||||||
notifications.notifications = TimelineHelper.filterNotification(context.getApplicationContext(), notFilteredNotifications);
|
if (notifications.notifications != null) {
|
||||||
for (Notification notification : notifications.notifications) {
|
for (Notification notification : notifications.notifications) {
|
||||||
if (notification != null) {
|
if (notification != null && notification.status != null) {
|
||||||
notification.status = SpannableHelper.convertStatus(context.getApplicationContext(), notification.status);
|
notification.status = SpannableHelper.convertStatus(context.getApplicationContext(), notification.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications);
|
notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications);
|
||||||
|
@ -137,7 +136,6 @@ public class NotificationsHelper {
|
||||||
|
|
||||||
public static void onRetrieveNotifications(Context context, Notifications newNotifications, final Account account) {
|
public static void onRetrieveNotifications(Context context, Notifications newNotifications, final Account account) {
|
||||||
List<Notification> notificationsReceived = newNotifications.notifications;
|
List<Notification> notificationsReceived = newNotifications.notifications;
|
||||||
|
|
||||||
if (notificationsReceived == null || notificationsReceived.size() == 0 || account == null)
|
if (notificationsReceived == null || notificationsReceived.size() == 0 || account == null)
|
||||||
return;
|
return;
|
||||||
String key = account.user_id + "@" + account.instance;
|
String key = account.user_id + "@" + account.instance;
|
||||||
|
@ -149,7 +147,7 @@ public class NotificationsHelper {
|
||||||
boolean notif_poll = prefs.getBoolean(context.getString(R.string.SET_NOTIF_POLL), true);
|
boolean notif_poll = prefs.getBoolean(context.getString(R.string.SET_NOTIF_POLL), true);
|
||||||
boolean notif_fav = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FAVOURITE), true);
|
boolean notif_fav = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FAVOURITE), true);
|
||||||
boolean notif_status = prefs.getBoolean(context.getString(R.string.SET_NOTIF_STATUS), true);
|
boolean notif_status = prefs.getBoolean(context.getString(R.string.SET_NOTIF_STATUS), true);
|
||||||
final String max_id = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + key, null);
|
final String max_id = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + key, null);
|
||||||
final List<Notification> notifications = new ArrayList<>();
|
final List<Notification> notifications = new ArrayList<>();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (Notification notif : notificationsReceived) {
|
for (Notification notif : notificationsReceived) {
|
||||||
|
@ -309,10 +307,10 @@ public class NotificationsHelper {
|
||||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
|
||||||
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(),
|
||||||
R.mipmap.ic_launcher), finalNotifType, context.getString(R.string.top_notification), finalMessage1);
|
R.mipmap.ic_launcher), finalNotifType, context.getString(R.string.top_notification), finalMessage1);
|
||||||
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + account.user_id + "@" + account.instance, null);
|
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
|
||||||
if (lastNotif == null || notifications.get(0).id.compareTo(lastNotif) > 0) {
|
if (lastNotif == null || notifications.get(0).id.compareTo(lastNotif) > 0) {
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -322,10 +320,10 @@ public class NotificationsHelper {
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||||
notify_user(context, account, intent, resource, finalNotifType, context.getString(R.string.top_notification), finalMessage);
|
notify_user(context, account, intent, resource, finalNotifType, context.getString(R.string.top_notification), finalMessage);
|
||||||
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + account.user_id + "@" + account.instance, null);
|
String lastNotif = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, null);
|
||||||
if (lastNotif == null || notifications.get(0).id.compareTo(lastNotif) > 0) {
|
if (lastNotif == null || notifications.get(0).id.compareTo(lastNotif) > 0) {
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(context.getString(R.string.LAST_NOTIFICATION_MAX_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
editor.putString(context.getString(R.string.LAST_NOTIFICATION_ID) + account.user_id + "@" + account.instance, notifications.get(0).id);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,10 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.client.entities.Account;
|
||||||
import app.fedilab.android.client.mastodon.MastodonNotificationsService;
|
import app.fedilab.android.client.mastodon.MastodonNotificationsService;
|
||||||
import app.fedilab.android.client.mastodon.entities.PushSubscription;
|
import app.fedilab.android.client.mastodon.entities.PushSubscription;
|
||||||
|
import app.fedilab.android.exception.DBException;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
@ -76,9 +78,19 @@ public class PushNotifications {
|
||||||
MastodonNotificationsService mastodonNotificationsService = init(context, BaseMainActivity.currentInstance);
|
MastodonNotificationsService mastodonNotificationsService = init(context, BaseMainActivity.currentInstance);
|
||||||
ECDH finalEcdh = ecdh;
|
ECDH finalEcdh = ecdh;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
String[] slugArray = slug.split("@");
|
||||||
|
Account accountDb = null;
|
||||||
|
try {
|
||||||
|
accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]);
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (accountDb == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
PushSubscription pushSubscription;
|
PushSubscription pushSubscription;
|
||||||
Call<PushSubscription> pushSubscriptionCall = mastodonNotificationsService.pushSubscription(
|
Call<PushSubscription> pushSubscriptionCall = mastodonNotificationsService.pushSubscription(
|
||||||
BaseMainActivity.currentToken,
|
accountDb.token,
|
||||||
endpoint,
|
endpoint,
|
||||||
pubKey,
|
pubKey,
|
||||||
auth,
|
auth,
|
||||||
|
|
|
@ -197,11 +197,6 @@ public class ThemeHelper {
|
||||||
viewToShow.startAnimation(animateShow);
|
viewToShow.startAnimation(animateShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SlideAnimation {
|
|
||||||
void onAnimationEnded();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<LinkedHashMap<String, String>> getContributorsTheme(Context context) {
|
public static List<LinkedHashMap<String, String>> getContributorsTheme(Context context) {
|
||||||
List<LinkedHashMap<String, String>> linkedHashMaps = new ArrayList<>();
|
List<LinkedHashMap<String, String>> linkedHashMaps = new ArrayList<>();
|
||||||
String[] list;
|
String[] list;
|
||||||
|
@ -220,7 +215,6 @@ public class ThemeHelper {
|
||||||
return linkedHashMaps;
|
return linkedHashMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static LinkedHashMap<String, String> readCSVFile(InputStream inputStream) {
|
private static LinkedHashMap<String, String> readCSVFile(InputStream inputStream) {
|
||||||
LinkedHashMap<String, String> readValues = new LinkedHashMap<>();
|
LinkedHashMap<String, String> readValues = new LinkedHashMap<>();
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
|
@ -249,7 +243,6 @@ public class ThemeHelper {
|
||||||
return readValues;
|
return readValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow to set colors for tablayout
|
* Allow to set colors for tablayout
|
||||||
*
|
*
|
||||||
|
@ -282,7 +275,6 @@ public class ThemeHelper {
|
||||||
materialButton.setBackgroundTintList(ThemeHelper.getBackgroundButtonColorStateList(context));
|
materialButton.setBackgroundTintList(ThemeHelper.getBackgroundButtonColorStateList(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow to set ThumbDrawable colors for SwitchCompat
|
* Allow to set ThumbDrawable colors for SwitchCompat
|
||||||
*
|
*
|
||||||
|
@ -372,4 +364,8 @@ public class ThemeHelper {
|
||||||
intentBD.putExtras(b);
|
intentBD.putExtras(b);
|
||||||
LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBD);
|
LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface SlideAnimation {
|
||||||
|
void onAnimationEnded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package app.fedilab.android;
|
package app.fedilab.android.interfaces;
|
||||||
/* Copyright 2021 Thomas Schneider
|
/* Copyright 2021 Thomas Schneider
|
||||||
*
|
*
|
||||||
* This file is a part of Fedilab
|
* This file is a part of Fedilab
|
|
@ -16,7 +16,6 @@ package app.fedilab.android.services;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
@ -24,7 +23,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.unifiedpush.android.connector.MessagingReceiver;
|
import org.unifiedpush.android.connector.MessagingReceiver;
|
||||||
|
|
||||||
import app.fedilab.android.helper.Helper;
|
|
||||||
import app.fedilab.android.helper.NotificationsHelper;
|
import app.fedilab.android.helper.NotificationsHelper;
|
||||||
import app.fedilab.android.helper.PushNotifications;
|
import app.fedilab.android.helper.PushNotifications;
|
||||||
|
|
||||||
|
@ -40,18 +38,14 @@ public class CustomReceiver extends MessagingReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String slug) {
|
public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String slug) {
|
||||||
// Called when a new message is received. The message contains the full POST body of the push message
|
// Called when a new message is received. The message contains the full POST body of the push message
|
||||||
Log.v(Helper.TAG, "onMessage: " + slug);
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
/* ECDH ecdh = ECDH.getInstance(slug);
|
/* ECDH ecdh = ECDH.getInstance(slug);
|
||||||
Log.v(Helper.TAG, "ecdh: " + ecdh);
|
|
||||||
if (ecdh == null) {
|
if (ecdh == null) {
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
//String decrypted = ecdh.uncryptMessage(context, String.valueOf(message));
|
//String decrypted = ecdh.uncryptMessage(context, String.valueOf(message));
|
||||||
// Log.v(Helper.TAG, "decrypted: " + decrypted);
|
|
||||||
NotificationsHelper.task(context, slug);
|
NotificationsHelper.task(context, slug);
|
||||||
// Log.v(Helper.TAG, "decrypted: " + decrypted);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -71,18 +65,15 @@ public class CustomReceiver extends MessagingReceiver {
|
||||||
PushNotifications
|
PushNotifications
|
||||||
.registerPushNotifications(context, endpoint, slug);
|
.registerPushNotifications(context, endpoint, slug);
|
||||||
}
|
}
|
||||||
Log.v(Helper.TAG, "onNewEndpoint: " + 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: " + s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUnregistered(@Nullable Context context, @NotNull String s) {
|
public void onUnregistered(@Nullable Context context, @NotNull String s) {
|
||||||
Log.v(Helper.TAG, "onUnregistered: " + s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private static final int searchDeep = 15;
|
private static final int searchDeep = 15;
|
||||||
|
private static final int TYPE_COMPOSE = 1;
|
||||||
public static boolean autocomplete = false;
|
public static boolean autocomplete = false;
|
||||||
public static String[] ALPHA = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
|
public static String[] ALPHA = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
|
||||||
"s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", ",", "?",
|
"s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", ",", "?",
|
||||||
|
@ -114,7 +115,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
"..--..", ".-.-.-", ".----.",};
|
"..--..", ".-.-.-", ".----.",};
|
||||||
private final List<Status> statusList;
|
private final List<Status> statusList;
|
||||||
private final int TYPE_NORMAL = 0;
|
private final int TYPE_NORMAL = 0;
|
||||||
private static final int TYPE_COMPOSE = 1;
|
|
||||||
private final Account account;
|
private final Account account;
|
||||||
public ManageDrafts manageDrafts;
|
public ManageDrafts manageDrafts;
|
||||||
List<Emoji> emojis;
|
List<Emoji> emojis;
|
||||||
|
@ -134,6 +134,28 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
composeViewHolder.binding.characterProgress.setProgress(charCount);
|
composeViewHolder.binding.characterProgress.setProgress(charCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StatusDraft prepareDraft(List<Status> statusList, ComposeAdapter composeAdapter, String instance, String user_id) {
|
||||||
|
//Collect all statusCompose
|
||||||
|
List<Status> statusDrafts = new ArrayList<>();
|
||||||
|
List<Status> statusReplies = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
|
for (Status status : statusList) {
|
||||||
|
|
||||||
|
//Statuses must be sent
|
||||||
|
if (composeAdapter.getItemViewType(i) == TYPE_COMPOSE) {
|
||||||
|
statusDrafts.add(status);
|
||||||
|
} else {
|
||||||
|
statusReplies.add(status);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
StatusDraft statusDraftDB = new StatusDraft();
|
||||||
|
statusDraftDB.statusReplyList = statusReplies;
|
||||||
|
statusDraftDB.statusDraftList = statusDrafts;
|
||||||
|
statusDraftDB.instance = instance;
|
||||||
|
statusDraftDB.user_id = user_id;
|
||||||
|
return statusDraftDB;
|
||||||
|
}
|
||||||
|
|
||||||
//Create text when mentioning a toot
|
//Create text when mentioning a toot
|
||||||
public void loadMentions(Status status) {
|
public void loadMentions(Status status) {
|
||||||
|
@ -194,7 +216,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setStatusCount(int count) {
|
public void setStatusCount(int count) {
|
||||||
statusCount = count;
|
statusCount = count;
|
||||||
}
|
}
|
||||||
|
@ -366,13 +387,13 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
}
|
}
|
||||||
notifyItemChanged(statusList.size() - 1);
|
notifyItemChanged(statusList.size() - 1);
|
||||||
}
|
}
|
||||||
|
//------- end contact ----->
|
||||||
|
|
||||||
//Put cursor to the end after changing contacts
|
//Put cursor to the end after changing contacts
|
||||||
public void putCursor() {
|
public void putCursor() {
|
||||||
statusList.get(statusList.size() - 1).setCursorToEnd = true;
|
statusList.get(statusList.size() - 1).setCursorToEnd = true;
|
||||||
notifyItemChanged(statusList.size() - 1);
|
notifyItemChanged(statusList.size() - 1);
|
||||||
}
|
}
|
||||||
//------- end contact ----->
|
|
||||||
|
|
||||||
private void displayAttachments(ComposeViewHolder holder, int position, int scrollToMediaPosition) {
|
private void displayAttachments(ComposeViewHolder holder, int position, int scrollToMediaPosition) {
|
||||||
if (statusList.size() > position && statusList.get(position).media_attachments != null) {
|
if (statusList.size() > position && statusList.get(position).media_attachments != null) {
|
||||||
|
@ -567,7 +588,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
return statusList.size();
|
return statusList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize text watcher for content writing
|
* Initialize text watcher for content writing
|
||||||
* It will allow to complete autocomplete edit text while starting words with @, #, : etc.
|
* It will allow to complete autocomplete edit text while starting words with @, #, : etc.
|
||||||
|
@ -906,29 +926,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||||
return textw;
|
return textw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StatusDraft prepareDraft(List<Status> statusList, ComposeAdapter composeAdapter, String instance, String user_id) {
|
|
||||||
//Collect all statusCompose
|
|
||||||
List<Status> statusDrafts = new ArrayList<>();
|
|
||||||
List<Status> statusReplies = new ArrayList<>();
|
|
||||||
int i = 0;
|
|
||||||
for (Status status : statusList) {
|
|
||||||
|
|
||||||
//Statuses must be sent
|
|
||||||
if (composeAdapter.getItemViewType(i) == TYPE_COMPOSE) {
|
|
||||||
statusDrafts.add(status);
|
|
||||||
} else {
|
|
||||||
statusReplies.add(status);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
StatusDraft statusDraftDB = new StatusDraft();
|
|
||||||
statusDraftDB.statusReplyList = statusReplies;
|
|
||||||
statusDraftDB.statusDraftList = statusDrafts;
|
|
||||||
statusDraftDB.instance = instance;
|
|
||||||
statusDraftDB.user_id = user_id;
|
|
||||||
return statusDraftDB;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
|
|
@ -257,7 +257,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (truncate_toots_size > 0) {
|
if (truncate_toots_size > 0) {
|
||||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
|
|
@ -112,8 +112,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,9 +25,9 @@ import androidx.lifecycle.MutableLiveData;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import app.fedilab.android.InstancesSocialService;
|
|
||||||
import app.fedilab.android.client.entities.InstanceSocial;
|
import app.fedilab.android.client.entities.InstanceSocial;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.interfaces.InstancesSocialService;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
|
@ -27,19 +27,21 @@
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".activities.ContextActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/appBar"
|
android:id="@+id/appBar"
|
||||||
android:background="@color/cyanea_primary_reference"
|
android:background="@color/cyanea_primary_reference"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
>
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:layout_scrollFlags="scroll|enterAlways"
|
app:layout_scrollFlags="scroll|enterAlways"
|
||||||
android:fitsSystemWindows="true">
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/profile_picture"
|
android:id="@+id/profile_picture"
|
||||||
android:layout_width="30dp"
|
android:layout_width="30dp"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
see <http://www.gnu.org/licenses>.
|
see <http://www.gnu.org/licenses>.
|
||||||
-->
|
-->
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:backgroundTint="?backgroundColorLight"
|
android:background="@color/cyanea_background_dark"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
|
@ -1562,7 +1562,7 @@
|
||||||
<string name="REPLACE_WIKIPEDIA" translatable="false">REPLACE_WIKIPEDIA</string>
|
<string name="REPLACE_WIKIPEDIA" translatable="false">REPLACE_WIKIPEDIA</string>
|
||||||
<string name="REPLACE_WIKIPEDIA_HOST" translatable="false">REPLACE_WIKIPEDIA_HOST</string>
|
<string name="REPLACE_WIKIPEDIA_HOST" translatable="false">REPLACE_WIKIPEDIA_HOST</string>
|
||||||
<string name="DEFAULT_REPLACE_WIKIPEDIA_HOST" translatable="false">wikiless.org</string>
|
<string name="DEFAULT_REPLACE_WIKIPEDIA_HOST" translatable="false">wikiless.org</string>
|
||||||
<string name="LAST_NOTIFICATION_MAX_ID" translatable="false">LAST_NOTIFICATION_MAX_ID</string>
|
<string name="LAST_NOTIFICATION_ID" translatable="false">LAST_NOTIFICATION_ID</string>
|
||||||
<string name="type_of_notifications">Type of notifications</string>
|
<string name="type_of_notifications">Type of notifications</string>
|
||||||
<string name="alternative_frontends">Alternative frontends</string>
|
<string name="alternative_frontends">Alternative frontends</string>
|
||||||
<string name="type_of_notifications_title">Chose the type of notifications</string>
|
<string name="type_of_notifications_title">Chose the type of notifications</string>
|
||||||
|
|
Loading…
Reference in a new issue