diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-07-16 13:01:39 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-07-16 13:01:39 +0000 |
commit | 45181aa712dc248686c50bda6249e3811d68ba1d (patch) | |
tree | b486197c67108c7042a164ad4e4517be7caacca7 /app/src | |
parent | b382ebecc3703569fff15d93bba90ad36f1f1298 (diff) | |
download | infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar.gz infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar.bz2 infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar.lz infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar.xz infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.tar.zst infinity-for-reddit-45181aa712dc248686c50bda6249e3811d68ba1d.zip |
Add column spacing to the RecyclerView in PostGalleryActivity.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java | 34 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_post_gallery.xml | 4 |
2 files changed, 37 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index e5410ff1..d296688f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -3,8 +3,10 @@ package ml.docilealligator.infinityforreddit.activities; import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; +import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -24,6 +26,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; +import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -70,6 +73,7 @@ import ml.docilealligator.infinityforreddit.services.SubmitPostService; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.UploadImageUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -220,6 +224,36 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee } }); imagesRecyclerView.setAdapter(adapter); + Resources resources = getResources(); + int nColumns = resources.getBoolean(R.bool.isTablet) || resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2; + ((GridLayoutManager) imagesRecyclerView.getLayoutManager()).setSpanCount(nColumns); + imagesRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { + @Override + public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams(); + + int spanIndex = layoutParams.getSpanIndex(); + + int offset = (int) (Utils.convertDpToPixel(16, PostGalleryActivity.this)); + int halfOffset = offset / 2; + + if (nColumns == 2) { + if (spanIndex == 0) { + outRect.set(halfOffset, 0, halfOffset, offset); + } else { + outRect.set(halfOffset, 0, halfOffset, offset); + } + } else if (nColumns == 3) { + if (spanIndex == 0) { + outRect.set(halfOffset, 0, halfOffset, offset); + } else if (spanIndex == 1) { + outRect.set(halfOffset, 0, halfOffset, offset); + } else { + outRect.set(halfOffset, 0, halfOffset, offset); + } + } + } + }); if (savedInstanceState != null) { subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); diff --git a/app/src/main/res/layout/activity_post_gallery.xml b/app/src/main/res/layout/activity_post_gallery.xml index 80f87dc1..150870e0 100644 --- a/app/src/main/res/layout/activity_post_gallery.xml +++ b/app/src/main/res/layout/activity_post_gallery.xml @@ -191,7 +191,9 @@ android:id="@+id/images_recycler_view_post_gallery_activity" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingStart="8dp" + android:paddingEnd="8dp" app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" app:spanCount="2" /> |