mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-23 16:34:44 +01:00
Set item offset in Postfragment when using StaggeredGridLayoutManager. Minor UI tweaks.
This commit is contained in:
parent
8f1d183858
commit
c5a824ac89
@ -7,11 +7,11 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -22,6 +22,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@ -159,6 +160,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
} else {
|
||||
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
|
||||
mPostRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
|
||||
StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration =
|
||||
new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset);
|
||||
mPostRecyclerView.addItemDecoration(itemDecoration);
|
||||
}
|
||||
|
||||
mGlide = Glide.with(activity);
|
||||
@ -583,4 +587,35 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
currentPosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static class StaggeredGridLayoutManagerItemOffsetDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int mItemOffset;
|
||||
|
||||
StaggeredGridLayoutManagerItemOffsetDecoration(int itemOffset) {
|
||||
mItemOffset = itemOffset;
|
||||
}
|
||||
|
||||
StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) {
|
||||
this(context.getResources().getDimensionPixelSize(itemOffsetId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
|
||||
@NonNull RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
|
||||
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
|
||||
|
||||
int spanIndex = layoutParams.getSpanIndex();
|
||||
|
||||
int halfOffset = mItemOffset / 2;
|
||||
|
||||
if(spanIndex == 0) {
|
||||
outRect.set(0, 0, halfOffset, 0);
|
||||
} else {
|
||||
outRect.set(halfOffset, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@
|
||||
android:id="@+id/fetch_comments_info_linear_layout_comments_listing_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -15,6 +15,7 @@
|
||||
android:id="@+id/no_subscriptions_linear_layout_followed_users_listing_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -26,6 +26,7 @@
|
||||
android:id="@+id/fetch_post_info_linear_layout_post_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -28,6 +28,7 @@
|
||||
android:id="@+id/fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -15,6 +15,7 @@
|
||||
android:id="@+id/no_subscriptions_linear_layout_subreddits_listing_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -28,6 +28,7 @@
|
||||
android:id="@+id/fetch_user_listing_info_linear_layout_user_listing_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
@ -2,7 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="36dp"
|
||||
android:layout_margin="48dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
|
@ -9,4 +9,5 @@
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
<dimen name="roundedBottomSheetCornerRadiusLeftPadding">0dp</dimen>
|
||||
<dimen name="roundedBottomSheetCornerRadiusRightPadding">0dp</dimen>
|
||||
<dimen name="staggeredLayoutManagerItemOffset">16dp</dimen>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user