This commit is contained in:
Thomas 2022-04-27 18:15:32 +02:00
parent 0f855c5ac2
commit 4767712fb0
16 changed files with 116 additions and 118 deletions

View file

@ -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());
}
}

View file

@ -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) {

View file

@ -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
*
@ -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
*

View file

@ -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());
}
}
}

View file

@ -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,13 +96,14 @@ public class NotificationsHelper {
try {
Response<List<Notification>> notificationsResponse = notificationsCall.execute();
if (notificationsResponse.isSuccessful()) {
List<Notification> notFilteredNotifications = notificationsResponse.body();
notifications.notifications = TimelineHelper.filterNotification(context.getApplicationContext(), notFilteredNotifications);
notifications.notifications = notificationsResponse.body();
if (notifications.notifications != null) {
for (Notification notification : notifications.notifications) {
if (notification != null) {
if (notification != null && notification.status != null) {
notification.status = SpannableHelper.convertStatus(context.getApplicationContext(), notification.status);
}
}
}
notifications.pagination = MastodonHelper.getPaginationNotification(notifications.notifications);
}
} catch (IOException e) {
@ -137,7 +136,6 @@ public class NotificationsHelper {
public static void onRetrieveNotifications(Context context, Notifications newNotifications, final Account account) {
List<Notification> 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<Notification> 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<? super Bitmap> 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();
}
}

View file

@ -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<PushSubscription> pushSubscriptionCall = mastodonNotificationsService.pushSubscription(
BaseMainActivity.currentToken,
accountDb.token,
endpoint,
pubKey,
auth,

View file

@ -197,11 +197,6 @@ public class ThemeHelper {
viewToShow.startAnimation(animateShow);
}
public interface SlideAnimation {
void onAnimationEnded();
}
public static List<LinkedHashMap<String, String>> getContributorsTheme(Context context) {
List<LinkedHashMap<String, String>> linkedHashMaps = new ArrayList<>();
String[] list;
@ -220,7 +215,6 @@ public class ThemeHelper {
return linkedHashMaps;
}
private static LinkedHashMap<String, String> readCSVFile(InputStream inputStream) {
LinkedHashMap<String, String> 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();
}
}

View file

@ -1,4 +1,4 @@
package app.fedilab.android;
package app.fedilab.android.interfaces;
/* Copyright 2021 Thomas Schneider
*
* This file is a part of Fedilab

View file

@ -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);
}
}

View file

@ -104,6 +104,7 @@ import es.dmoral.toasty.Toasty;
public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder
"..--..", ".-.-.-", ".----.",};
private final List<Status> statusList;
private final int TYPE_NORMAL = 0;
private static final int TYPE_COMPOSE = 1;
private final Account account;
public ManageDrafts manageDrafts;
List<Emoji> emojis;
@ -134,6 +134,28 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
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
public void loadMentions(Status status) {
@ -194,7 +216,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
}
public void setStatusCount(int count) {
statusCount = count;
}
@ -366,13 +387,13 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
notifyItemChanged(statusList.size() - 1);
}
//------- end contact ----->
//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<RecyclerView.ViewHolder
return statusList.size();
}
/**
* Initialize text watcher for content writing
* 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;
}
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")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {

View file

@ -257,7 +257,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
if (truncate_toots_size > 0) {
holder.binding.statusContent.setMaxLines(truncate_toots_size);
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);

View file

@ -112,8 +112,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
}
@SuppressWarnings("deprecation")
@SuppressLint("ApplySharedPref")
@Override

View file

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

View file

@ -27,19 +27,21 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".activities.ContextActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:background="@color/cyanea_primary_reference"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/profile_picture"
android:layout_width="30dp"

View file

@ -15,7 +15,7 @@
see <http://www.gnu.org/licenses>.
-->
<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_height="match_parent">

View file

@ -1562,7 +1562,7 @@
<string name="REPLACE_WIKIPEDIA" translatable="false">REPLACE_WIKIPEDIA</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="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="alternative_frontends">Alternative frontends</string>
<string name="type_of_notifications_title">Chose the type of notifications</string>