Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void showImage() {
if (isAdded() && !TextUtils.isEmpty(mImageUrl)) {
// use max of width/height so image is cached the same regardless of orientation
Rect pt = DisplayUtils.getWindowSize(requireActivity());
int hiResWidth = Math.max(pt.height(), pt.width());
int hiResWidth = (int) (Math.max(pt.height(), pt.width()) * 0.8);
// don't use AT media proxy here
mPhotoView.setImageUrl(mImageUrl, hiResWidth, mIsPrivate, false, mPhotoViewListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public interface PhotoViewListener {
void onTapPhotoView();
}

private String mImageUrl;

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on field Note

Missing null annotation
private int mHiResWidth;
private boolean mIsPrivate;
private boolean mIsPrivateAtSite;

private PhotoViewListener mPhotoViewListener;
private String mLoResImageUrl;
private String mHiResImageUrl;
Expand Down Expand Up @@ -75,6 +80,11 @@ public void setImageUrl(String imageUrl,
boolean isPrivate,
boolean isPrivateAtSite,
PhotoViewListener listener) {
mImageUrl = imageUrl;
mHiResWidth = hiResWidth;
mIsPrivate = isPrivate;
mIsPrivateAtSite = isPrivateAtSite;

int loResWidth = (int) (hiResWidth * 0.10f);
mLoResImageUrl = ReaderUtils
.getResizedImageUrl(imageUrl, loResWidth, 0, isPrivate, isPrivateAtSite, PhotonUtils.Quality.LOW);
Expand Down Expand Up @@ -110,11 +120,16 @@ private void loadImage() {

mImageManager
.loadWithResultListener(mImageView, ImageType.IMAGE, mHiResImageUrl, ScaleType.CENTER, mLoResImageUrl,
new RequestListener<Drawable>() {
new RequestListener<>() {
@Override
public void onLoadFailed(@Nullable Exception e, @Nullable Object model) {
if (e != null) {
AppLog.e(AppLog.T.READER, e);
// A timeout could happen but there's no way to know it because the exception here is
// always a GlideException. So let's try to reload the image with a lower res
mImageView.post(
() -> loadFallbackImage()
);
}
boolean lowResNotLoadedYet = isLoading();
if (lowResNotLoadedYet) {
Expand All @@ -130,6 +145,35 @@ public void onResourceReady(@NonNull Drawable resource, @Nullable Object model)
});
}

private void loadFallbackImage() {
if (!hasLayout()) {
return;
}
String resImageUrl = ReaderUtils.getResizedImageUrl(mImageUrl, (int) (mHiResWidth * 0.5), 0, mIsPrivate,
mIsPrivateAtSite, PhotonUtils.Quality.MEDIUM);

mImageManager
.loadWithResultListener(mImageView, ImageType.IMAGE, resImageUrl, ScaleType.CENTER, mLoResImageUrl,
new RequestListener<>() {
@Override
public void onLoadFailed(@Nullable Exception e, @Nullable Object model) {
if (e != null) {
AppLog.e(AppLog.T.READER, e);
}
boolean lowResNotLoadedYet = isLoading();
if (lowResNotLoadedYet) {
hideProgress();
showError();
}
}

@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Object model) {
handleResponse();
}
});
}

private void handleResponse() {
hideProgress();
hideError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.bumptech.glide.request.target.ViewTarget
import com.bumptech.glide.request.transition.Transition
import com.bumptech.glide.signature.ObjectKey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.time.withTimeout
import org.wordpress.android.WordPress
import org.wordpress.android.networking.MShot
import org.wordpress.android.ui.media.VideoLoader
Expand Down Expand Up @@ -294,6 +295,7 @@ class ImageManager @Inject constructor(
if (!context.isAvailable()) return
Glide.with(context)
.load(imgUrl.toUri())
.timeout(5000)
.addFallback(imageType)
.addPlaceholder(imageType)
.addThumbnail(context, thumbnailUrl, requestListener)
Expand Down