diff options
Diffstat (limited to 'app/src/main')
12 files changed, 1029 insertions, 260 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java index a4feec43..11fd245d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit; import android.content.SharedPreferences; -import android.util.Log; import androidx.annotation.NonNull; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index e0350c63..1c4b8c04 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -169,14 +169,14 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA haulerView.setDragEnabled(false); } - setupViewPager(); + setupViewPager(savedInstanceState); } public boolean isUseBottomAppBar() { return useBottomAppBar; } - private void setupViewPager() { + private void setupViewPager(Bundle savedInstanceState) { if (!useBottomAppBar) { setToolbarTitle(0); viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @@ -189,6 +189,9 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOffscreenPageLimit(3); + if (savedInstanceState == null) { + viewPager.setCurrentItem(getIntent().getIntExtra(EXTRA_GALLERY_ITEM_INDEX, 0), false); + } } private void setToolbarTitle(int position) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index b14d094c..7653ecbf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -1318,12 +1318,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy switch (post.getPostType()) { case Post.IMAGE_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -1391,14 +1391,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy break; } case Post.VIDEO_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); - Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -1421,14 +1421,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy break; } case Post.LINK_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); - Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); @@ -1461,14 +1461,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy break; } case Post.GALLERY_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); - Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java index cbf34984..6d98405a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java @@ -37,19 +37,16 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte private ArrayList<Post.Gallery> galleryImages; private boolean blurImage; private float ratio; - private OnItemClickListener onItemClickListener; public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface, SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy, - int mColorAccent, int mPrimaryTextColor, float scale, - OnItemClickListener onItemClickListener) { + int mColorAccent, int mPrimaryTextColor, float scale) { this.glide = glide; this.typeface = typeface; this.saveMemoryCenterInisdeDownsampleStrategy = saveMemoryCenterInisdeDownsampleStrategy; this.mColorAccent = mColorAccent; this.mPrimaryTextColor = mPrimaryTextColor; this.mScale = scale; - this.onItemClickListener = onItemClickListener; } @NonNull @@ -70,6 +67,17 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte } ((ImageViewHolder) holder).binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); ((ImageViewHolder) holder).binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); + + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); + + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.removeOnLayoutChangeListener(this); + loadImage(((ImageViewHolder) holder)); + } + }); + loadImage((ImageViewHolder) holder); } } @@ -85,7 +93,6 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte } private void loadImage(ImageViewHolder holder) { - holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); RequestBuilder<Drawable> imageRequestBuilder = glide.load(galleryImages.get(holder.getBindingAdapterPosition()).url).listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { @@ -137,10 +144,6 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte binding.progressBarItemGalleryImageInPostFeed.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); binding.errorTextViewItemGalleryImageInPostFeed.setTextColor(mPrimaryTextColor); - binding.imageViewItemGalleryImageInPostFeed.setOnClickListener(view -> { - onItemClickListener.onClick(getBindingAdapterPosition()); - }); - binding.errorTextViewItemGalleryImageInPostFeed.setOnClickListener(view -> { binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); @@ -148,8 +151,4 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte }); } } - - public interface OnItemClickListener { - void onClick(int galleryItemIndex); - } } 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 a1a4c5bd..182204e5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -11,10 +11,10 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; @@ -34,7 +34,6 @@ import androidx.core.content.ContextCompat; import androidx.paging.PagingDataAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; -import androidx.recyclerview.widget.LinearSnapHelper; import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; @@ -87,6 +86,8 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; +import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment; @@ -118,9 +119,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 4; private static final int VIEW_TYPE_POST_COMPACT = 5; private static final int VIEW_TYPE_POST_GALLERY = 6; - private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 7; - private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 8; - private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 9; + private static final int VIEW_TYPE_POST_GALLERY_GALLERY_TYPE = 7; + private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 8; + private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 9; + private static final int VIEW_TYPE_POST_CARD_2_GALLERY_TYPE = 10; + private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 11; private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() { @Override @@ -414,7 +417,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } return VIEW_TYPE_POST_COMPACT; } else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_GALLERY) { - return VIEW_TYPE_POST_GALLERY; + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.GALLERY_TYPE) { + return VIEW_TYPE_POST_GALLERY_GALLERY_TYPE; + } else { + return VIEW_TYPE_POST_GALLERY; + } + } else { + return VIEW_TYPE_POST_GALLERY; + } } else { Post post = getItem(position); if (post != null) { @@ -429,8 +441,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE; case Post.GIF_TYPE: case Post.IMAGE_TYPE: - case Post.GALLERY_TYPE: return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE; + case Post.GALLERY_TYPE: + return VIEW_TYPE_POST_CARD_2_GALLERY_TYPE; case Post.LINK_TYPE: case Post.NO_PREVIEW_LINK_TYPE: switch (mDefaultLinkPostLayout) { @@ -472,6 +485,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } else if (viewType == VIEW_TYPE_POST_GALLERY) { return new PostGalleryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_gallery, parent, false)); + } else if (viewType == VIEW_TYPE_POST_GALLERY_GALLERY_TYPE) { + return new PostGalleryGalleryTypeViewHolder(ItemPostGalleryGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE) { if (mDataSavingMode) { return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false)); @@ -479,6 +494,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return new PostCard2VideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(mLegacyAutoplayVideoControllerUI ? R.layout.item_post_card_2_video_autoplay_legacy_controller : R.layout.item_post_card_2_video_autoplay, parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE) { return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false)); + } else if (viewType == VIEW_TYPE_POST_CARD_2_GALLERY_TYPE) { + return new PostCard2GalleryTypeViewHolder(ItemPostCard2GalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { //VIEW_TYPE_POST_CARD_2_TEXT_TYPE return new PostCard2TextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_text, parent, false)); @@ -858,24 +875,25 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } } - } else if (holder instanceof PostGalleryTypeViewHolder) { + } else if (holder instanceof PostBaseGalleryTypeViewHolder) { if (mDataSavingMode && mDisableImagePreview) { - ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.VISIBLE); - ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setImageResource(R.drawable.ic_gallery_24dp); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } else { - ((PostGalleryTypeViewHolder) holder).binding.galleryRecyclerViewItemPostGalleryType.setVisibility(View.VISIBLE); + ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); + ((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size())); Post.Preview preview = getSuitablePreview(post.getPreviews()); if (preview != null) { if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - ((PostGalleryTypeViewHolder) holder).adapter.setRatio(-1); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } else { - ((PostGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } } else { - ((PostGalleryTypeViewHolder) holder).adapter.setRatio(-1); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } - ((PostGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); - ((PostGalleryTypeViewHolder) holder).adapter.setBlurImage( + ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); } } else if (holder instanceof PostTextTypeViewHolder) { @@ -1392,50 +1410,86 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor); } - switch (post.getPostType()) { - case Post.IMAGE_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + if (mDataSavingMode && (mDisableImagePreview || + ((post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) && mOnlyDisablePreviewInVideoAndGifPosts))) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + if (post.getPostType() == Post.VIDEO_TYPE) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); + } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); + } else if (post.getPostType() == Post.LINK_TYPE) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + } else if (post.getPostType() == Post.GALLERY_TYPE) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + } + } else { + switch (post.getPostType()) { + case Post.IMAGE_TYPE: { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; + if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostGalleryViewHolder) holder).preview = preview; - if (preview != null) { - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + loadImage(holder); + } + }); } else { - ((PostGalleryViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); + break; + } + case Post.GIF_TYPE: { + if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + } else { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; + if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + loadImage(holder); + } + }); + } else { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); } - }); - } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - if (post.getPostType() == Post.VIDEO_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else if (post.getPostType() == Post.LINK_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + break; } - break; - } - case Post.GIF_TYPE: { - if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); - } else { + case Post.VIDEO_TYPE: { Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { @@ -1461,111 +1515,83 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie }); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); } + break; } - break; - } - case Post.VIDEO_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + case Post.LINK_TYPE: { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; + if (preview != null) { + ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostGalleryViewHolder) holder).preview = preview; - if (preview != null) { - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; - } else { - ((PostGalleryViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - }); - } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - } - break; - } - case Post.LINK_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); - - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostGalleryViewHolder) holder).preview = preview; - if (preview != null) { - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { + ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + loadImage(holder); + } + }); } else { - ((PostGalleryViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); - } - }); - } else { + break; + } + case Post.NO_PREVIEW_LINK_TYPE: { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + break; + } + case Post.TEXT_TYPE: { + ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle()); + break; } - break; - } - case Post.NO_PREVIEW_LINK_TYPE: { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); - break; - } - case Post.TEXT_TYPE: { - ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle()); - break; } - case Post.GALLERY_TYPE: { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); + } + } + } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) { + Post post = getItem(position); + if (post != null) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).post = post; + ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition = position; + if (post.isRead()) { + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + } - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostGalleryViewHolder) holder).preview = preview; - if (preview != null) { - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; - } else { - ((PostGalleryViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); - } - }); + if (mDataSavingMode && mDisableImagePreview) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + } else { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryBaseGalleryTypeViewHolder) holder).preview = preview; + + ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size())); + if (preview != null) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - break; + } else { + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( + (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); } } } @@ -1889,9 +1915,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).linkTextView.setVisibility(View.GONE); - } else if (holder instanceof PostGalleryTypeViewHolder) { - ((PostGalleryTypeViewHolder) holder).binding.galleryRecyclerViewItemPostGalleryType.setVisibility(View.GONE); - ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.GONE); + } else if (holder instanceof PostBaseGalleryTypeViewHolder) { + ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); } else if (holder instanceof PostTextTypeViewHolder) { ((PostTextTypeViewHolder) holder).contentTextView.setText(""); ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); @@ -1984,6 +2010,17 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).errorTextView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); + } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) { + if (mMarkPostsAsReadOnScroll) { + int position = ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition; + if (position < super.getItemCount() && position >= 0) { + Post post = getItem(position); + ((PostGalleryBaseGalleryTypeViewHolder) holder).markPostRead(post, false); + } + } + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); } } @@ -3103,53 +3140,85 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } - public class PostGalleryTypeViewHolder extends PostBaseViewHolder { - ItemPostGalleryTypeBinding binding; + public class PostBaseGalleryTypeViewHolder extends PostBaseViewHolder { + FrameLayout frameLayout; + RecyclerView galleryRecyclerView; + CustomTextView imageIndexTextView; + ImageView noPreviewImageView; + PostGalleryTypeImageRecyclerViewAdapter adapter; private boolean swipeLocked; - PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding binding) { - super(binding.getRoot()); - this.binding = binding; + PostBaseGalleryTypeViewHolder(View rootView, + AspectRatioGifImageView iconGifImageView, + TextView subredditTextView, + TextView userTextView, + ImageView stickiedPostImageView, + TextView postTimeTextView, + TextView titleTextView, + CustomTextView typeTextView, + ImageView archivedImageView, + ImageView lockedImageView, + ImageView crosspostImageView, + CustomTextView nsfwTextView, + CustomTextView spoilerTextView, + CustomTextView flairTextView, + CustomTextView awardsTextView, + FrameLayout frameLayout, + RecyclerView galleryRecyclerView, + CustomTextView imageIndexTextView, + ImageView noPreviewImageView, + ConstraintLayout bottomConstraintLayout, + ImageView upvoteButton, + TextView scoreTextView, + ImageView downvoteButton, + TextView commentsCountTextView, + ImageView saveButton, + ImageView shareButton, + boolean itemViewIsNotCardView) { + super(rootView); setBaseView( - binding.iconGifImageViewItemPostGalleryType, - binding.subredditNameTextViewItemPostGalleryType, - binding.userTextViewItemPostGalleryType, - binding.stickiedPostImageViewItemPostGalleryType, - binding.postTimeTextViewItemPostGalleryType, - binding.titleTextViewItemPostGalleryType, - binding.typeTextViewItemPostGalleryType, - binding.archivedImageViewItemPostGalleryType, - binding.lockedImageViewItemPostGalleryType, - binding.crosspostImageViewItemPostGalleryType, - binding.nsfwTextViewItemPostGalleryType, - binding.spoilerTextViewItemPostGalleryType, - binding.flairTextViewItemPostGalleryType, - binding.awardsTextViewItemPostGalleryType, - binding.bottomConstraintLayoutItemPostGalleryType, - binding.upvoteButtonItemPostGalleryType, - binding.scoreTextViewItemPostGalleryType, - binding.downvoteButtonItemPostGalleryType, - binding.commentsCountTextViewItemPostGalleryType, - binding.saveButtonItemPostGalleryType, - binding.shareButtonItemPostGalleryType); + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + typeTextView, + archivedImageView, + lockedImageView, + crosspostImageView, + nsfwTextView, + spoilerTextView, + flairTextView, + awardsTextView, + bottomConstraintLayout, + upvoteButton, + scoreTextView, + downvoteButton, + commentsCountTextView, + saveButton, + shareButton, + itemViewIsNotCardView); + + this.frameLayout = frameLayout; + this.galleryRecyclerView = galleryRecyclerView; + this.imageIndexTextView = imageIndexTextView; + this.noPreviewImageView = noPreviewImageView; + + imageIndexTextView.setTextColor(mMediaIndicatorIconTint); + imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); + imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); + + noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, - mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale, - galleryItemIndex -> { - int position = getBindingAdapterPosition(); - if (position < 0) { - return; - } - if (post != null) { - markPostRead(post, true); - openMedia(post, galleryItemIndex); - } - }); - binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter); - new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType); - binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool); - binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(new SwipeLockLinearLayoutManager( + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); + galleryRecyclerView.setAdapter(adapter); + new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); + galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + SwipeLockLinearLayoutManager layoutManager = new SwipeLockLinearLayoutManager( mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { @Override public void lockSwipe() { @@ -3165,22 +3234,81 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void setSwipeLocked(boolean swipeLocked) { - PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked; + PostBaseGalleryTypeViewHolder.this.swipeLocked = swipeLocked; } - })); - binding.getRoot().setOnTouchListener((view, motionEvent) -> { - swipeLocked = false; - return false; }); - binding.bottomConstraintLayoutItemPostGalleryType.setOnTouchListener(new View.OnTouchListener() { + galleryRecyclerView.setLayoutManager(layoutManager); + galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - swipeLocked = false; + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + } + + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); + } + }); + galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + private float downX; + private float downY; + private boolean dragged; + private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + + @Override + public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + int action = e.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + downX = e.getRawX(); + downY = e.getRawY(); + break; + case MotionEvent.ACTION_MOVE: + if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + int index = layoutManager.findFirstVisibleItemPosition(); + int position = getBindingAdapterPosition(); + if (position >= 0) { + if (post != null) { + markPostRead(post, true); + openMedia(post, index); + } + } + } + + downX = 0; + downY = 0; + dragged = false; + } return false; } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + rootView.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + bottomConstraintLayout.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; }); - binding.noPreviewImageViewItemPostGalleryType.setOnClickListener(view -> { + noPreviewImageView.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position < 0) { return; @@ -3197,6 +3325,39 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } + public class PostGalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { + + PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostGalleryType, + binding.subredditNameTextViewItemPostGalleryType, + binding.userTextViewItemPostGalleryType, + binding.stickiedPostImageViewItemPostGalleryType, + binding.postTimeTextViewItemPostGalleryType, + binding.titleTextViewItemPostGalleryType, + binding.typeTextViewItemPostGalleryType, + binding.archivedImageViewItemPostGalleryType, + binding.lockedImageViewItemPostGalleryType, + binding.crosspostImageViewItemPostGalleryType, + binding.nsfwTextViewItemPostGalleryType, + binding.spoilerTextViewItemPostGalleryType, + binding.flairTextViewItemPostGalleryType, + binding.awardsTextViewItemPostGalleryType, + binding.galleryFrameLayoutItemPostGalleryType, + binding.galleryRecyclerViewItemPostGalleryType, + binding.imageIndexTextViewItemPostGalleryType, + binding.noPreviewImageViewItemPostGalleryType, + binding.bottomConstraintLayoutItemPostGalleryType, + binding.upvoteButtonItemPostGalleryType, + binding.scoreTextViewItemPostGalleryType, + binding.downvoteButtonItemPostGalleryType, + binding.commentsCountTextViewItemPostGalleryType, + binding.saveButtonItemPostGalleryType, + binding.shareButtonItemPostGalleryType, + false); + } + } + class PostTextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_text_type) AspectRatioGifImageView iconGifImageView; @@ -4109,6 +4270,199 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } + class PostGalleryBaseGalleryTypeViewHolder extends RecyclerView.ViewHolder { + + FrameLayout frameLayout; + RecyclerView recyclerView; + CustomTextView imageIndexTextView; + ImageView noPreviewImageView; + + PostGalleryTypeImageRecyclerViewAdapter adapter; + private boolean swipeLocked; + + Post post; + Post.Preview preview; + + int currentPosition; + + public PostGalleryBaseGalleryTypeViewHolder(@NonNull View itemView, + FrameLayout frameLayout, + RecyclerView recyclerView, + CustomTextView imageIndexTextView, + ImageView noPreviewImageView) { + super(itemView); + + this.frameLayout = frameLayout; + this.recyclerView = recyclerView; + this.imageIndexTextView = imageIndexTextView; + this.noPreviewImageView = noPreviewImageView; + + if (mActivity.typeface != null) { + imageIndexTextView.setTypeface(mActivity.typeface); + } + + itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + + imageIndexTextView.setTextColor(mMediaIndicatorIconTint); + imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); + imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); + + adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); + recyclerView.setAdapter(adapter); + new PagerSnapHelper().attachToRecyclerView(recyclerView); + recyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + SwipeLockLinearLayoutManager layoutManager = new SwipeLockLinearLayoutManager( + mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { + @Override + public void lockSwipe() { + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; + } + + @Override + public void unlockSwipe() { + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } + + @Override + public void setSwipeLocked(boolean swipeLocked) { + PostGalleryBaseGalleryTypeViewHolder.this.swipeLocked = swipeLocked; + } + }); + recyclerView.setLayoutManager(layoutManager); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + } + + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); + } + }); + recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + private float downX; + private float downY; + private boolean dragged; + private long downTime; + private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + private final int longClickThreshold = ViewConfiguration.getLongPressTimeout(); + + @Override + public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + int action = e.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + downX = e.getRawX(); + downY = e.getRawY(); + downTime = System.currentTimeMillis(); + break; + case MotionEvent.ACTION_MOVE: + if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + if (!dragged) { + if (System.currentTimeMillis() - downTime >= longClickThreshold) { + onLongClick(); + } + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + if (System.currentTimeMillis() - downTime < longClickThreshold) { + onClick(); + } + } + case MotionEvent.ACTION_CANCEL: + downX = 0; + downY = 0; + dragged = false; + + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + noPreviewImageView.setOnClickListener(view -> { + onClick(); + }); + + noPreviewImageView.setOnLongClickListener(view -> onLongClick()); + } + + void onClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); + + if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post); + } + } + } + } + + boolean onLongClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); + + if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post); + } + } + } + + return true; + } + + void markPostRead(Post post, boolean changePostItemColor) { + if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { + post.markAsRead(true); + if (changePostItemColor) { + itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + } + if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { + ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); + mFragment.markPostAsRead(post); + } + } + } + } + + class PostGalleryGalleryTypeViewHolder extends PostGalleryBaseGalleryTypeViewHolder { + + public PostGalleryGalleryTypeViewHolder(@NonNull ItemPostGalleryGalleryTypeBinding binding) { + super(binding.getRoot(), binding.galleryFrameLayoutItemPostGalleryGalleryType, + binding.galleryRecyclerViewItemPostGalleryGalleryType, binding.imageIndexTextViewItemPostGalleryGalleryType, + binding.imageViewNoPreviewItemPostGalleryGalleryType); + } + } + class PostCard2VideoAutoplayViewHolder extends PostBaseViewHolder implements ToroPlayer { @BindView(R.id.icon_gif_image_view_item_post_card_2_video_autoplay) AspectRatioGifImageView iconGifImageView; @@ -4515,6 +4869,41 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } + public class PostCard2GalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { + + PostCard2GalleryTypeViewHolder(ItemPostCard2GalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostCard2GalleryType, + binding.subredditNameTextViewItemPostCard2GalleryType, + binding.userTextViewItemPostCard2GalleryType, + binding.stickiedPostImageViewItemPostCard2GalleryType, + binding.postTimeTextViewItemPostCard2GalleryType, + binding.titleTextViewItemPostCard2GalleryType, + binding.typeTextViewItemPostCard2GalleryType, + binding.archivedImageViewItemPostCard2GalleryType, + binding.lockedImageViewItemPostCard2GalleryType, + binding.crosspostImageViewItemPostCard2GalleryType, + binding.nsfwTextViewItemPostCard2GalleryType, + binding.spoilerCustomTextViewItemPostCard2GalleryType, + binding.flairCustomTextViewItemPostCard2GalleryType, + binding.awardsTextViewItemPostCard2GalleryType, + binding.galleryFrameLayoutItemPostCard2GalleryType, + binding.galleryRecyclerViewItemPostCard2GalleryType, + binding.imageIndexTextViewItemPostCard2GalleryType, + binding.noPreviewImageViewItemPostCard2GalleryType, + binding.bottomConstraintLayoutItemPostCard2GalleryType, + binding.upvoteButtonItemPostCard2GalleryType, + binding.scoreTextViewItemPostCard2GalleryType, + binding.downvoteButtonItemPostCard2GalleryType, + binding.commentsCountTextViewItemPostCard2GalleryType, + binding.saveButtonItemPostCard2GalleryType, + binding.shareButtonItemPostCard2GalleryType, + true); + + binding.dividerItemPostCard2GalleryType.setBackgroundColor(mDividerColor); + } + } + class PostCard2TextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_card_2_text) AspectRatioGifImageView iconGifImageView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java index 97d29022..5b62bbfb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java @@ -38,7 +38,7 @@ public class SwipeLockFrameLayout extends FrameLayout implements SwipeLockView { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { updateSwipeLock(ev); - return true; + return locked; } @SuppressLint("ClickableViewAccessibility") // we are just listening to touch events diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 32c98b04..cb3f1694 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -16,6 +16,7 @@ import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; +import android.util.Log; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -1057,8 +1058,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (!(viewHolder instanceof PostRecyclerViewAdapter.PostBaseViewHolder) && !(viewHolder instanceof PostRecyclerViewAdapter.PostCompactBaseViewHolder)) { return makeMovementFlags(0, 0); - } else if (viewHolder instanceof PostRecyclerViewAdapter.PostGalleryTypeViewHolder) { - if (((PostRecyclerViewAdapter.PostGalleryTypeViewHolder) viewHolder).isSwipeLocked()) { + } else if (viewHolder instanceof PostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) { + if (((PostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) viewHolder).isSwipeLocked()) { return makeMovementFlags(0, 0); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java index a22ad6fd..464b6d9f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilter.java @@ -357,12 +357,12 @@ public class PostFilter implements Parcelable { postFilter.containDomains = stringBuilder.toString(); } - postFilter.containTextType = p.containTextType || postFilter.containTextType; - postFilter.containLinkType = p.containLinkType || postFilter.containLinkType; - postFilter.containImageType = p.containImageType || postFilter.containImageType; - postFilter.containGifType = p.containGifType || postFilter.containGifType; - postFilter.containVideoType = p.containVideoType || postFilter.containVideoType; - postFilter.containGalleryType = p.containGalleryType || postFilter.containGalleryType; + postFilter.containTextType = p.containTextType && postFilter.containTextType; + postFilter.containLinkType = p.containLinkType && postFilter.containLinkType; + postFilter.containImageType = p.containImageType && postFilter.containImageType; + postFilter.containGifType = p.containGifType && postFilter.containGifType; + postFilter.containVideoType = p.containVideoType && postFilter.containVideoType; + postFilter.containGalleryType = p.containGalleryType && postFilter.containGalleryType; } return postFilter; diff --git a/app/src/main/res/layout/item_post_card_2_gallery_type.xml b/app/src/main/res/layout/item_post_card_2_gallery_type.xml new file mode 100644 index 00000000..1455d1fd --- /dev/null +++ b/app/src/main/res/layout/item_post_card_2_gallery_type.xml @@ -0,0 +1,309 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + xmlns:tools="http://schemas.android.com/tools" + android:paddingTop="16dp" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground" + android:orientation="vertical"> + + <com.google.android.material.card.MaterialCardView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + app:cardElevation="2dp" + app:cardCornerRadius="8dp" + style="?attr/materialCardViewElevatedStyle"> + + <FrameLayout + android:id="@+id/gallery_frame_layout_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/gallery_recycler_view_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" /> + + <com.libRG.CustomTextView + android:id="@+id/image_index_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + </FrameLayout> + + <ImageView + android:id="@+id/no_preview_image_view_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="150dp" + android:scaleType="center" + android:visibility="gone" /> + + </com.google.android.material.card.MaterialCardView> + + <TextView + android:id="@+id/title_text_view_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:textSize="?attr/title_font_18" + android:fontFamily="?attr/title_font_family" /> + + <com.nex3z.flowlayout.FlowLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="16dp" + app:flRowVerticalGravity="center" + app:flChildSpacing="16dp" + app:flChildSpacingForLastRow="align" + app:flRowSpacing="8dp"> + + <com.libRG.CustomTextView + android:id="@+id/type_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="4dp" + android:text="@string/gallery" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + <com.libRG.CustomTextView + android:id="@+id/spoiler_custom_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/spoiler" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + android:visibility="gone" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + <com.libRG.CustomTextView + android:id="@+id/nsfw_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="4dp" + android:text="@string/nsfw" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:visibility="gone" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + <com.libRG.CustomTextView + android:id="@+id/flair_custom_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + android:visibility="gone" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + <com.libRG.CustomTextView + android:id="@+id/awards_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="4dp" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:visibility="gone" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + <ImageView + android:id="@+id/archived_image_view_item_post_card_2_gallery_type" + android:layout_width="24dp" + android:layout_height="24dp" + android:src="@drawable/ic_archive_outline" + android:visibility="gone" /> + + <ImageView + android:id="@+id/locked_image_view_item_post_card_2_gallery_type" + android:layout_width="24dp" + android:layout_height="24dp" + android:src="@drawable/ic_outline_lock_24dp" + android:visibility="gone" /> + + <ImageView + android:id="@+id/crosspost_image_view_item_post_card_2_gallery_type" + android:layout_width="24dp" + android:layout_height="24dp" + android:src="@drawable/crosspost" + android:visibility="gone" /> + + <ImageView + android:id="@+id/stickied_post_image_view_item_post_card_2_gallery_type" + android:layout_width="24dp" + android:layout_height="24dp" + android:visibility="gone" + tools:visibility="visible" /> + + <TextView + android:id="@+id/link_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:visibility="gone" /> + + <TextView + android:id="@+id/post_time_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> + + </com.nex3z.flowlayout.FlowLayout> + + <com.nex3z.flowlayout.FlowLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="16dp" + android:paddingEnd="16dp" + app:flRowVerticalGravity="center" + app:flChildSpacing="16dp" + app:flChildSpacingForLastRow="align" + app:flRowSpacing="8dp"> + + <ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView + android:id="@+id/icon_gif_image_view_item_post_card_2_gallery_type" + android:layout_width="24dp" + android:layout_height="24dp" /> + + <TextView + android:id="@+id/subreddit_name_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> + + <TextView + android:id="@+id/user_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> + + </com.nex3z.flowlayout.FlowLayout> + + <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/bottom_constraint_layout_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <ImageView + android:id="@+id/upvote_button_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:src="@drawable/ic_arrow_upward_grey_24dp" + android:background="?actionBarItemBackground" + android:clickable="true" + android:focusable="true" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + + <TextView + android:id="@+id/score_text_view_item_post_card_2_gallery_type" + android:layout_width="64dp" + android:layout_height="wrap_content" + android:gravity="center" + android:textSize="?attr/font_12" + android:textStyle="bold" + android:fontFamily="?attr/font_family" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/upvote_button_item_post_card_2_gallery_type" /> + + <ImageView + android:id="@+id/downvote_button_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:src="@drawable/ic_arrow_downward_grey_24dp" + android:background="?actionBarItemBackground" + android:clickable="true" + android:focusable="true" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/score_text_view_item_post_card_2_gallery_type" /> + + <TextView + android:id="@+id/comments_count_text_view_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:gravity="center_vertical" + android:textSize="?attr/font_12" + android:textStyle="bold" + android:fontFamily="?attr/font_family" + android:drawableStart="@drawable/ic_comment_grey_24dp" + android:drawablePadding="12dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/downvote_button_item_post_card_2_gallery_type" /> + + <ImageView + android:id="@+id/save_button_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:background="?actionBarItemBackground" + android:clickable="true" + android:focusable="true" + app:layout_constraintHorizontal_bias="1" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/comments_count_text_view_item_post_card_2_gallery_type" + app:layout_constraintEnd_toStartOf="@id/share_button_item_post_card_2_gallery_type" /> + + <ImageView + android:id="@+id/share_button_item_post_card_2_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:src="@drawable/ic_share_grey_24dp" + android:background="?actionBarItemBackground" + android:clickable="true" + android:focusable="true" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" /> + + </androidx.constraintlayout.widget.ConstraintLayout> + + <View + android:id="@+id/divider_item_post_card_2_gallery_type" + android:layout_width="match_parent" + android:layout_height="1dp" + android:paddingBottom="8dp" /> + +</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_post_gallery_gallery_type.xml b/app/src/main/res/layout/item_post_gallery_gallery_type.xml new file mode 100644 index 00000000..d1ee61b6 --- /dev/null +++ b/app/src/main/res/layout/item_post_gallery_gallery_type.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="wrap_content" + xmlns:tools="http://schemas.android.com/tools" + android:layout_marginTop="8dp" + android:layout_marginBottom="8dp" + app:cardElevation="2dp" + app:cardCornerRadius="8dp" + style="?attr/materialCardViewElevatedStyle"> + + <FrameLayout + android:id="@+id/gallery_frame_layout_item_post_gallery_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/gallery_recycler_view_item_post_gallery_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" /> + + <com.libRG.CustomTextView + android:id="@+id/image_index_text_view_item_post_gallery_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + </FrameLayout> + + <ImageView + android:id="@+id/image_view_no_preview_item_post_gallery_gallery_type" + android:layout_width="match_parent" + android:layout_height="150dp" + android:scaleType="center" + android:background="@drawable/thumbnail_compact_layout_rounded_edge" + android:visibility="gone" /> + +</com.google.android.material.card.MaterialCardView>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_post_gallery_type.xml b/app/src/main/res/layout/item_post_gallery_type.xml index 4ea4579c..13bd9517 100644 --- a/app/src/main/res/layout/item_post_gallery_type.xml +++ b/app/src/main/res/layout/item_post_gallery_type.xml @@ -196,11 +196,31 @@ </com.nex3z.flowlayout.FlowLayout> - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/gallery_recycler_view_item_post_gallery_type" + <FrameLayout + android:id="@+id/gallery_frame_layout_item_post_gallery_type" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" /> + android:visibility="gone"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/gallery_recycler_view_item_post_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" /> + + <com.libRG.CustomTextView + android:id="@+id/image_index_text_view_item_post_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + </FrameLayout> <ImageView android:id="@+id/no_preview_image_view_item_post_gallery_type" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7bb044b..bdcba30e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,12 +25,12 @@ <string name="edit_multi_reddit_activity_label">Edit Multireddit</string> <string name="selected_subeddits_activity_label">Selected Subreddits</string> <string name="report_activity_label">Report</string> - <string name="view_imgur_media_activity_image_label">Image %1$,d/%2$d</string> - <string name="view_imgur_media_activity_video_label">Video %1$,d/%2$d</string> + <string name="view_imgur_media_activity_image_label">Image %1$d/%2$d</string> + <string name="view_imgur_media_activity_video_label">Video %1$d/%2$d</string> <string name="send_private_message_activity_label">Send PM</string> - <string name="view_reddit_gallery_activity_image_label">Image %1$,d/%2$d</string> - <string name="view_reddit_gallery_activity_gif_label">Gif %1$,d/%2$d</string> - <string name="view_reddit_gallery_activity_video_label">Video %1$,d/%2$d</string> + <string name="view_reddit_gallery_activity_image_label">Image %1$d/%2$d</string> + <string name="view_reddit_gallery_activity_gif_label">Gif %1$d/%2$d</string> + <string name="view_reddit_gallery_activity_video_label">Video %1$d/%2$d</string> <string name="submit_crosspost_activity_label">Crosspost</string> <string name="give_award_activity_label">Give Award</string> <string name="subreddit_filter_popular_and_all_activity_label">r/all and r/popular</string> @@ -201,7 +201,7 @@ <string name="title_required">The post needs a good title</string> <string name="link_required">Hey where is the link?</string> <string name="select_an_image">Please select an image first</string> - <string name="voting_length">Voting length: %1$,d days</string> + <string name="voting_length">Voting length: %1$d days</string> <string name="posting">Posting</string> <string name="post_failed">Could not post it</string> <string name="error_processing_image">Error processing image</string> @@ -358,7 +358,7 @@ <string name="notification_summary_message">New Message</string> <string name="notification_summary_subreddit">Subreddit</string> <string name="notification_summary_award">Award</string> - <string name="notification_new_messages">%1$,d New Messages</string> + <string name="notification_new_messages">%1$d New Messages</string> <string name="label_account">Account</string> <string name="label_reddit">Reddit</string> @@ -382,9 +382,9 @@ <string name="settings_mute_autoplaying_videos_title">Mute Autoplaying Videos</string> <string name="settings_autoplay_nsfw_videos_title">Autoplay NSFW Videos</string> <string name="settings_start_autoplay_visible_area_offset_portrait_title">Autoplay Videos Visible Area Offset (Portrait)</string> - <string name="settings_start_autoplay_visible_area_offset_portrait_summary">Start autoplaying videos when %1$,d%% of them are visible</string> + <string name="settings_start_autoplay_visible_area_offset_portrait_summary">Start autoplaying videos when %1$d%% of them are visible</string> <string name="settings_start_autoplay_visible_area_offset_landscape_title">Autoplay Videos Visible Area Offset (Landscape)</string> - <string name="settings_start_autoplay_visible_area_offset_landscape_summary">Start autoplaying videos when %1$,d%% of them are visible</string> + <string name="settings_start_autoplay_visible_area_offset_landscape_summary">Start autoplaying videos when %1$d%% of them are visible</string> <string name="settings_immersive_interface_title">Immersive Interface</string> <string name="settings_immersive_interface_summary">Does Not Apply to All Pages</string> <string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string> @@ -636,7 +636,7 @@ <string name="settings_hide_text_post_content">Hide Text Post Content</string> <string name="settings_hide_comment_awards_title">Hide Comment Awards</string> <string name="settings_show_fewer_toolbar_options_threshold_title">Show Fewer Toolbar Options Starting From</string> - <string name="settings_show_fewer_toolbar_options_threshold_summary">Level %1$,d</string> + <string name="settings_show_fewer_toolbar_options_threshold_summary">Level %1$d</string> <string name="settings_show_author_avatar_title">Show Author Avatar</string> <string name="settings_reddit_user_agreement_title">Reddit User Agreement</string> <string name="settings_always_show_child_comment_count_title">Always Show the Number of Child Comments</string> @@ -688,15 +688,15 @@ <string name="elapsed_time_just_now">Just Now</string> <string name="elapsed_time_a_minute_ago">1 Minute</string> - <string name="elapsed_time_minutes_ago">%1$,d Minutes</string> + <string name="elapsed_time_minutes_ago">%1$d Minutes</string> <string name="elapsed_time_an_hour_ago">1 Hour</string> - <string name="elapsed_time_hours_ago">%1$,d Hours</string> + <string name="elapsed_time_hours_ago">%1$d Hours</string> <string name="elapsed_time_yesterday">Yesterday</string> - <string name="elapsed_time_days_ago">%1$,d Days</string> + <string name="elapsed_time_days_ago">%1$d Days</string> <string name="elapsed_time_a_month_ago">1 Month</string> - <string name="elapsed_time_months_ago">%1$,d Months</string> + <string name="elapsed_time_months_ago">%1$d Months</string> <string name="elapsed_time_a_year_ago">1 Year</string> - <string name="elapsed_time_years_ago">%1$,d Years</string> + <string name="elapsed_time_years_ago">%1$d Years</string> <string name="error_getting_multi_reddit_data">Error getting multireddit data</string> <string name="error_loading_multi_reddit_list">Cannot sync multireddits</string> @@ -1077,7 +1077,7 @@ <string name="give_award_dialog_title">Give Award?</string> <string name="anonymous">Anonymous</string> - <string name="give_award_error_message">Code: %1$,d/\n Message: %2$s</string> + <string name="give_award_error_message">Code: %1$d/\n Message: %2$s</string> <string name="give_award_success">Award given</string> <string name="give_award_failed">Failed</string> @@ -1315,4 +1315,6 @@ <string name="load_more_posts_failed">Failed to load more posts.\nTap to retry.</string> <string name="no_more_posts">No more posts</string> + <string name="image_index_in_gallery">%1$d/%2$d</string> + </resources> |