aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-02-19 08:48:25 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-02-19 08:48:25 +0000
commit800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff (patch)
tree3c25da51ed7d95eea7cf64708b899be41b045db6 /app/src/main
parent719a5a3a8e3f3ee4eca4f33f8e709f8eaf65ad33 (diff)
downloadinfinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar.gz
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar.bz2
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar.lz
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar.xz
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.tar.zst
infinity-for-reddit-800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff.zip
Add Gallery Layout to default post layout option. 3 columns is available in PostFragment.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java43
-rw-r--r--app/src/main/res/values/arrays.xml1
2 files changed, 30 insertions, 14 deletions
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 cbce964b..dc0fa55f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -733,10 +733,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mLinearLayoutManager = new LinearLayoutManager(activity);
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
} else {
- mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
+ mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL);
mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration =
- new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset);
+ new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns);
mPostRecyclerView.addItemDecoration(itemDecoration);
windowWidth /= 2;
}
@@ -1117,7 +1117,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (mLinearLayoutManager != null) {
outState.putInt(RECYCLER_VIEW_POSITION_STATE, mLinearLayoutManager.findFirstVisibleItemPosition());
} else if (mStaggeredGridLayoutManager != null) {
- int[] into = new int[2];
+ int[] into = new int[mStaggeredGridLayoutManager.getSpanCount()];
outState.putInt(RECYCLER_VIEW_POSITION_STATE,
mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0]);
}
@@ -1275,16 +1275,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
int nColumns = getNColumns(getResources());
if (nColumns == 1) {
mLinearLayoutManager = new LinearLayoutManager(activity);
+ if (mPostRecyclerView.getItemDecorationCount() > 0) {
+ mPostRecyclerView.removeItemDecorationAt(0);
+ }
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
mStaggeredGridLayoutManager = null;
+ } else {
+ mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL);
if (mPostRecyclerView.getItemDecorationCount() > 0) {
mPostRecyclerView.removeItemDecorationAt(0);
}
- } else if (nColumns == 2) {
- mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration =
- new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset);
+ new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns);
mPostRecyclerView.addItemDecoration(itemDecoration);
mLinearLayoutManager = null;
}
@@ -1641,7 +1644,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (mLinearLayoutManager != null) {
previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
} else if (mStaggeredGridLayoutManager != null) {
- int[] into = new int[2];
+ int[] into = new int[mStaggeredGridLayoutManager.getSpanCount()];
previousPosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0];
}
@@ -1724,13 +1727,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private static class StaggeredGridLayoutManagerItemOffsetDecoration extends RecyclerView.ItemDecoration {
private int mItemOffset;
+ private int mNColumns;
- StaggeredGridLayoutManagerItemOffsetDecoration(int itemOffset) {
+ StaggeredGridLayoutManagerItemOffsetDecoration(int itemOffset, int nColumns) {
mItemOffset = itemOffset;
+ mNColumns = nColumns;
}
- StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) {
- this(context.getResources().getDimensionPixelSize(itemOffsetId));
+ StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId, int nColumns) {
+ this(context.getResources().getDimensionPixelSize(itemOffsetId), nColumns);
}
@Override
@@ -1744,10 +1749,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
int halfOffset = mItemOffset / 2;
- if (spanIndex == 0) {
- outRect.set(halfOffset, 0, halfOffset / 2, 0);
- } else {
- outRect.set(halfOffset / 2, 0, halfOffset, 0);
+ if (mNColumns == 2) {
+ if (spanIndex == 0) {
+ outRect.set(halfOffset, 0, halfOffset / 2, 0);
+ } else {
+ outRect.set(halfOffset / 2, 0, halfOffset, 0);
+ }
+ } else if (mNColumns == 3) {
+ if (spanIndex == 0) {
+ outRect.set(halfOffset, 0, halfOffset / 2, 0);
+ } else if (spanIndex == 1) {
+ outRect.set(halfOffset / 2, 0, halfOffset / 2, 0);
+ } else {
+ outRect.set(halfOffset / 2, 0, halfOffset, 0);
+ }
}
}
}
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 1c210973..4686b42d 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -225,6 +225,7 @@
<string-array name="settings_number_of_columns_in_post_feed">
<item>1</item>
<item>2</item>
+ <item>3</item>
</string-array>
<string-array name="settings_main_page_tab_count">