From add179c578b60022b4ffd790c1dcc6716584f876 Mon Sep 17 00:00:00 2001 From: Ztiany Date: Tue, 15 Oct 2019 11:14:23 +0800 Subject: [PATCH] update RecyclerView utils --- .../recyclerview/DividerItemDecoration.java | 1 + .../widget/recyclerview/MarginDecoration.java | 40 ------------------- .../widget/recyclerview/MarginDecoration.kt | 33 +++++++++++++++ .../OnRecyclerViewScrollBottomListener.java | 3 -- 4 files changed, 34 insertions(+), 43 deletions(-) delete mode 100644 lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.java create mode 100644 lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.kt diff --git a/lib_base/src/main/java/com/android/base/widget/recyclerview/DividerItemDecoration.java b/lib_base/src/main/java/com/android/base/widget/recyclerview/DividerItemDecoration.java index 43cdee2..b196e7e 100644 --- a/lib_base/src/main/java/com/android/base/widget/recyclerview/DividerItemDecoration.java +++ b/lib_base/src/main/java/com/android/base/widget/recyclerview/DividerItemDecoration.java @@ -174,4 +174,5 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration { outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); } } + } \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.java b/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.java deleted file mode 100644 index c586406..0000000 --- a/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.android.base.widget.recyclerview; - -import android.graphics.Rect; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - - -public class MarginDecoration extends RecyclerView.ItemDecoration { - - private int mTop; - private int mLeft; - private int mRight; - private int mBottom; - - public MarginDecoration(int left, int top, int right, int bottom) { - mTop = top; - mBottom = bottom; - mRight = right; - mLeft = left; - } - - public MarginDecoration(int margin) { - mTop = margin; - mBottom = margin; - mRight = margin; - mLeft = margin; - } - - @Override - public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { - super.getItemOffsets(outRect, view, parent, state); - outRect.top = mTop; - outRect.bottom = mBottom; - outRect.left = mLeft; - outRect.right = mRight; - } - -} diff --git a/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.kt b/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.kt new file mode 100644 index 0000000..c98708e --- /dev/null +++ b/lib_base/src/main/java/com/android/base/widget/recyclerview/MarginDecoration.kt @@ -0,0 +1,33 @@ +package com.android.base.widget.recyclerview + +import android.graphics.Rect +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.ItemDecoration +import androidx.recyclerview.widget.RecyclerView.State + +class MarginDecoration : ItemDecoration { + + private var top: Int + private var left: Int + private var right: Int + private var bottom: Int + + constructor(left: Int = 0, top: Int = 0, right: Int = 0, bottom: Int = 0) { + this.top = top + this.bottom = bottom + this.right = right + this.left = left + } + + constructor(margin: Int) : this(margin, margin, margin, margin) + + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: State) { + super.getItemOffsets(outRect, view, parent, state) + outRect.top = top + outRect.bottom = bottom + outRect.left = left + outRect.right = right + } + +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/widget/recyclerview/OnRecyclerViewScrollBottomListener.java b/lib_base/src/main/java/com/android/base/widget/recyclerview/OnRecyclerViewScrollBottomListener.java index 438c0fe..741629e 100644 --- a/lib_base/src/main/java/com/android/base/widget/recyclerview/OnRecyclerViewScrollBottomListener.java +++ b/lib_base/src/main/java/com/android/base/widget/recyclerview/OnRecyclerViewScrollBottomListener.java @@ -85,16 +85,13 @@ public abstract class OnRecyclerViewScrollBottomListener extends RecyclerView.On return max; } - @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } - protected abstract void onBottom(); protected abstract void onLeaveBottom(); - } \ No newline at end of file