summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java1008
1 files changed, 782 insertions, 226 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
index a769721f9..1f3ff8c8e 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
@@ -19,27 +19,10 @@ package fr.gouv.etalab.mastodon.helper;
import android.annotation.SuppressLint;
import android.app.Activity;
+import android.app.DownloadManager;
+import android.app.FragmentManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
-import android.database.Cursor;
-import android.graphics.BitmapFactory;
-import android.graphics.Color;
-import android.graphics.Matrix;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.media.AudioAttributes;
-import android.os.CountDownTimer;
-import android.provider.MediaStore;
-import android.provider.OpenableColumns;
-import android.support.annotation.Nullable;
-import android.support.customtabs.CustomTabsIntent;
-import android.support.design.widget.TabLayout;
-import android.support.media.ExifInterface;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.graphics.drawable.DrawableCompat;
-import android.support.v7.app.AlertDialog;
-import android.app.DownloadManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
@@ -47,13 +30,22 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
+import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -61,26 +53,41 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.os.CountDownTimer;
import android.os.Environment;
+import android.provider.MediaStore;
+import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.customtabs.CustomTabsIntent;
import android.support.design.widget.NavigationView;
+import android.support.design.widget.TabLayout;
+import android.support.media.ExifInterface;
+import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.content.ContextCompat;
+import android.support.v4.graphics.drawable.DrawableCompat;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.view.menu.ActionMenuItemView;
+import android.support.v7.widget.ActionMenuView;
+import android.support.v7.widget.Toolbar;
import android.text.Html;
-import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
-import android.text.style.ImageSpan;
+import android.text.style.URLSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.MimeTypeMap;
@@ -105,6 +112,9 @@ import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
+import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
+import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
+import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;
import org.conscrypt.Conscrypt;
@@ -139,32 +149,34 @@ import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.BuildConfig;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
-import fr.gouv.etalab.mastodon.activities.InstanceFederatedActivity;
import fr.gouv.etalab.mastodon.activities.LoginActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Application;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
+import fr.gouv.etalab.mastodon.client.Entities.Card;
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
+import fr.gouv.etalab.mastodon.client.Entities.Filters;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
-import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.Tag;
import fr.gouv.etalab.mastodon.client.Entities.Version;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
-import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import static android.content.Context.DOWNLOAD_SERVICE;
+import static fr.gouv.etalab.mastodon.activities.BaseMainActivity.filters;
/**
@@ -223,6 +235,7 @@ public class Helper {
public static final String LAST_LIST = "last_list";
public static final String LAST_LIST_NAME = "last_list_name";
+
//Notifications
public static final int NOTIFICATION_INTENT = 1;
public static final int HOME_TIMELINE_INTENT = 2;
@@ -262,6 +275,14 @@ public class Helper {
public static final String SET_COMPACT_MODE = "set_compact_mode";
public static final String SET_SHARE_DETAILS = "set_share_details";
public static final String SET_NOTIF_SOUND = "set_notif_sound";
+ public static final String SET_ENABLE_TIME_SLOT = "set_enable_time_slot";
+ public static final String SET_KEEP_BACKGROUND_PROCESS = "set_keep_background_process";
+ public static final String SET_DISPLAY_EMOJI = "set_display_emoji";
+ public static final String SET_DISPLAY_CARD = "set_display_card";
+ public static final String SET_DISPLAY_VIDEO_PREVIEWS= "set_display_video_previews";
+ public static final String SET_OLD_DIRECT_TIMELINE = "sset_old_direct_timeline";
+ public static final String SET_BATTERY_PROFILE = "set_battery_profile";
+ public static final String SET_DEFAULT_LOCALE = "set_default_locale";
public static final int S_512KO = 1;
public static final int S_1MO = 2;
public static final int S_2MO = 3;
@@ -269,6 +290,10 @@ public class Helper {
public static final int ATTACHMENT_WIFI = 2;
public static final int ATTACHMENT_ASK = 3;
+ public static final int BATTERY_PROFILE_NORMAL = 1;
+ public static final int BATTERY_PROFILE_MEDIUM = 2;
+ public static final int BATTERY_PROFILE_LOW = 3;
+
public static final int THEME_LIGHT = 1;
public static final int THEME_DARK = 2;
public static final int THEME_BLACK = 3;
@@ -308,10 +333,12 @@ public class Helper {
public static final String SET_COOKIES = "set_cookies";
public static final String SET_FOLDER_RECORD = "set_folder_record";
public static final String SET_TOOT_VISIBILITY = "set_toot_visibility";
+ public static final String SET_DISPLAY_DIRECT = "set_display_direct";
public static final String SET_DISPLAY_LOCAL = "set_display_local";
public static final String SET_DISPLAY_GLOBAL = "set_display_global";
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots";
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size";
+ public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size";
//End points
public static final String EP_AUTHORIZE = "/oauth/authorize";
@@ -358,7 +385,7 @@ public class Helper {
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
- public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_À-ú-]+)");
+ public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
private static final Pattern mentionPattern = Pattern.compile("(@[\\w]+)");
@@ -379,7 +406,6 @@ public class Helper {
STORE,
TOOT
}
- private static boolean isPerformingSearch = false;
/**
* Converts emojis in input to unicode
@@ -439,7 +465,6 @@ public class Helper {
* Check if the user is connected to Internet
* @return boolean
*/
- @SuppressWarnings("unused")
public static boolean isConnectedToInternet(Context context, String instance) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if( cm == null)
@@ -637,7 +662,11 @@ public class Helper {
public static String dateDiffFull(Date dateToot){
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault());
- return df.format(dateToot);
+ try {
+ return df.format(dateToot);
+ }catch (Exception e){
+ return "";
+ }
}
/***
@@ -722,13 +751,15 @@ public class Helper {
message = context.getString(R.string.toast_show_boost);
}else if(statusAction == API.StatusAction.HIDE_BOOST){
message = context.getString(R.string.toast_hide_boost);
+ }else if(statusAction == API.StatusAction.BLOCK_DOMAIN){
+ message = context.getString(R.string.toast_block_domain);
}
}else {
message = context.getString(R.string.toast_error);
}
if( !message.trim().equals(""))
- Toast.makeText(context, message, Toast.LENGTH_LONG).show();
+ Toasty.success(context, message, Toast.LENGTH_LONG).show();
}
@@ -742,13 +773,22 @@ public class Helper {
* @param url String download url
*/
public static void manageDownloads(final Context context, final String url){
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ int style;
+ if (theme == Helper.THEME_DARK) {
+ style = R.style.DialogDark;
+ } else if (theme == Helper.THEME_BLACK){
+ style = R.style.DialogBlack;
+ }else {
+ style = R.style.Dialog;
+ }
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
final DownloadManager.Request request;
try {
request = new DownloadManager.Request(Uri.parse(url.trim()));
}catch (Exception e){
- Toast.makeText(context,R.string.toast_error,Toast.LENGTH_LONG).show();
+ Toasty.error(context,context.getString(R.string.toast_error),Toast.LENGTH_LONG).show();
return;
}
final String fileName = URLUtil.guessFileName(url, null, null);
@@ -838,19 +878,6 @@ public class Helper {
channelId = "channel_boost";
channelTitle = context.getString(R.string.channel_notif_boost);
}
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_HIGH);
- NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .setUsage(AudioAttributes.USAGE_ALARM)
- .build();
- assert mNotificationManager != null;
- String soundUri =sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
- channel.setSound(Uri.parse(soundUri), audioAttributes);
- mNotificationManager.createNotificationChannel(channel);
- }
-
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.notification_icon)
.setTicker(message)
@@ -858,15 +885,7 @@ public class Helper {
.setAutoCancel(true)
.setContentIntent(pIntent)
.setContentText(message);
- if( sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT,false) ) {
- notificationBuilder.setVibrate(new long[] { 500, 500, 500});
- }else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
- String soundUri =sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
- notificationBuilder.setSound(Uri.parse(soundUri));
- }
-
int ledColour = Color.BLUE;
-
switch (sharedpreferences.getInt(Helper.SET_LED_COLOUR, Helper.LED_COLOUR)) {
case 0: // BLUE
ledColour = Color.BLUE;
@@ -891,7 +910,36 @@ public class Helper {
break;
}
- notificationBuilder.setLights(ledColour, 500, 1000);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel channel;
+ NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ if( sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT,false) ) {
+ channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_LOW);
+ channel.setSound(null, null);
+ channel.setVibrationPattern(new long[] { 500, 500, 500});
+ channel.enableVibration(true);
+ channel.setLightColor(ledColour);
+ }else {
+ channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_HIGH);
+ String soundUri = sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
+ AudioAttributes audioAttributes = new AudioAttributes.Builder()
+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION)
+ .build();
+ channel.setSound(Uri.parse(soundUri), audioAttributes);
+ }
+ assert mNotificationManager != null;
+ mNotificationManager.createNotificationChannel(channel);
+ }else{
+ if( sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT,false) ) {
+ notificationBuilder.setVibrate(new long[] { 500, 500, 500});
+ }else {
+ String soundUri =sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
+ notificationBuilder.setSound(Uri.parse(soundUri));
+ }
+ notificationBuilder.setLights(ledColour, 500, 1000);
+ }
notificationBuilder.setContentTitle(title);
notificationBuilder.setLargeIcon(icon);
notificationManager.notify(notificationId, notificationBuilder.build());
@@ -951,7 +999,7 @@ public class Helper {
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
notify_user(context, intent, notificationIdTmp, BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher), NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
- Toast.makeText(context, R.string.toast_saved,Toast.LENGTH_LONG).show();
+ Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
return false;
}
})
@@ -959,7 +1007,7 @@ public class Helper {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
notify_user(context, intent, notificationIdTmp, resource, NotifType.STORE, context.getString(R.string.save_over), context.getString(R.string.download_from, fileName));
- Toast.makeText(context, R.string.toast_saved,Toast.LENGTH_LONG).show();
+ Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show();
}
});
} catch (Exception ignored) {}
@@ -1104,7 +1152,7 @@ public class Helper {
if( ! activity.isFinishing() ) {
menuAccountsOpened = false;
String userId = account.getId();
- Toast.makeText(activity, activity.getString(R.string.toast_account_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_LONG).show();
+ Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_LONG).show();
changeUser(activity, userId, true);
arrow.setImageResource(R.drawable.ic_arrow_drop_down);
return true;
@@ -1117,7 +1165,17 @@ public class Helper {
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- new AlertDialog.Builder(activity)
+ final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ int style;
+ if (theme == Helper.THEME_DARK) {
+ style = R.style.DialogDark;
+ } else if (theme == Helper.THEME_BLACK){
+ style = R.style.DialogBlack;
+ }else {
+ style = R.style.Dialog;
+ }
+ new AlertDialog.Builder(activity, style)
.setTitle(activity.getString(R.string.delete_account_title))
.setMessage(activity.getString(R.string.delete_account_message, "@" + account.getAcct() + "@" + account.getInstance()))
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@@ -1185,17 +1243,25 @@ public class Helper {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
}
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
+ if( !account.getToken().equals(token)){
+ FragmentManager fm = activity.getFragmentManager();
+ for(int i = 0; i < fm.getBackStackEntryCount(); ++i) {
+ fm.popBackStack();
+ }
+ }
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim());
- editor.apply();
+ editor.commit();
activity.recreate();
if( checkItem ) {
Intent intent = new Intent(activity, MainActivity.class);
intent.putExtra(INTENT_ACTION, CHANGE_USER_INTENT);
activity.startActivity(intent);
}
+
}
@@ -1222,17 +1288,7 @@ public class Helper {
if( url.startsWith("/") ){
url = Helper.getLiveInstanceWithProtocol(activity) + url;
}
-
- Glide.with(activity.getApplicationContext())
- .asBitmap()
- .load(url)
- .into(new SimpleTarget<Bitmap>() {
- @Override
- public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
- Resources res = activity.getResources();
- imageView.setImageBitmap(resource);
- }
- });
+ loadGiF(activity,url, imageView);
}
@@ -1243,6 +1299,8 @@ public class Helper {
cw_mention = String.format("@%s %s",mention.getUsername(),cw_mention);
}
SpannableString spannableString = new SpannableString(cw_mention);
+ final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
for (final Mention mention : mentions) {
String targetedAccount = "@" + mention.getUsername();
if (spannableString.toString().contains(targetedAccount)) {
@@ -1262,6 +1320,13 @@ public class Helper {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
+ ds.setUnderlineText(false);
+ if (theme == THEME_DARK)
+ ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
+ else if (theme == THEME_BLACK)
+ ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
+ else if (theme == THEME_LIGHT)
+ ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
startPosition, endPosition,
@@ -1279,37 +1344,175 @@ public class Helper {
* @param account Account - new account in use
* @param headerLayout View - the menu header
*/
- public static void updateHeaderAccountInfo(final Activity activity, final Account account, final View headerLayout){
+ public static void updateHeaderAccountInfo(Activity activity, final Account account, final View headerLayout){
ImageView profilePicture = headerLayout.findViewById(R.id.profilePicture);
-
TextView username = headerLayout.findViewById(R.id.username);
TextView displayedName = headerLayout.findViewById(R.id.displayedName);
+ LinearLayout more_option_container = headerLayout.findViewById(R.id.more_option_container);
+ SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ ImageView icon = new ImageView(activity);
+
+
+ FloatingActionButton.LayoutParams layoutparmans = new FloatingActionButton.LayoutParams((int)Helper.convertDpToPixel(35,activity),(int)Helper.convertDpToPixel(35,activity));
+ FloatingActionButton.LayoutParams layoutparmanImg = new FloatingActionButton.LayoutParams((int)Helper.convertDpToPixel(25,activity),(int)Helper.convertDpToPixel(25,activity));
+ layoutparmans.setMargins((int)Helper.convertDpToPixel(20, activity),0,0,0);
+ MenuFloating actionButton = null;
+ if( theme == THEME_LIGHT) {
+ icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
+ actionButton = new MenuFloating.Builder(activity)
+ .setContentView(icon, layoutparmanImg)
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular))
+ .setLayoutParams(layoutparmans)
+ .setTag("THEME")
+ .intoView(more_option_container)
+ .build();
+ }else if( theme == THEME_DARK) {
+ icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
+ actionButton = new MenuFloating.Builder(activity)
+ .setContentView(icon, layoutparmanImg)
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_dark))
+ .setLayoutParams(layoutparmans)
+ .setTag("THEME")
+ .intoView(more_option_container)
+ .build();
+ }else if( theme == THEME_BLACK) {
+ icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
+ actionButton = new MenuFloating.Builder(activity)
+ .setContentView(icon, layoutparmanImg)
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_black))
+ .setLayoutParams(layoutparmans)
+ .setTag("THEME")
+ .intoView(more_option_container)
+ .build();
+ }
+
+
+ SubActionButton.Builder itemBuilder = new SubActionButton.Builder(activity);
+
+ // repeat many times:
+ ImageView itemIconLight = new ImageView(activity);
+ itemIconLight.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
+ SubActionButton buttonLight = itemBuilder
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular))
+ .setContentView(itemIconLight).build();
+
+
+ ImageView itemDark = new ImageView(activity);
+ itemDark.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
+ SubActionButton buttonDark = itemBuilder
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_dark))
+ .setContentView(itemDark).build();
+
+ ImageView itemBlack = new ImageView(activity);
+ itemBlack.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
+ SubActionButton buttonBlack = itemBuilder
+ .setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_black))
+ .setContentView(itemBlack).build();
+
+ FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(activity)
+ .addSubActionView(buttonLight)
+ .addSubActionView(buttonDark)
+ .addSubActionView(buttonBlack)
+ .attachTo(actionButton)
+ .setStartAngle(0)
+ .setEndAngle(90)
+ .build();
+
+ if( actionButton != null) {
+ actionButton.setFocusableInTouchMode(true);
+ actionButton.setFocusable(true);
+ actionButton.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ if(actionMenu.isOpen())
+ actionMenu.close(true);
+ else
+ actionMenu.open(true);
+ return false;
+ }
+ });
+ actionButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ try {
+ actionMenu.close(true);
+ }catch (Exception ignored){}
+
+ }
+ });
+ }
+ buttonLight.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ actionMenu.close(true);
+ SharedPreferences.Editor editor = sharedpreferences.edit();
+ editor.putInt(Helper.SET_THEME, Helper.THEME_LIGHT);
+ editor.apply();
+ activity.recreate();
+ Intent intent = new Intent(activity, MainActivity.class);
+ activity.finish();
+ activity.startActivity(intent);
+ }
+ });
+ buttonDark.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ actionMenu.close(true);
+ SharedPreferences.Editor editor = sharedpreferences.edit();
+ editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
+ editor.apply();
+ activity.recreate();
+ Intent intent = new Intent(activity, MainActivity.class);
+ activity.finish();
+ activity.startActivity(intent);
+ }
+ });
+ buttonBlack.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ actionMenu.close(true);
+ SharedPreferences.Editor editor = sharedpreferences.edit();
+ editor.putInt(Helper.SET_THEME, Helper.THEME_BLACK);
+ editor.apply();
+ activity.recreate();
+ Intent intent = new Intent(activity, MainActivity.class);
+ activity.finish();
+ activity.startActivity(intent);
+ }
+ });
+
if( account == null ) {
Helper.logout(activity);
Intent myIntent = new Intent(activity, LoginActivity.class);
- Toast.makeText(activity,R.string.toast_error, Toast.LENGTH_LONG).show();
+ Toasty.error(activity,activity.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
activity.startActivity(myIntent);
activity.finish(); //User is logged out to get a new token
}else {
- account.makeEmojisAccount(activity, ((BaseMainActivity)activity));
+ account.makeEmojisAccount(activity, ((BaseMainActivity)activity), account);
username.setText(String.format("@%s",account.getUsername() + "@" + account.getInstance()));
displayedName.setText(account.getdisplayNameSpan(), TextView.BufferType.SPANNABLE);
String url = account.getAvatar();
if( url.startsWith("/") ){
url = Helper.getLiveInstanceWithProtocol(activity) + account.getAvatar();
}
- Glide.with(activity.getApplicationContext())
- .load(url)
- .into(profilePicture);
+ loadGiF(activity, url, profilePicture);
String urlHeader = account.getHeader();
if( urlHeader.startsWith("/") ){
urlHeader = Helper.getLiveInstanceWithProtocol(activity) + account.getHeader();
}
- LinearLayout main_header_container = headerLayout.findViewById(R.id.main_header_container);
- final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
- if( theme == Helper.THEME_LIGHT){
- main_header_container.setBackgroundDrawable( activity.getResources().getDrawable(R.drawable.side_nav_bar_dark));
+ ImageView owner_accounts = headerLayout.findViewById(R.id.owner_accounts);
+ ImageView header_option_info = headerLayout.findViewById(R.id.header_option_info);
+ ImageView header_option_menu = headerLayout.findViewById(R.id.header_option_menu);
+ if( theme == Helper.THEME_DARK || theme == Helper.THEME_BLACK){
+ changeDrawableColor(activity, owner_accounts,R.color.dark_text);
+ changeDrawableColor(activity, header_option_info,R.color.dark_text);
+ changeDrawableColor(activity, header_option_menu,R.color.dark_text);
+ }else {
+ changeDrawableColor(activity, owner_accounts,R.color.light_black);
+ changeDrawableColor(activity, header_option_info,R.color.light_black);
+ changeDrawableColor(activity, header_option_menu,R.color.light_black);
}
if (!urlHeader.contains("missing.png")) {
Glide.with(activity.getApplicationContext())
@@ -1320,11 +1523,20 @@ public class Helper {
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image);
backgroundImage.setImageBitmap(resource);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- backgroundImage.setImageAlpha(60);
- }else {
- backgroundImage.setAlpha(60);
+ if( theme == THEME_LIGHT){
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ backgroundImage.setImageAlpha(80);
+ }else {
+ backgroundImage.setAlpha(80);
+ }
+ }else{
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ backgroundImage.setImageAlpha(60);
+ }else {
+ backgroundImage.setAlpha(60);
+ }
}
+
}
});
}
@@ -1371,9 +1583,11 @@ public class Helper {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
- boolean success = deleteDir(new File(dir, aChildren));
- if (!success) {
- return false;
+ if (!aChildren.equals("databases") && !aChildren.equals("shared_prefs")) {
+ boolean success = deleteDir(new File(dir, aChildren));
+ if (!success) {
+ return false;
+ }
}
}
return dir.delete();
@@ -1393,27 +1607,44 @@ public class Helper {
* @param fullContent String, should be the st
* @return TextView
*/
- public static SpannableString clickableElementsDescription(final Context context, String fullContent, List<Emojis> emojis) {
+ public static SpannableString clickableElementsDescription(final Context context, String fullContent) {
+
SpannableString spannableString;
fullContent = Helper.shortnameToUnicode(fullContent, true);
+ SpannableString spannableStringT = new SpannableString(fullContent);
+ Pattern aLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
+ Matcher matcherALink = aLink.matcher(spannableStringT.toString());
+ ArrayList<Account> accountsMentionUnknown = new ArrayList<>();
+ while (matcherALink.find()){
+ String acct = matcherALink.group(3).replace("@","");
+ String instance = matcherALink.group(2);
+ Account account = new Account();
+ account.setAcct(acct);
+ account.setInstance(instance);
+ accountsMentionUnknown.add(account);
+ }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_LEGACY));
+ spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>",""), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
- spannableString = new SpannableString(Html.fromHtml(fullContent));
+ spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>","")));
+
+ URLSpan[] urls = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
+ for(URLSpan span : urls)
+ spannableString.removeSpan(span);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
- boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
- if( embedded_browser){
- Matcher matcher;
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
- matcher = Patterns.WEB_URL.matcher(spannableString);
- else
- matcher = urlPattern.matcher(spannableString);
- while (matcher.find()){
- int matchStart = matcher.start(1);
- int matchEnd = matcher.end();
- final String url = spannableString.toString().substring(matchStart, matchEnd);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ Matcher matcher;
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
+ matcher = Patterns.WEB_URL.matcher(spannableString);
+ else
+ matcher = urlPattern.matcher(spannableString);
+ while (matcher.find()){
+ int matchStart = matcher.start(1);
+ int matchEnd = matcher.end();
+ final String url = spannableString.toString().substring(matchS