diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java index fe5dc54c..33b63d79 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/ImageDownloadDialogBuilder.java @@ -56,9 +56,8 @@ public class ImageDownloadDialogBuilder extends AlertDialog.Builder{ private BaseActivity getBaseActivity() { Context baseActivityContext = context; while (baseActivityContext instanceof ContextWrapper) { - if (context instanceof BaseActivity) { + if (context instanceof BaseActivity) return (BaseActivity) context; - } baseActivityContext = ((ContextWrapper)context).getBaseContext(); } return null; diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java index b361c68d..1d5dc485 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/ui/PhotoViewUtils.java @@ -3,12 +3,20 @@ package gr.thmmy.mthmmy.utils.ui; import android.app.Dialog; import android.content.Context; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.view.ViewGroup; import android.view.Window; +import androidx.annotation.Nullable; + import com.bumptech.glide.Glide; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.Target; import com.github.chrisbanes.photoview.PhotoView; +import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; public class PhotoViewUtils { @@ -24,21 +32,32 @@ public class PhotoViewUtils { PhotoView photoView = new PhotoView(context); photoView.setLayoutParams(new ViewGroup.LayoutParams(screenWidth, screenHeight)); - Glide.with(context) .load(imageURL) .fitCenter() + .error(R.drawable.ic_file_not_found) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + photoView.setZoomable(false); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + photoView.setOnLongClickListener(v -> { + ImageDownloadDialogBuilder imageDownloadDialogBuilder = new ImageDownloadDialogBuilder(context, imageURL); + imageDownloadDialogBuilder.show(); + return false; + }); + return false; + } + }) .into(photoView); builder.addContentView(photoView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); builder.show(); - - photoView.setOnLongClickListener(v -> { - ImageDownloadDialogBuilder imageDownloadDialogBuilder = new ImageDownloadDialogBuilder(context, imageURL); - imageDownloadDialogBuilder.show(); - return false; - }); } } diff --git a/app/src/main/res/drawable/ic_file_not_found.xml b/app/src/main/res/drawable/ic_file_not_found.xml new file mode 100644 index 00000000..78615445 --- /dev/null +++ b/app/src/main/res/drawable/ic_file_not_found.xml @@ -0,0 +1,5 @@ + + +