From c97120528bd158c7ff430846ac04acfa74f78058 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 14 Jul 2020 23:26:19 +0800 Subject: Use SubsamplingScaleImageView in ViewImgurImageFragment. Probably fix gif too small in AspectRatioGifImageView. --- .../Activity/ViewImageOrGifActivity.java | 11 ----------- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 2 +- .../Adapter/PostRecyclerViewAdapter.java | 2 +- .../Fragment/ViewImgurImageFragment.java | 23 ++++++++++++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java index 0577ba2f..dd2b0d1c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java @@ -11,7 +11,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.Html; -import android.util.DisplayMetrics; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -155,16 +154,6 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa setTitle(""); } - DisplayMetrics displayMetrics = new DisplayMetrics(); - getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - int windowHeight = displayMetrics.heightPixels; - - /*mHaulerView.setOnDragDismissedListener(dragDirection -> { - int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; - finish(); - overridePendingTransition(0, slide); - });*/ - mLoadErrorLinearLayout.setOnClickListener(view -> { mProgressBar.setVisibility(View.VISIBLE); mLoadErrorLinearLayout.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index bbf36110..a7975e47 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1248,7 +1248,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mPost.getPreviewWidth()) { + if (mImageViewWidth > mPost.getPreviewWidth() && mPost.getPostType() == Post.IMAGE_TYPE) { imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); } else { imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 835d8af1..d630f12a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -875,7 +875,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter post.getPreviewWidth()) { + if (mImageViewWidth > post.getPreviewWidth() && post.getPostType() == Post.IMAGE_TYPE) { imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostImageAndGifAutoplayViewHolder) holder).imageView); } else { imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java index 51c48d26..83411416 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java @@ -26,7 +26,6 @@ import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; -import com.alexvasilkov.gestures.views.GestureImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; @@ -35,6 +34,8 @@ import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.transition.Transition; +import com.davemorrissey.labs.subscaleview.ImageSource; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import java.io.File; @@ -58,7 +59,7 @@ public class ViewImgurImageFragment extends Fragment { @BindView(R.id.progress_bar_view_imgur_image_fragment) ProgressBar progressBar; @BindView(R.id.image_view_view_imgur_image_fragment) - GestureImageView imageView; + SubsamplingScaleImageView imageView; @BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment) LinearLayout errorLinearLayout; @@ -110,20 +111,30 @@ public class ViewImgurImageFragment extends Fragment { } private void loadImage() { - glide.load(imgurMedia.getLink()).listener(new RequestListener() { + glide.asBitmap().load(imgurMedia.getLink()).listener(new RequestListener() { @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { progressBar.setVisibility(View.GONE); errorLinearLayout.setVisibility(View.VISIBLE); return false; } @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + public boolean onResourceReady(Bitmap resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { progressBar.setVisibility(View.GONE); return false; } - }).override(Target.SIZE_ORIGINAL).into(imageView); + }).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + imageView.setImage(ImageSource.bitmap(resource)); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); } @Override -- cgit v1.2.3