From 874ecbbf72fedc9f1f539308e453ea2547ccc516 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 21 Feb 2021 22:28:56 +0800 Subject: Start adding Card Layout 2. --- .../adapters/PostRecyclerViewAdapter.java | 262 ++++++++++++++++++++- .../PostLayoutBottomSheetFragment.java | 6 + .../utils/SharedPreferencesUtils.java | 1 + 3 files changed, 257 insertions(+), 12 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index c791e2d8..76a561c5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -115,8 +115,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override @@ -377,8 +378,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter imageRequestBuilder = mGlide.load(url).listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + ((PostCard2ViewHolder) holder).progressBar.setVisibility(View.GONE); + ((PostCard2ViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); + ((PostCard2ViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { + ((PostCard2ViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostCard2ViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + loadImage(holder, post, preview); + }); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + ((PostCard2ViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostCard2ViewHolder) holder).progressBar.setVisibility(View.GONE); + return false; + } + }); + + if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostCard2ViewHolder) holder).imageView); + } else { + if (mImageViewWidth > preview.getPreviewWidth()) { + imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostCard2ViewHolder) holder).imageView); + } else { + imageRequestBuilder.into(((PostCard2ViewHolder) holder).imageView); + } + } } } @@ -1587,6 +1705,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + itemView.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position >= 0 && canStartActivity) { Post post = getItem(position); @@ -2276,7 +2399,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); + openMedia(post); + } + }); + + noPreviewLinkImageView.setOnClickListener(view -> { + imageView.performClick(); + }); + } + } + class ErrorViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.error_text_view_item_footer_error) TextView errorTextView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java index fba94be1..b2babae7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java @@ -30,6 +30,8 @@ public class PostLayoutBottomSheetFragment extends RoundedBottomSheetDialogFragm TextView compactLayoutTextView; @BindView(R.id.gallery_layout_text_view_post_layout_bottom_sheet_fragment) TextView galleryLayoutTextView; + @BindView(R.id.card_layout_2_text_view_post_layout_bottom_sheet_fragment) + TextView cardLayout2TextView; private Activity activity; public PostLayoutBottomSheetFragment() { // Required empty public constructor @@ -55,6 +57,10 @@ public class PostLayoutBottomSheetFragment extends RoundedBottomSheetDialogFragm ((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_GALLERY); dismiss(); }); + cardLayout2TextView.setOnClickListener(view -> { + ((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_2); + dismiss(); + }); return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index d19f905d..86c562fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -65,6 +65,7 @@ public class SharedPreferencesUtils { public static final int POST_LAYOUT_CARD = 0; public static final int POST_LAYOUT_COMPACT = 1; public static final int POST_LAYOUT_GALLERY = 2; + public static final int POST_LAYOUT_CARD_2 = 3; public static final String FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.front_page_scrolled_position"; public static final String FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE = "_front_page"; -- cgit v1.2.3