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 + .../layout/fragment_post_layot_bottom_sheet.xml | 16 + .../res/layout/item_post_card_2_with_preview.xml | 371 +++++++++++++++++++++ app/src/main/res/layout/item_post_gallery.xml | 112 +++---- app/src/main/res/layout/item_post_with_preview.xml | 13 - app/src/main/res/values/strings.xml | 1 + 8 files changed, 698 insertions(+), 84 deletions(-) create mode 100644 app/src/main/res/layout/item_post_card_2_with_preview.xml (limited to 'app/src') 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"; diff --git a/app/src/main/res/layout/fragment_post_layot_bottom_sheet.xml b/app/src/main/res/layout/fragment_post_layot_bottom_sheet.xml index 760a5ea3..3cf40d28 100644 --- a/app/src/main/res/layout/fragment_post_layot_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_post_layot_bottom_sheet.xml @@ -60,6 +60,22 @@ android:textSize="?attr/font_default" android:fontFamily="?attr/font_family" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_card_2_with_preview.xml b/app/src/main/res/layout/item_post_card_2_with_preview.xml new file mode 100644 index 00000000..8a5fe64e --- /dev/null +++ b/app/src/main/res/layout/item_post_card_2_with_preview.xml @@ -0,0 +1,371 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_gallery.xml b/app/src/main/res/layout/item_post_gallery.xml index 4d40c4d8..3d32cd04 100644 --- a/app/src/main/res/layout/item_post_gallery.xml +++ b/app/src/main/res/layout/item_post_gallery.xml @@ -8,73 +8,67 @@ app:cardElevation="2dp" app:cardCornerRadius="8dp"> - - - - - - - + - + - + - + - + + app:drawableTopCompat="@drawable/ic_error_outline_black_24dp" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/error_loading_image_tap_to_retry" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> - + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_post_with_preview.xml b/app/src/main/res/layout/item_post_with_preview.xml index 5cec4cfa..5782403c 100644 --- a/app/src/main/res/layout/item_post_with_preview.xml +++ b/app/src/main/res/layout/item_post_with_preview.xml @@ -101,19 +101,6 @@ android:textSize="?attr/title_font_18" android:fontFamily="?attr/title_font_family" /> - - Card Layout Compact Layout Gallery Layout + Card Layout 2 Just Now 1 Minute -- cgit v1.2.3