Browse Source

Glide crash fix

pull/70/head
Ezerous 5 years ago
parent
commit
c5326e781c
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 19
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 17
      app/src/main/java/gr/thmmy/mthmmy/utils/ui/GlideUtils.java

19
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -1,5 +1,7 @@
package gr.thmmy.mthmmy.activities.profile; package gr.thmmy.mthmmy.activities.profile;
import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
@ -57,6 +59,7 @@ import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml; import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.emojiTagToHtml;
import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide;
import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage; import static gr.thmmy.mthmmy.utils.ui.PhotoViewUtils.displayPhotoViewImage;
/** /**
@ -222,12 +225,16 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
avatarView.setOnClickListener(v -> displayPhotoViewImage(ProfileActivity.this, avatarUrl)); avatarView.setOnClickListener(v -> displayPhotoViewImage(ProfileActivity.this, avatarUrl));
} }
Glide.with(this) if(isValidContextForGlide(this)){
.load(avatarUri) Glide.with(this)
.circleCrop() .load(avatarUri)
.error(R.drawable.ic_default_user_avatar) .circleCrop()
.placeholder(R.drawable.ic_default_user_avatar) .error(R.drawable.ic_default_user_avatar)
.into(avatarView); .placeholder(R.drawable.ic_default_user_avatar)
.into(avatarView);
}
else
Timber.d("Will not load Glide image (invalid context)");
} }
/** /**

15
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -88,6 +88,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_WHITE;
import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW; import static gr.thmmy.mthmmy.activities.topic.TopicParser.USER_COLOR_YELLOW;
import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager; import static gr.thmmy.mthmmy.base.BaseActivity.getSessionManager;
import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename; import static gr.thmmy.mthmmy.utils.FileUtils.faIconFromFilename;
import static gr.thmmy.mthmmy.utils.ui.GlideUtils.isValidContextForGlide;
/** /**
* Custom {@link RecyclerView.Adapter} used for topics. * Custom {@link RecyclerView.Adapter} used for topics.
@ -810,12 +811,14 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if(imageUrl!=null) if(imageUrl!=null)
imageUrl = imageUrl.trim(); imageUrl = imageUrl.trim();
Glide.with(context) if(isValidContextForGlide(context)) {
.load(imageUrl) Glide.with(context)
.circleCrop() .load(imageUrl)
.error(R.drawable.ic_default_user_avatar_darker) .circleCrop()
.placeholder(R.drawable.ic_default_user_avatar_darker) .error(R.drawable.ic_default_user_avatar_darker)
.into(imageView); .placeholder(R.drawable.ic_default_user_avatar_darker)
.into(imageView);
}
} }
@Override @Override

17
app/src/main/java/gr/thmmy/mthmmy/utils/ui/GlideUtils.java

@ -0,0 +1,17 @@
package gr.thmmy.mthmmy.utils.ui;
import android.app.Activity;
import android.content.Context;
public class GlideUtils {
public static boolean isValidContextForGlide(final Context context) {
if (context == null)
return false;
if (context instanceof Activity) {
final Activity activity = (Activity) context;
return !activity.isDestroyed() && !activity.isFinishing();
}
return true;
}
}
Loading…
Cancel
Save