diff options
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.java | 293 |
1 files changed, 224 insertions, 69 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 8c6ff5c07..8f8acc335 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 @@ -194,13 +194,15 @@ public class Helper { @SuppressWarnings({"unused", "WeakerAccess"}) public static final String TAG = "mastodon_etalab"; - public static final String CLIENT_NAME_VALUE = "Mastalab"; + public static final String CLIENT_NAME_VALUE = "Fedilab"; public static final String OAUTH_SCOPES = "read write follow"; public static final String OAUTH_SCOPES_PEERTUBE = "user"; public static final String PREF_KEY_OAUTH_TOKEN = "oauth_token"; public static final String PREF_KEY_ID = "userID"; + public static final String PREF_IS_MODERATOR = "is_moderator"; + public static final String PREF_IS_ADMINISTRATOR = "is_administrator"; public static final String PREF_INSTANCE = "instance"; public static final String REDIRECT_CONTENT = "urn:ietf:wg:oauth:2.0:oob"; public static final String REDIRECT_CONTENT_WEB = "mastalab://backtomastalab"; @@ -223,12 +225,14 @@ public class Helper { public static final String SCOPE = "scope"; public static final String SCOPES = "scopes"; public static final String WEBSITE = "website"; - public static final String WEBSITE_VALUE = "https://mastalab.app"; + public static final String WEBSITE_VALUE = "https://fedilab.app"; public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message"; public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id"; public static final String LAST_HOMETIMELINE_MAX_ID = "last_hometimeline_max_id"; public static final String BOOKMARK_ID = "bookmark_id"; + public static final String BOOKMARK_DATE = "bookmark_date"; public static final String LAST_READ_TOOT_ID = "last_read_toot_id"; + public static final String LAST_READ_TOOT_DATE = "last_read_toot_date"; public static final String LAST_HOMETIMELINE_NOTIFICATION_MAX_ID = "last_hometimeline_notification_max_id"; public static final String SHOULD_CONTINUE_STREAMING = "should_continue_streaming"; public static final String SHOULD_CONTINUE_STREAMING_HOME = "should_continue_streaming_home"; @@ -282,6 +286,7 @@ public class Helper { public static final String SET_SHOW_BOOKMARK = "set_show_bookmark"; public static final String SET_FULL_PREVIEW = "set_full_preview"; public static final String SET_COMPACT_MODE = "set_compact_mode"; + public static final String SET_CONSOLE_MODE = "set_console_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"; @@ -293,7 +298,9 @@ public class Helper { public static final String SET_BATTERY_PROFILE = "set_battery_profile"; public static final String SET_DEFAULT_LOCALE_NEW = "set_default_locale_new"; public static final String SET_NOTIFICATION_ACTION = "set_notification_action"; - public static final int S_512KO = 1; + public static final String SET_DISPLAY_CONTENT_AFTER_FM = "set_display_content_after_fm"; + public static final int S_NO = 0; + static final int S_512KO = 1; public static final int S_1MO = 2; public static final int S_2MO = 3; public static final int ATTACHMENT_ALWAYS = 1; @@ -360,7 +367,7 @@ public class Helper { 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"; public static final String SET_ART_WITH_NSFW = "set_art_with_nsfw"; - + public static final String SET_OPTIMIZE_LOADING = "set_optimize_loading"; //End points public static final String EP_AUTHORIZE = "/oauth/authorize"; @@ -530,11 +537,54 @@ public class Helper { editor.putString(Helper.CLIENT_ID, null); editor.putString(Helper.CLIENT_SECRET, null); editor.putString(Helper.PREF_KEY_ID, null); + editor.putBoolean(Helper.PREF_IS_MODERATOR, false); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false); editor.putString(Helper.PREF_INSTANCE, null); editor.putString(Helper.ID, null); editor.apply(); } + /** + * Log out the authenticated user by removing its token + * @param activity Activity + */ + public static void logoutCurrentUser(Activity activity) { + SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + //Current user + + SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(activity)); + Account account = new AccountDAO(activity, db).getUniqAccount(userId, instance); + account.setToken("null"); + new AccountDAO(activity, db).updateAccount(account); + Account newAccount = new AccountDAO(activity, db).getLastUsedAccount(); + SharedPreferences.Editor editor = sharedpreferences.edit(); + if( newAccount == null){ + editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, null); + editor.putString(Helper.CLIENT_ID, null); + editor.putString(Helper.CLIENT_SECRET, null); + editor.putString(Helper.PREF_KEY_ID, null); + editor.putBoolean(Helper.PREF_IS_MODERATOR, false); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false); + editor.putString(Helper.PREF_INSTANCE, null); + editor.putString(Helper.ID, null); + editor.apply(); + }else{ + editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, newAccount.getToken()); + editor.putString(Helper.PREF_KEY_ID, newAccount.getId()); + editor.putString(Helper.PREF_INSTANCE, newAccount.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, newAccount.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, newAccount.isAdmin()); + editor.commit(); + Intent changeAccount = new Intent(activity, MainActivity.class); + changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.finish(); + activity.startActivity(changeAccount); + } + + } + /** * Convert String date from Mastodon @@ -544,20 +594,26 @@ public class Helper { */ public static Date mstStringToDate(Context context, String date) throws ParseException { Locale userLocale; + if (date == null ) + return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { userLocale = context.getResources().getConfiguration().getLocales().get(0); } else { //noinspection deprecation userLocale = context.getResources().getConfiguration().locale; } - final String STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + String STRING_DATE_FORMAT; + if( !date.contains("+")) + STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + else //GNU date format + STRING_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setLenient(true); try { return simpleDateFormat.parse(date); }catch (Exception e){ - String newdate = date.split("\\+")[0]; + String newdate = date.split("\\+")[0].trim(); simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", userLocale); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); simpleDateFormat.setLenient(true); @@ -565,6 +621,29 @@ public class Helper { } } + /** + * Convert String date from Mastodon + * @param context Context + * @param date String + * @return Date + */ + public static Date opencollectivetStringToDate(Context context, String date) throws ParseException { + Locale userLocale; + if (date == null ) + return null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + userLocale = context.getResources().getConfiguration().getLocales().get(0); + } else { + //noinspection deprecation + userLocale = context.getResources().getConfiguration().locale; + } + String STRING_DATE_FORMAT; + STRING_DATE_FORMAT = "yyyy-MM-dd HH:mm"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); + simpleDateFormat.setLenient(true); + return simpleDateFormat.parse(date); + } /** * Convert a date in String -> format yyyy-MM-dd HH:mm:ss @@ -913,7 +992,7 @@ public class Helper { channelTitle = context.getString(R.string.channel_notif_boost); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId) - .setSmallIcon(R.drawable.notification_icon) + .setSmallIcon(R.drawable.fedilab_notification_icon) .setTicker(message) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) @@ -985,9 +1064,10 @@ public class Helper { * @param context Context * @param url String download url */ - public static void manageMoveFileDownload(final Context context, final String preview_url, final String url, Bitmap bitmap, File fileVideo){ + public static void manageMoveFileDownload(final Context context, final String preview_url, final String url, Bitmap bitmap, File fileVideo, boolean isSharing){ - final String fileName = URLUtil.guessFileName(url, null, null);final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + final String fileName = URLUtil.guessFileName(url, null, null); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); String myDir = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()); String mime = getMimeType(url); try { @@ -1022,31 +1102,42 @@ public class Helper { Uri uri = Uri.parse("file://" + file.getAbsolutePath()); intent.setDataAndType(uri, getMimeType(url)); - Glide.with(context) - .asBitmap() - .load(preview_url) - .listener(new RequestListener<Bitmap>(){ + if( !isSharing) + Glide.with(context) + .asBitmap() + .load(preview_url) + .listener(new RequestListener<Bitmap>(){ - @Override - public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { - return false; - } + @Override + public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { + return false; + } - @Override - 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)); - Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); - return false; - } - }) - .into(new SimpleTarget<Bitmap>() { - @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)); - Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); - } - }); + @Override + 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)); + Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); + return false; + } + }) + .into(new SimpleTarget<Bitmap>() { + @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)); + Toasty.success(context, context.getString(R.string.toast_saved),Toast.LENGTH_LONG).show(); + } + }); + else { + Intent shareIntent = new Intent(Intent.ACTION_SEND); + if( bitmap != null) + shareIntent.setType("image/*"); + else + shareIntent.setType("video/*"); + shareIntent.putExtra(Intent.EXTRA_STREAM, uri); + shareIntent.putExtra(Intent.EXTRA_TEXT, R.string.share_with); + context.startActivity(shareIntent); + } } catch (Exception ignored) {} } @@ -1282,13 +1373,41 @@ public class Helper { MenuItem itemPCom = menu.findItem(R.id.nav_peertube_comm); if( itemPCom != null) itemPCom.setVisible(false); - }else if( BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON){ + }else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){ MenuItem itemCom = menu.findItem(R.id.nav_peertube_comm); if( itemCom != null) itemCom.setVisible(false); MenuItem itemPFCom = menu.findItem(R.id.nav_pixelfed_comm); if( itemPFCom != null) itemPFCom.setVisible(false); + + if( BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ + MenuItem nav_list = menu.findItem(R.id.nav_list); + if( nav_list != null) + nav_list.setVisible(false); + MenuItem nav_peertube = menu.findItem(R.id.nav_peertube); + if( nav_peertube != null) + nav_peertube.setVisible(false); + MenuItem nav_filters = menu.findItem(R.id.nav_filters); + if( nav_filters != null) + nav_filters.setVisible(false); + MenuItem nav_follow_request = menu.findItem(R.id.nav_follow_request); + if( nav_follow_request != null) + nav_follow_request.setVisible(false); + MenuItem nav_who_to_follow = menu.findItem(R.id.nav_who_to_follow); + if( nav_who_to_follow != null) + nav_who_to_follow.setVisible(false); + MenuItem nav_blocked = menu.findItem(R.id.nav_blocked); + if( nav_blocked != null) + nav_blocked.setVisible(false); + MenuItem nav_muted = menu.findItem(R.id.nav_muted); + if( nav_muted != null) + nav_muted.setVisible(false); + MenuItem nav_blocked_domains = menu.findItem(R.id.nav_blocked_domains); + if( nav_blocked_domains != null) + nav_blocked_domains.setVisible(false); + + } } } @@ -1330,6 +1449,8 @@ public class Helper { 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.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); editor.commit(); Intent changeAccount = new Intent(activity, MainActivity.class); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); @@ -1577,7 +1698,7 @@ public class Helper { } @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) finalIcon.setImageResource(R.drawable.missing); else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) finalIcon.setImageResource(R.drawable.missing_peertube); @@ -1631,7 +1752,7 @@ public class Helper { } @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) itemIconAcc.setImageResource(R.drawable.missing); else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) itemIconAcc.setImageResource(R.drawable.missing_peertube); @@ -1657,19 +1778,28 @@ public class Helper { subActionButtonAcc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); - editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); - editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); - editor.commit(); - if(accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE")) - Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show(); - else - Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct() + "@" + accountChoice.getInstance()), Toast.LENGTH_LONG).show(); - Intent changeAccount = new Intent(activity, MainActivity.class); - changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - activity.finish(); - activity.startActivity(changeAccount); + if( !accountChoice.getToken().equals("null")) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); + editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); + editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin()); + editor.commit(); + if (accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE")) + Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show(); + else + Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct() + "@" + accountChoice.getInstance()), Toast.LENGTH_LONG).show(); + Intent changeAccount = new Intent(activity, MainActivity.class); + changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.finish(); + activity.startActivity(changeAccount); + }else{ //The account was logged out + Intent intent = new Intent(activity, LoginActivity.class); + intent.putExtra("instance", accountChoice.getInstance()); + intent.putExtra("social", accountChoice.getSocial()); + activity.startActivity(intent); + } } }); actionMenuAccBuilder.addSubActionView(subActionButtonAcc); @@ -1677,11 +1807,11 @@ public class Helper { } } - FloatingActionMenu actionMenuAcc = actionMenuAccBuilder.attachTo(actionButtonAcc) - .setStartAngle(0) - .setEndAngle(135) - .build(); if( actionButtonAcc != null) { + FloatingActionMenu actionMenuAcc = actionMenuAccBuilder.attachTo(actionButtonAcc) + .setStartAngle(0) + .setEndAngle(135) + .build(); if( accounts.size() > 2){ actionButtonAcc.setFocusableInTouchMode(true); actionButtonAcc.setFocusable(true); @@ -1710,15 +1840,24 @@ public class Helper { public void onClick(View v) { for(final Account accountChoice: accounts) { if (!currrentUserId.equals(accountChoice.getId())) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); - editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); - editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); - editor.commit(); - Intent changeAccount = new Intent(activity, MainActivity.class); - changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - activity.finish(); - activity.startActivity(changeAccount); + if( !accountChoice.getToken().equals("null")) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken()); + editor.putString(Helper.PREF_KEY_ID, accountChoice.getId()); + editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim()); + editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator()); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin()); + editor.commit(); + Intent changeAccount = new Intent(activity, MainActivity.class); + changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + activity.finish(); + activity.startActivity(changeAccount); + }else{ //The account was logged out + Intent intent = new Intent(activity, LoginActivity.class); + intent.putExtra("instance", accountChoice.getInstance()); + intent.putExtra("social", accountChoice.getSocial()); + activity.startActivity(intent); + } } } } @@ -1874,10 +2013,10 @@ public class Helper { accountsMentionUnknown.add(account); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>",""), Html.FROM_HTML_MODE_LEGACY)); + spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString(), Html.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL)); else //noinspection deprecation - spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>",""))); + spannableString = new SpannableString(Html.fromHtml(spannableStringT.toString())); URLSpan[] urls = spannableString.getSpans(0, spannableString.length(), URLSpan.class); for(URLSpan span : urls) @@ -2717,8 +2856,11 @@ public class Helper { return; } } - if( url == null || url.equals("null") || url.contains("missing.png") || url.contains(".svg")) { - if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { + if( url != null && url.startsWith("/")){ + url = Helper.getLiveInstanceWithProtocol(context) + url; + } + if( url == null || url.equals("null")|| url.equals("false") || url.contains("missing.png") || url.contains(".svg")) { + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { try { Glide.with(imageView.getContext()) .load(R.drawable.missing) @@ -2736,6 +2878,15 @@ public class Helper { } catch (Exception ignored) { } return; + }else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ + try { + Glide.with(imageView.getContext()) + .load(R.drawable.gnu_default_avatar) + .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10))) + .into(imageView); + } catch (Exception ignored) { + } + return; } } if( !disableGif) @@ -2813,14 +2964,16 @@ public class Helper { try { takenImage = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uriFile); } catch (IOException e) { - Toasty.error(context, context.getString(R.string.toast_error),Toast.LENGTH_LONG).show(); + try { + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + }catch (Exception ignored){}; return null; } ExifInterface exif = null; try (InputStream inputStream = context.getContentResolver().openInputStream(uriFile)) { assert inputStream != null; exif = new ExifInterface(inputStream); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } Matrix matrix = null; @@ -2837,7 +2990,7 @@ public class Helper { } SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); - int resizeSet = sharedpreferences.getInt(Helper.SET_PICTURE_RESIZE, Helper.S_2MO); + int resizeSet = sharedpreferences.getInt(Helper.SET_PICTURE_RESIZE, Helper.S_NO); if( mediaType == MediaType.PROFILE) resizeSet = Helper.S_1MO; double resizeby = size; @@ -2995,7 +3148,7 @@ public class Helper { tableLayout.setTabTextColors(ContextCompat.getColor(context, R.color.dark_text), ContextCompat.getColor(context, R.color.mastodonC4)); } - public static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) { + private static void removeTab(TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter, int position) { if (tableLayout.getTabCount() >= position ) { try { if(tableLayout.getTabCount() > 0) @@ -3158,6 +3311,8 @@ public class Helper { } if (timedMute != null && timedMute.size() > 0 && timedMute.contains(status.getAccount().getId())) return false; + if( status.isNotice()) + return false; return true; } |