Fix crashes
This commit is contained in:
parent
3c20af322f
commit
d80193545d
|
@ -67,6 +67,8 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import app.fedilab.android.client.API;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
|
@ -312,6 +314,15 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
}else{
|
||||
account_un.setCompoundDrawables( null, null, null, null);
|
||||
}
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
if( !disableAnimatedEmoji) {
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
account_dn.invalidate();
|
||||
}
|
||||
}, 0, 130, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
//Peertube account watched by a Mastodon account
|
||||
if( peertubeAccount && (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)) {
|
||||
|
|
|
@ -19,12 +19,14 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.Spannable;
|
||||
|
@ -66,6 +68,7 @@ import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
|||
import static app.fedilab.android.helper.Helper.THEME_BLACK;
|
||||
import static app.fedilab.android.helper.Helper.THEME_DARK;
|
||||
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
|
||||
import static app.fedilab.android.helper.Helper.drawableToBitmap;
|
||||
import static app.fedilab.android.helper.Helper.hashtagPattern;
|
||||
|
||||
|
||||
|
@ -924,6 +927,8 @@ public class Account implements Parcelable {
|
|||
|
||||
|
||||
final List<Emojis> emojis = account.getEmojis();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
if( emojis != null && emojis.size() > 0 ) {
|
||||
|
||||
final int[] i = {0};
|
||||
|
@ -931,37 +936,59 @@ public class Account implements Parcelable {
|
|||
fields = account.getFields();
|
||||
try {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.asDrawable()
|
||||
.load(emoji.getUrl())
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
|
||||
if (noteSpan != null && noteSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
for (int startPosition = -1; (startPosition = noteSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= noteSpan.toString().length() && endPosition >= startPosition)
|
||||
if (endPosition <= noteSpan.toString().length() && endPosition >= startPosition){
|
||||
ImageSpan imageSpan;
|
||||
if( !disableAnimatedEmoji) {
|
||||
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||
resource.setVisible(true, true);
|
||||
imageSpan = new ImageSpan(resource);
|
||||
}else{
|
||||
resource.setVisible(true, true);
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
noteSpan.setSpan(
|
||||
new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (displayNameSpan != null && displayNameSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition)
|
||||
if (endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition){
|
||||
ImageSpan imageSpan;
|
||||
if( !disableAnimatedEmoji) {
|
||||
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||
resource.setVisible(true, true);
|
||||
imageSpan = new ImageSpan(resource);
|
||||
}else{
|
||||
resource.setVisible(true, true);
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
displayNameSpan.setSpan(
|
||||
new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator it = fieldsSpan.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry) it.next();
|
||||
|
@ -971,13 +998,24 @@ public class Account implements Parcelable {
|
|||
//emojis can be used several times so we have to loop
|
||||
for (int startPosition = -1; (startPosition = fieldSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= fieldSpan.toString().length() && endPosition >= startPosition)
|
||||
if (endPosition <= fieldSpan.toString().length() && endPosition >= startPosition){
|
||||
ImageSpan imageSpan;
|
||||
if( !disableAnimatedEmoji) {
|
||||
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||
resource.setVisible(true, true);
|
||||
imageSpan = new ImageSpan(resource);
|
||||
}else{
|
||||
resource.setVisible(true, true);
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
fieldSpan.setSpan(
|
||||
new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
fieldsSpan.put((SpannableString) pair.getKey(), fieldSpan);
|
||||
}else
|
||||
fieldsSpan.put(keySpan, fieldSpan);
|
||||
|
@ -1010,29 +1048,42 @@ public class Account implements Parcelable {
|
|||
if( account.getDisplay_name() != null)
|
||||
displayNameSpan = new SpannableString(account.getDisplay_name());
|
||||
final List<Emojis> emojis = account.getEmojis();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
if( emojis != null && emojis.size() > 0 ) {
|
||||
final int[] i = {0};
|
||||
for (final Emojis emoji : emojis) {
|
||||
try {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.asDrawable()
|
||||
.load(emoji.getUrl())
|
||||
.into(new SimpleTarget<Bitmap>() {
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
if (displayNameSpan != null && displayNameSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition)
|
||||
if (endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition){
|
||||
ImageSpan imageSpan;
|
||||
if( !disableAnimatedEmoji) {
|
||||
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||
resource.setVisible(true, true);
|
||||
imageSpan = new ImageSpan(resource);
|
||||
}else{
|
||||
resource.setVisible(true, true);
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
displayNameSpan.setSpan(
|
||||
new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
i[0]++;
|
||||
if (i[0] == (emojis.size())) {
|
||||
if (listener != null)
|
||||
|
|
|
@ -14,6 +14,7 @@ package app.fedilab.android.drawers;
|
|||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
|
@ -64,8 +65,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
import app.fedilab.android.activities.AccountReportActivity;
|
||||
import app.fedilab.android.client.API;
|
||||
|
@ -105,7 +105,7 @@ import app.fedilab.android.interfaces.OnRetrieveEmojiAccountInterface;
|
|||
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
|
||||
|
||||
import static app.fedilab.android.activities.BaseMainActivity.social;
|
||||
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -376,24 +376,30 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
holder.status_document_container.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_document_container.setVisibility(View.VISIBLE);
|
||||
if( !notification.isNotificationAnimated() && status.getEmojis().size() > 0) {
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
if( !disableAnimatedEmoji && !notification.isNotificationAnimated() && (status.getEmojis().size() > 0 || status.getAccount().getEmojis().size() > 0) ) {
|
||||
notification.setNotificationAnimated(true);
|
||||
try{
|
||||
/*try{
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.notification_status_content.invalidate();
|
||||
}
|
||||
}, 0, 130, TimeUnit.MILLISECONDS);
|
||||
}catch (Exception ignored){}
|
||||
|
||||
|
||||
/*new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||
}catch (Exception ignored){}*/
|
||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Activity)context).runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.notification_account_username.invalidate();
|
||||
holder.notification_status_content.invalidate();
|
||||
}
|
||||
}, 0, 500);*/
|
||||
});
|
||||
|
||||
}
|
||||
}, 0, 130);
|
||||
}
|
||||
if( !status.isClickable())
|
||||
Status.transform(context, status);
|
||||
|
|
|
@ -96,9 +96,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|||
import com.varunest.sparkbutton.SparkButton;
|
||||
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -107,14 +104,11 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import app.fedilab.android.activities.AccountReportActivity;
|
||||
import app.fedilab.android.asynctasks.PostStatusAsyncTask;
|
||||
import app.fedilab.android.asynctasks.RetrieveRelationshipAsyncTask;
|
||||
import app.fedilab.android.asynctasks.RetrieveRelationshipQuickReplyAsyncTask;
|
||||
import app.fedilab.android.client.API;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
|
@ -1175,16 +1169,32 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12 * textSizePercent / 100);
|
||||
holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100);
|
||||
}
|
||||
if( !status.isStatusAnimated() && status.getEmojis().size() > 0 ) {
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
|
||||
|
||||
if( !disableAnimatedEmoji && !status.isStatusAnimated() && (status.getEmojis().size() > 0 || status.getAccount().getEmojis().size() > 0) ) {
|
||||
status.setStatusAnimated(true);
|
||||
try{
|
||||
/*try{
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.status_content.invalidate();
|
||||
}
|
||||
}, 0, 130, TimeUnit.MILLISECONDS);
|
||||
}catch (Exception ignored){}
|
||||
}catch (Exception ignored){}*/
|
||||
|
||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Activity)context).runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
holder.status_account_displayname.invalidate();
|
||||
holder.status_content.invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0, 130);
|
||||
|
||||
}
|
||||
holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100);
|
||||
|
|
Loading…
Reference in New Issue