Commit 4b579bbb authored by Thomas's avatar Thomas
Browse files

Fix issue #431

parent 64056f21
Pipeline #298955 passed with stage
in 4 minutes and 5 seconds
......@@ -180,7 +180,6 @@ public abstract class BaseMainActivity extends BaseActivity
public static String regex_home, regex_local, regex_public;
public static boolean show_boosts, show_replies, show_art_nsfw;
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
public static boolean isAttached = false;
private static boolean notificationChecked = false;
private final int PICK_IMPORT = 5556;
private FloatingActionButton toot, delete_all, add_new;
......@@ -2382,13 +2381,11 @@ public abstract class BaseMainActivity extends BaseActivity
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
isAttached = true;
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
isAttached = false;
}
public enum iconLauncher {
......
......@@ -103,6 +103,7 @@ import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
......@@ -225,7 +226,6 @@ import okhttp3.TlsVersion;
import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.activities.BaseMainActivity.filters;
import static app.fedilab.android.activities.BaseMainActivity.isAttached;
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
import static app.fedilab.android.activities.BaseMainActivity.regex_home;
import static app.fedilab.android.activities.BaseMainActivity.regex_local;
......@@ -1722,37 +1722,50 @@ public class Helper {
icon = new ImageView(activity);
ImageView finalIcon = icon;
if (isValidContextForGlide(activity)) {
Glide.with(activity)
.asDrawable()
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.listener(new RequestListener<Drawable>() {
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
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);
return false;
}
})
.load(!disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static())
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
finalIcon.setImageDrawable(resource);
}
String avatarUrl = !disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static();
if( avatarUrl.contains(".gif")) {
Glide.with(finalIcon.getContext())
.asGif()
.load(avatarUrl)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.into(finalIcon);
}else{
Glide.with(activity)
.asDrawable()
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.listener(new RequestListener<Drawable>() {
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
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);
return false;
}
})
.load(avatarUrl)
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
finalIcon.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
}
});
}
MenuFloating.Builder actionButtonAccBuild = new MenuFloating.Builder(activity);
if (theme == THEME_LIGHT) {
......@@ -1782,39 +1795,50 @@ public class Helper {
if (!accountChoice.getAvatar().startsWith("http"))
accountChoice.setAvatar("https://" + accountChoice.getInstance() + accountChoice.getAvatar());
ImageView itemIconAcc = new ImageView(activity);
if (!activity.isFinishing() && isAttached) {
if (isValidContextForGlide(activity) ) {
try {
Glide.with(activity)
.asDrawable()
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.load(!disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
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);
return false;
}
})
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
itemIconAcc.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
String avatarUrl = !disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static();
if( avatarUrl.contains(".gif")) {
Glide.with(itemIconAcc.getContext())
.asGif()
.load(avatarUrl)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.into(itemIconAcc);
}else{
Glide.with(activity)
.asDrawable()
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(270)))
.load(!disableGif ? accountChoice.getAvatar() : accountChoice.getAvatar_static())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
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);
return false;
}
})
.into(new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
itemIconAcc.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
}
});
} catch (Exception ignored) {
}
}
......@@ -1924,7 +1948,7 @@ public class Helper {
}
if (!urlHeader.contains("missing.png")) {
ImageView backgroundImage = headerLayout.findViewById(R.id.back_ground_image);
if (!activity.isFinishing() && isAttached) {
if (isValidContextForGlide(activity)) {
try {
Glide.with(activity)
.asDrawable()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment