Update lib change the way to load animated emoji
This commit is contained in:
parent
507a58b024
commit
af2aa0d1d2
|
@ -73,7 +73,7 @@ task gitPushReleaseNotes(type: Exec, dependsOn: 'copyAllReleaseNotes') {
|
|||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.browser:browser:1.2.0'
|
||||
|
@ -125,8 +125,7 @@ dependencies {
|
|||
implementation "ch.acra:acra-notification:5.4.0"
|
||||
implementation 'com.github.stom79:Android-WYSIWYG-Editor:3.2.1'
|
||||
implementation 'com.github.duanhong169:colorpicker:1.1.6'
|
||||
implementation 'com.github.penfeizhou.android.animation:apng:1.1.0'
|
||||
implementation 'com.github.penfeizhou.android.animation:gif:1.1.0'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.0.0'
|
||||
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
|
||||
implementation 'com.github.smarteist:autoimageslider:1.3.2'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
|
||||
|
|
|
@ -119,7 +119,7 @@ public class BookmarkActivity extends BaseActivity implements OnRetrieveFeedsInt
|
|||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
lv_status = findViewById(R.id.lv_status);
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
|
|||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
Bundle b = getIntent().getExtras();
|
||||
Status status = null;
|
||||
if (b != null) {
|
||||
|
|
|
@ -144,7 +144,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
|
|||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
LinearLayout custom_fields_container = findViewById(R.id.custom_fields_container);
|
||||
set_profile_name = findViewById(R.id.set_profile_name);
|
||||
set_profile_description = findViewById(R.id.set_profile_description);
|
||||
|
|
|
@ -149,7 +149,7 @@ public class OwnerChartsActivity extends BaseActivity implements OnRetrieveChart
|
|||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
if (account != null) {
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
}
|
||||
|
||||
toolbar_close.setOnClickListener(v -> finish());
|
||||
|
|
|
@ -212,7 +212,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
|
|||
SQLiteDatabase db = Sqlite.getInstance(OwnerNotificationActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(OwnerNotificationActivity.this, db).getUniqAccount(userId, instance);
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
||||
int c1 = getResources().getColor(R.color.cyanea_accent);
|
||||
|
|
|
@ -156,7 +156,7 @@ public class OwnerNotificationChartsActivity extends BaseActivity implements OnR
|
|||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
if (account != null) {
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
}
|
||||
|
||||
toolbar_close.setOnClickListener(v -> finish());
|
||||
|
|
|
@ -221,7 +221,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(OwnerStatusActivity.this, db).getUniqAccount(userId, instance);
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
||||
int c1 = getResources().getColor(R.color.cyanea_accent);
|
||||
|
|
|
@ -232,7 +232,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), my_pp);
|
||||
Helper.loadGiF(getApplicationContext(), account, my_pp);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if (b != null) {
|
||||
peertubeInstance = b.getString("peertube_instance", null);
|
||||
|
|
|
@ -750,7 +750,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
|
|||
toot_content.requestFocus();
|
||||
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
|
||||
if (visibility == null) {
|
||||
|
|
|
@ -352,7 +352,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
actionbar_title.setText(account.getAcct());
|
||||
ImageView pp_actionBar = findViewById(R.id.pp_actionBar);
|
||||
if (account.getAvatar() != null) {
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
}
|
||||
final AppBarLayout appBar = findViewById(R.id.appBar);
|
||||
|
@ -717,7 +717,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
|
||||
|
||||
}
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), account_pp);
|
||||
Helper.loadGiF(getApplicationContext(), account, account_pp);
|
||||
account_pp.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(ShowAccountActivity.this, SlideMediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
|
|
@ -218,7 +218,7 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
|
|||
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
|
||||
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
||||
|
|
|
@ -1070,7 +1070,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
|||
initialContent = displayWYSIWYG() ? wysiwyg.getContentAsHTML() : toot_content.getText().toString();
|
||||
|
||||
|
||||
Helper.loadGiF(getApplicationContext(), account.getAvatar(), pp_actionBar);
|
||||
Helper.loadGiF(getApplicationContext(), account, pp_actionBar);
|
||||
|
||||
|
||||
if (sharedContent != null) { //Shared content
|
||||
|
|
|
@ -45,20 +45,16 @@ import androidx.preference.PreferenceManager;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.github.penfeizhou.animation.apng.APNGDrawable;
|
||||
import com.github.penfeizhou.animation.apng.decode.APNGParser;
|
||||
import com.github.penfeizhou.animation.gif.GifDrawable;
|
||||
import com.github.penfeizhou.animation.gif.decode.GifParser;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -81,6 +77,7 @@ import static app.fedilab.android.helper.Helper.hashtagPattern;
|
|||
* Manage accounts
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Account implements Parcelable {
|
||||
|
||||
public static final Creator<Account> CREATOR = new Creator<Account>() {
|
||||
|
@ -368,7 +365,7 @@ public class Account implements Parcelable {
|
|||
return fieldsSpan;
|
||||
}
|
||||
|
||||
public void setFieldsSpan(LinkedHashMap<SpannableString, SpannableString> fieldsSpan) {
|
||||
private void setFieldsSpan(LinkedHashMap<SpannableString, SpannableString> fieldsSpan) {
|
||||
this.fieldsSpan = fieldsSpan;
|
||||
}
|
||||
|
||||
|
@ -771,20 +768,17 @@ public class Account implements Parcelable {
|
|||
}
|
||||
final int link_color = l_c;
|
||||
if (account.getFields() != null && account.getFields().size() > 0) {
|
||||
Iterator it = account.getFields().entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry) it.next();
|
||||
for (Map.Entry<String, String> stringStringEntry : account.getFields().entrySet()) {
|
||||
SpannableString fieldSpan;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
fieldSpan = new SpannableString(Html.fromHtml((String) pair.getValue(), FROM_HTML_MODE_LEGACY));
|
||||
fieldSpan = new SpannableString(Html.fromHtml((String) ((Map.Entry) stringStringEntry).getValue(), FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
//noinspection deprecation
|
||||
fieldSpan = new SpannableString(Html.fromHtml((String) pair.getValue()));
|
||||
fieldsSpan.put(new SpannableString((String) pair.getKey()), fieldSpan);
|
||||
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((String) pair.getValue());
|
||||
fieldSpan = new SpannableString(Html.fromHtml((String) ((Map.Entry) stringStringEntry).getValue()));
|
||||
fieldsSpan.put(new SpannableString((String) ((Map.Entry) stringStringEntry).getKey()), fieldSpan);
|
||||
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((String) ((Map.Entry) stringStringEntry).getValue());
|
||||
while (matcherALink.find()) {
|
||||
String acct = matcherALink.group(3).replace("@", "");
|
||||
String acct = Objects.requireNonNull(matcherALink.group(3)).replace("@", "");
|
||||
String instance = matcherALink.group(2);
|
||||
Account accountMention = new Account();
|
||||
accountMention.setAcct(acct);
|
||||
|
@ -804,7 +798,6 @@ public class Account implements Parcelable {
|
|||
SpannableString keySpan = (SpannableString) pair.getKey();
|
||||
|
||||
Matcher matcher = Helper.xmppPattern.matcher(fieldSpan);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
while (matcher.find()) {
|
||||
URLSpan[] urls = fieldSpan.getSpans(0, fieldSpan.length(), URLSpan.class);
|
||||
for (URLSpan span : urls)
|
||||
|
@ -947,7 +940,6 @@ public class Account implements Parcelable {
|
|||
int matchEnd = matcher.end();
|
||||
final String url = fieldSpan.toString().substring(matchStart, matchEnd);
|
||||
if (matchEnd <= fieldSpan.toString().length() && matchEnd >= matchStart) {
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
fieldSpan.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View textView) {
|
||||
|
@ -968,9 +960,8 @@ public class Account implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
final List<Emojis> emojis = account.getEmojis();
|
||||
boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false);
|
||||
final List<Emojis> emojis = account.getEmojis();
|
||||
if (emojis != null && emojis.size() > 0) {
|
||||
|
||||
final int[] i = {0};
|
||||
|
@ -978,41 +969,21 @@ public class Account implements Parcelable {
|
|||
fields = account.getFields();
|
||||
try {
|
||||
Glide.with(context)
|
||||
.asFile()
|
||||
.load(emoji.getUrl())
|
||||
.into(new SimpleTarget<File>() {
|
||||
.asDrawable()
|
||||
.load(disableAnimatedEmoji?emoji.getStatic_url():emoji.getUrl())
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull File resourceFile, @Nullable Transition<? super File> transition) {
|
||||
Drawable resource;
|
||||
if (GifParser.isGif(resourceFile.getAbsolutePath())) {
|
||||
resource = GifDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else if (APNGParser.isAPNG(resourceFile.getAbsolutePath())) {
|
||||
resource = APNGDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else {
|
||||
resource = Drawable.createFromPath(resourceFile.getAbsolutePath());
|
||||
}
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
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(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1025,55 +996,36 @@ public class Account implements Parcelable {
|
|||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
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(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator it = fieldsSpan.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry) it.next();
|
||||
SpannableString fieldSpan = (SpannableString) pair.getValue();
|
||||
SpannableString keySpan = (SpannableString) pair.getKey();
|
||||
for (Map.Entry<SpannableString, SpannableString> spannableStringSpannableStringEntry : fieldsSpan.entrySet()) {
|
||||
SpannableString fieldSpan = (SpannableString) ((Map.Entry) spannableStringSpannableStringEntry).getValue();
|
||||
SpannableString keySpan = (SpannableString) ((Map.Entry) spannableStringSpannableStringEntry).getKey();
|
||||
if (fieldSpan.toString().contains(targetedEmoji)) {
|
||||
//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) {
|
||||
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(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
fieldsSpan.put((SpannableString) pair.getKey(), fieldSpan);
|
||||
fieldsSpan.put((SpannableString) ((Map.Entry) spannableStringSpannableStringEntry).getKey(), fieldSpan);
|
||||
} else
|
||||
fieldsSpan.put(keySpan, fieldSpan);
|
||||
}
|
||||
|
||||
i[0]++;
|
||||
if (i[0] == (emojis.size())) {
|
||||
if (noteSpan != null)
|
||||
|
|
|
@ -58,12 +58,6 @@ import com.bumptech.glide.request.RequestListener;
|
|||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.github.penfeizhou.animation.apng.APNGDrawable;
|
||||
import com.github.penfeizhou.animation.apng.decode.APNGParser;
|
||||
import com.github.penfeizhou.animation.gif.GifDrawable;
|
||||
import com.github.penfeizhou.animation.gif.decode.GifParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -942,11 +936,11 @@ public class Status implements Parcelable {
|
|||
final int[] i = {0};
|
||||
for (final Emojis emoji : emojis) {
|
||||
Glide.with(context)
|
||||
.asFile()
|
||||
.load(emoji.getUrl())
|
||||
.listener(new RequestListener<File>() {
|
||||
.asDrawable()
|
||||
.load(disableAnimatedEmoji?emoji.getStatic_url():emoji.getUrl())
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -959,20 +953,9 @@ public class Status implements Parcelable {
|
|||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<File>() {
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull File resourceFile, @Nullable Transition<? super File> transition) {
|
||||
Drawable resource;
|
||||
if (GifParser.isGif(resourceFile.getAbsolutePath())) {
|
||||
resource = GifDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else if (APNGParser.isAPNG(resourceFile.getAbsolutePath())) {
|
||||
resource = APNGDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else {
|
||||
resource = Drawable.createFromPath(resourceFile.getAbsolutePath());
|
||||
}
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
if (contentSpan != null && contentSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
|
@ -980,24 +963,9 @@ public class Status implements Parcelable {
|
|||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
||||
ImageSpan imageSpan;
|
||||
if (!disableAnimatedEmoji) {
|
||||
try {
|
||||
resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context));
|
||||
resource.setVisible(true, true);
|
||||
imageSpan = new ImageSpan(resource);
|
||||
} catch (Exception e) {
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
|
||||
} else {
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
contentSpan.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1010,17 +978,9 @@ public class Status implements Parcelable {
|
|||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= contentSpanCW.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));
|
||||
}
|
||||
contentSpanCW.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1070,11 +1030,11 @@ public class Status implements Parcelable {
|
|||
for (final Emojis emoji : emojis) {
|
||||
int finalInc = inc;
|
||||
Glide.with(context)
|
||||
.asFile()
|
||||
.load(emoji.getUrl())
|
||||
.listener(new RequestListener<File>() {
|
||||
.asDrawable()
|
||||
.load(disableAnimatedEmoji?emoji.getStatic_url():emoji.getUrl())
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1087,20 +1047,9 @@ public class Status implements Parcelable {
|
|||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<File>() {
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull File resourceFile, @Nullable Transition<? super File> transition) {
|
||||
Drawable resource;
|
||||
if (GifParser.isGif(resourceFile.getAbsolutePath())) {
|
||||
resource = GifDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else if (APNGParser.isAPNG(resourceFile.getAbsolutePath())) {
|
||||
resource = APNGDrawable.fromFile(resourceFile.getAbsolutePath());
|
||||
} else {
|
||||
resource = Drawable.createFromPath(resourceFile.getAbsolutePath());
|
||||
}
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
if (titleSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
|
@ -1108,17 +1057,9 @@ public class Status implements Parcelable {
|
|||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if (endPosition <= titleSpan.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 {
|
||||
Bitmap bitmap = drawableToBitmap(resource.getCurrent());
|
||||
imageSpan = new ImageSpan(context,
|
||||
Bitmap.createScaledBitmap(bitmap, (int) Helper.convertDpToPixel(20, context),
|
||||
(int) Helper.convertDpToPixel(20, context), false));
|
||||
}
|
||||
titleSpan.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class AccountsAdminListAdapter extends RecyclerView.Adapter implements On
|
|||
holder.account_ac.setVisibility(View.VISIBLE);
|
||||
|
||||
holder.report_action_taken.setText(accountAdmin.getIp());
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
|
||||
Helper.loadGiF(context, account, holder.account_pp);
|
||||
|
||||
|
||||
holder.main_container.setOnClickListener(view -> {
|
||||
|
|
|
@ -96,7 +96,7 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
|
|||
else
|
||||
holder.account_ac.setVisibility(View.VISIBLE);
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
|
||||
Helper.loadGiF(context, account, holder.account_pp);
|
||||
|
||||
if (actionType == type.CURRENT) {
|
||||
holder.account_action.setImageResource(R.drawable.ic_close);
|
||||
|
|
|
@ -191,7 +191,7 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
|||
holder.account_fgc.setText(Helper.withSuffix(account.getFollowing_count()));
|
||||
holder.account_frc.setText(Helper.withSuffix(account.getFollowers_count()));
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
|
||||
Helper.loadGiF(context, account, holder.account_pp);
|
||||
if (account.isMakingAction()) {
|
||||
holder.account_follow.setEnabled(false);
|
||||
} else {
|
||||
|
|
|
@ -153,7 +153,7 @@ public class ArtListAdapter extends RecyclerView.Adapter implements OnPostAction
|
|||
Status.makeEmojis(context, this, status);
|
||||
|
||||
if (status.getAccount() != null && status.getAccount().getAvatar() != null)
|
||||
Helper.loadGiF(context, status.getAccount().getAvatar(), holder.art_pp);
|
||||
Helper.loadGiF(context, status.getAccount(), holder.art_pp);
|
||||
|
||||
if (status.getArt_attachment() != null)
|
||||
Glide.with(context)
|
||||
|
|
|
@ -999,7 +999,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
|
||||
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, notification.getAccount().getAvatar(), holder.notification_account_profile);
|
||||
Helper.loadGiF(context, notification.getAccount(), holder.notification_account_profile);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio
|
|||
.into(holder.peertube_video_image);
|
||||
if (account.getAvatar() != null && !account.getAvatar().equals("null") && !account.getAvatar().startsWith("http"))
|
||||
account.setAvatar("https://" + peertube.getInstance() + account.getAvatar());
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.peertube_profile);
|
||||
Helper.loadGiF(context, account, holder.peertube_profile);
|
||||
|
||||
|
||||
if (peertube.getHeaderType() != null && peertube.getHeaderTypeValue() != null) {
|
||||
|
|
|
@ -93,9 +93,9 @@ public class ReportsListAdapter extends RecyclerView.Adapter implements OnRetrie
|
|||
|
||||
|
||||
if (target_account.getAvatar() != null) {
|
||||
Helper.loadGiF(context, target_account.getAvatar(), holder.account_pp);
|
||||
Helper.loadGiF(context, target_account, holder.account_pp);
|
||||
}
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.account_pp_reporter);
|
||||
Helper.loadGiF(context, account, holder.account_pp_reporter);
|
||||
if (target_account.getAcct() != null) {
|
||||
holder.account_ac.setText(target_account.getAcct());
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public class ScheduledTootsListAdapter extends BaseAdapter implements OnPostActi
|
|||
holder.scheduled_toot_media_count.setVisibility(View.GONE);
|
||||
holder.scheduled_toot_date_creation.setVisibility(View.GONE);
|
||||
holder.scheduled_toot_privacy.setVisibility(View.GONE);
|
||||
Helper.loadGiF(context, storedStatus.getStatus().getAccount().getAvatar(), holder.scheduled_toot_pp);
|
||||
Helper.loadGiF(context, storedStatus.getStatus().getAccount(), holder.scheduled_toot_pp);
|
||||
} else {
|
||||
holder.scheduled_toot_pp.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -1784,13 +1784,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
|
||||
if (status.getReblog() != null) {
|
||||
Helper.loadGiF(context, accountForUrl.getAvatar(), holder.status_account_profile);
|
||||
Helper.loadGiF(context, status.getAccount().getAvatar(), holder.status_account_profile_boost_by);
|
||||
Helper.loadGiF(context, accountForUrl, holder.status_account_profile);
|
||||
Helper.loadGiF(context, status.getAccount(), holder.status_account_profile_boost_by);
|
||||
if (holder.status_boosted_by_info != null) {
|
||||
holder.status_boosted_by_info.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
Helper.loadGiF(context, accountForUrl.getAvatar(), holder.status_account_profile);
|
||||
Helper.loadGiF(context, accountForUrl, holder.status_account_profile);
|
||||
if (holder.status_boosted_by_info != null) {
|
||||
holder.status_boosted_by_info.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -3289,6 +3289,62 @@ public class Helper {
|
|||
return String.format(Locale.getDefault(), "%s:%s", strMin, strSec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void loadGiF(final Context context, Account account, final ImageView imageView) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
|
||||
String url = disableGif?account.getAvatar_static():account.getAvatar();
|
||||
if (url != null && url.startsWith("/")) {
|
||||
url = Helper.getLiveInstanceWithProtocol(context) + url;
|
||||
}
|
||||
if (!(context instanceof MainApplication) && ((Activity) context).isFinishing()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if( account.getAvatar_static().compareTo(account.getAvatar()) == 0 ) {
|
||||
Glide.with(imageView.getContext())
|
||||
.asDrawable()
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
}else{
|
||||
Glide.with(imageView.getContext())
|
||||
.asGif()
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
Glide.with(imageView.getContext())
|
||||
.asDrawable()
|
||||
.load(R.drawable.missing)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||
Glide.with(imageView.getContext())
|
||||
.asDrawable()
|
||||
.load(R.drawable.missing_peertube)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
Glide.with(imageView.getContext())
|
||||
.asDrawable()
|
||||
.load(R.drawable.gnu_default_avatar)
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
.into(imageView);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void loadGiF(final Context context, String url, final ImageView imageView) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
|
||||
|
|
Loading…
Reference in New Issue