diff --git a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java index f732a059..90dd682b 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java @@ -30,16 +30,15 @@ import app.fedilab.android.helper.Helper; @SuppressLint("Registered") public class BaseActivity extends CyaneaAppCompatActivity { + static { + Helper.installProvider(); + EmojiManager.install(new EmojiOneProvider()); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Helper.setLocale(this); } - - static { - Helper.installProvider(); - EmojiManager.install(new EmojiOneProvider()); - } - } diff --git a/app/src/main/java/app/fedilab/android/activities/ContextActivity.java b/app/src/main/java/app/fedilab/android/activities/ContextActivity.java index 3b0e5130..5003508b 100644 --- a/app/src/main/java/app/fedilab/android/activities/ContextActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ContextActivity.java @@ -42,10 +42,10 @@ public class ContextActivity extends BaseActivity { public static boolean expand; public static boolean displayCW; + public static Resources.Theme theme; Fragment currentFragment; private Status focusedStatus; private ActivityConversationBinding binding; - public static Resources.Theme theme; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/app/fedilab/android/client/entities/Account.java b/app/src/main/java/app/fedilab/android/client/entities/Account.java index 9e07bd36..b95f17ad 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/Account.java +++ b/app/src/main/java/app/fedilab/android/client/entities/Account.java @@ -93,21 +93,6 @@ public class Account implements Serializable { } } - /** - * Returns all Account in db - * - * @return Account List - */ - public List 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 * @@ -123,6 +108,21 @@ public class Account implements Serializable { } } + /** + * Returns all Account in db + * + * @return Account List + */ + public List 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 * diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 0be4cd01..c8f7251c 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -986,7 +986,13 @@ public class Helper { .setContentIntent(pIntent) .setContentText(message); 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 ledColour = Color.BLUE; break; @@ -1280,6 +1286,32 @@ public class Helper { 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 public enum PatternType { MENTION, @@ -1362,30 +1394,4 @@ public class Helper { }).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()); - - } - } } diff --git a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java index d6046c87..f87b2fe3 100644 --- a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java @@ -28,7 +28,6 @@ import android.os.Handler; import android.os.Looper; import android.text.Html; import android.text.SpannableString; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -69,12 +68,11 @@ public class NotificationsHelper { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(context); String[] slugArray = slug.split("@"); - Log.v(Helper.TAG, "slug: " + slug); Account accountDb = new Account(context).getUniqAccount(slugArray[0], slugArray[1]); if (accountDb == null) { 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 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); @@ -98,11 +96,12 @@ public class NotificationsHelper { try { Response> notificationsResponse = notificationsCall.execute(); if (notificationsResponse.isSuccessful()) { - List notFilteredNotifications = notificationsResponse.body(); - notifications.notifications = TimelineHelper.filterNotification(context.getApplicationContext(), notFilteredNotifications); - for (Notification notification : notifications.notifications) { - if (notification != null) { - notification.status = SpannableHelper.convertStatus(context.getApplicationContext(), notification.status); + notifications.notifications = notificationsResponse.body(); + if (notifications.notifications != null) { + for (Notification notification : notifications.notifications) { + if (notification != null && notification.status != null) { + notification.status = SpannableHelper.convertStatus(context.getApplicationContext(), notification.status); + } } } notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications); @@ -137,7 +136,6 @@ public class NotificationsHelper { public static void onRetrieveNotifications(Context context, Notifications newNotifications, final Account account) { List notificationsReceived = newNotifications.notifications; - if (notificationsReceived == null || notificationsReceived.size() == 0 || account == null) return; 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_fav = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FAVOURITE), 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 notifications = new ArrayList<>(); int pos = 0; for (Notification notif : notificationsReceived) { @@ -309,10 +307,10 @@ public class NotificationsHelper { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { notify_user(context, account, intent, BitmapFactory.decodeResource(context.getResources(), 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) { 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(); } return false; @@ -322,10 +320,10 @@ public class NotificationsHelper { @Override public void onResourceReady(@NonNull Bitmap resource, Transition transition) { 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) { 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(); } } diff --git a/app/src/main/java/app/fedilab/android/helper/PushNotifications.java b/app/src/main/java/app/fedilab/android/helper/PushNotifications.java index e7d40f58..3d4e588f 100644 --- a/app/src/main/java/app/fedilab/android/helper/PushNotifications.java +++ b/app/src/main/java/app/fedilab/android/helper/PushNotifications.java @@ -32,8 +32,10 @@ import java.util.concurrent.TimeUnit; import app.fedilab.android.BaseMainActivity; 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.entities.PushSubscription; +import app.fedilab.android.exception.DBException; import okhttp3.OkHttpClient; import retrofit2.Call; import retrofit2.Response; @@ -76,9 +78,19 @@ public class PushNotifications { MastodonNotificationsService mastodonNotificationsService = init(context, BaseMainActivity.currentInstance); ECDH finalEcdh = ecdh; 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; Call pushSubscriptionCall = mastodonNotificationsService.pushSubscription( - BaseMainActivity.currentToken, + accountDb.token, endpoint, pubKey, auth, diff --git a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java index e3843c1e..aad12090 100644 --- a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java @@ -197,11 +197,6 @@ public class ThemeHelper { viewToShow.startAnimation(animateShow); } - public interface SlideAnimation { - void onAnimationEnded(); - } - - public static List> getContributorsTheme(Context context) { List> linkedHashMaps = new ArrayList<>(); String[] list; @@ -220,7 +215,6 @@ public class ThemeHelper { return linkedHashMaps; } - private static LinkedHashMap readCSVFile(InputStream inputStream) { LinkedHashMap readValues = new LinkedHashMap<>(); if (inputStream != null) { @@ -249,7 +243,6 @@ public class ThemeHelper { return readValues; } - /** * Allow to set colors for tablayout * @@ -282,7 +275,6 @@ public class ThemeHelper { materialButton.setBackgroundTintList(ThemeHelper.getBackgroundButtonColorStateList(context)); } - /** * Allow to set ThumbDrawable colors for SwitchCompat * @@ -372,4 +364,8 @@ public class ThemeHelper { intentBD.putExtras(b); LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBD); } + + public interface SlideAnimation { + void onAnimationEnded(); + } } diff --git a/app/src/main/java/app/fedilab/android/InstancesSocialService.java b/app/src/main/java/app/fedilab/android/interfaces/InstancesSocialService.java similarity index 96% rename from app/src/main/java/app/fedilab/android/InstancesSocialService.java rename to app/src/main/java/app/fedilab/android/interfaces/InstancesSocialService.java index 580bf89a..3fbd1a57 100644 --- a/app/src/main/java/app/fedilab/android/InstancesSocialService.java +++ b/app/src/main/java/app/fedilab/android/interfaces/InstancesSocialService.java @@ -1,4 +1,4 @@ -package app.fedilab.android; +package app.fedilab.android.interfaces; /* Copyright 2021 Thomas Schneider * * This file is a part of Fedilab diff --git a/app/src/main/java/app/fedilab/android/services/CustomReceiver.java b/app/src/main/java/app/fedilab/android/services/CustomReceiver.java index d751fd3e..f87ded11 100644 --- a/app/src/main/java/app/fedilab/android/services/CustomReceiver.java +++ b/app/src/main/java/app/fedilab/android/services/CustomReceiver.java @@ -16,7 +16,6 @@ package app.fedilab.android.services; import android.content.Context; import android.content.Intent; -import android.util.Log; import androidx.annotation.NonNull; @@ -24,7 +23,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.unifiedpush.android.connector.MessagingReceiver; -import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.NotificationsHelper; import app.fedilab.android.helper.PushNotifications; @@ -40,18 +38,14 @@ public class CustomReceiver extends MessagingReceiver { @Override 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 - Log.v(Helper.TAG, "onMessage: " + slug); new Thread(() -> { try { /* ECDH ecdh = ECDH.getInstance(slug); - Log.v(Helper.TAG, "ecdh: " + ecdh); if (ecdh == null) { return; }*/ //String decrypted = ecdh.uncryptMessage(context, String.valueOf(message)); - // Log.v(Helper.TAG, "decrypted: " + decrypted); NotificationsHelper.task(context, slug); - // Log.v(Helper.TAG, "decrypted: " + decrypted); } catch (Exception e) { e.printStackTrace(); } @@ -71,18 +65,15 @@ public class CustomReceiver extends MessagingReceiver { PushNotifications .registerPushNotifications(context, endpoint, slug); } - Log.v(Helper.TAG, "onNewEndpoint: " + slug); } @Override public void onRegistrationFailed(@Nullable Context context, @NotNull String s) { - Log.v(Helper.TAG, "onRegistrationFailed: " + s); } @Override public void onUnregistered(@Nullable Context context, @NotNull String s) { - Log.v(Helper.TAG, "onUnregistered: " + s); } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 7584824d..4c93a79e 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -104,6 +104,7 @@ import es.dmoral.toasty.Toasty; public class ComposeAdapter extends RecyclerView.Adapter { private static final int searchDeep = 15; + private static final int TYPE_COMPOSE = 1; 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", "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 statusList; private final int TYPE_NORMAL = 0; - private static final int TYPE_COMPOSE = 1; private final Account account; public ManageDrafts manageDrafts; List emojis; @@ -134,6 +134,28 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList, ComposeAdapter composeAdapter, String instance, String user_id) { + //Collect all statusCompose + List statusDrafts = new ArrayList<>(); + List 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 public void loadMentions(Status status) { @@ -194,7 +216,6 @@ public class ComposeAdapter extends RecyclerView.Adapter //Put cursor to the end after changing contacts public void putCursor() { statusList.get(statusList.size() - 1).setCursorToEnd = true; notifyItemChanged(statusList.size() - 1); } - //------- end contact -----> private void displayAttachments(ComposeViewHolder holder, int position, int scrollToMediaPosition) { if (statusList.size() > position && statusList.get(position).media_attachments != null) { @@ -567,7 +588,6 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList, ComposeAdapter composeAdapter, String instance, String user_id) { - //Collect all statusCompose - List statusDrafts = new ArrayList<>(); - List 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") @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 26ad63f7..f31e5e8c 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -257,7 +257,6 @@ public class StatusAdapter extends RecyclerView.Adapter } - if (truncate_toots_size > 0) { holder.binding.statusContent.setMaxLines(truncate_toots_size); holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java index 44689444..2c39513b 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java @@ -112,8 +112,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements } - - @SuppressWarnings("deprecation") @SuppressLint("ApplySharedPref") @Override diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/InstanceSocialVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/InstanceSocialVM.java index db6b0262..72035998 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/InstanceSocialVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/InstanceSocialVM.java @@ -25,9 +25,9 @@ import androidx.lifecycle.MutableLiveData; import java.io.IOException; import java.util.concurrent.TimeUnit; -import app.fedilab.android.InstancesSocialService; import app.fedilab.android.client.entities.InstanceSocial; import app.fedilab.android.helper.Helper; +import app.fedilab.android.interfaces.InstancesSocialService; import okhttp3.OkHttpClient; import retrofit2.Call; import retrofit2.Response; diff --git a/app/src/main/res/layout/activity_conversation.xml b/app/src/main/res/layout/activity_conversation.xml index d91e5c58..7713c258 100644 --- a/app/src/main/res/layout/activity_conversation.xml +++ b/app/src/main/res/layout/activity_conversation.xml @@ -27,19 +27,21 @@ + tools:context=".activities.ContextActivity"> + + android:layout_height="wrap_content"> + + . --> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ddffcfd..e092c436 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1562,7 +1562,7 @@ REPLACE_WIKIPEDIA REPLACE_WIKIPEDIA_HOST wikiless.org - LAST_NOTIFICATION_MAX_ID + LAST_NOTIFICATION_ID Type of notifications Alternative frontends Chose the type of notifications