diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2022-11-12 14:16:27 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2022-11-12 14:16:27 +0000 |
commit | b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5 (patch) | |
tree | a04e7c5bfd5bf8ce2dcf600843de81bcbe8d03a2 /app/src/main/java/ml/docilealligator | |
parent | 03a2784fb885d0ab3a81304ffd11b02ad4d39930 (diff) | |
download | infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar.gz infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar.bz2 infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar.lz infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar.xz infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.tar.zst infinity-for-reddit-b85ed3c867f0c3a2ca0d90e4c29d54ef38c976b5.zip |
Show the current image index in gallery in PostFragment.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
3 files changed, 27 insertions, 14 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/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index a1a4c5bd..81c4c441 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -11,9 +11,7 @@ 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.ViewGroup; import android.widget.FrameLayout; @@ -863,7 +861,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.VISIBLE); ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setImageResource(R.drawable.ic_gallery_24dp); } else { - ((PostGalleryTypeViewHolder) holder).binding.galleryRecyclerViewItemPostGalleryType.setVisibility(View.VISIBLE); + ((PostGalleryTypeViewHolder) holder).binding.galleryFrameLayoutItemPostGalleryType.setVisibility(View.VISIBLE); + ((PostGalleryTypeViewHolder) holder).binding.imageIndexTextViewItemPostGalleryType.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)) { @@ -1890,7 +1889,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((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.galleryFrameLayoutItemPostGalleryType.setVisibility(View.GONE); ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.GONE); } else if (holder instanceof PostTextTypeViewHolder) { ((PostTextTypeViewHolder) holder).contentTextView.setText(""); @@ -3134,6 +3133,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie binding.saveButtonItemPostGalleryType, binding.shareButtonItemPostGalleryType); + binding.imageIndexTextViewItemPostGalleryType.setTextColor(mMediaIndicatorIconTint); + binding.imageIndexTextViewItemPostGalleryType.setBackgroundColor(mMediaIndicatorBackgroundColor); + binding.imageIndexTextViewItemPostGalleryType.setBorderColor(mMediaIndicatorBackgroundColor); + adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale, galleryItemIndex -> { @@ -3149,7 +3152,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter); new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType); binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool); - binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(new SwipeLockLinearLayoutManager( + SwipeLockLinearLayoutManager layoutManager = new SwipeLockLinearLayoutManager( mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { @Override public void lockSwipe() { @@ -3167,17 +3170,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie public void setSwipeLocked(boolean swipeLocked) { PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked; } - })); + }); + binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(layoutManager); + binding.galleryRecyclerViewItemPostGalleryType.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); + binding.imageIndexTextViewItemPostGalleryType.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); + } + }); + binding.getRoot().setOnTouchListener((view, motionEvent) -> { swipeLocked = false; return false; }); - binding.bottomConstraintLayoutItemPostGalleryType.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - swipeLocked = false; - return false; - } + binding.bottomConstraintLayoutItemPostGalleryType.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; }); binding.noPreviewImageViewItemPostGalleryType.setOnClickListener(view -> { 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..72d3e9b7 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 false; } @SuppressLint("ClickableViewAccessibility") // we are just listening to touch events |