blob: baf95926f42516a22d6ac009b96be10a250a1bc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package it.niedermann.owncloud.notes.model;
import android.graphics.Rect;
import android.view.View;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Px;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
public class SectionItemDecoration extends RecyclerView.ItemDecoration {
@NonNull
private final ItemAdapter adapter;
private final int sectionLeft;
private final int sectionTop;
private final int sectionRight;
private final int sectionBottom;
public SectionItemDecoration(@NonNull ItemAdapter adapter, @Px int sectionLeft, @Px int sectionTop, @Px int sectionRight, @Px int sectionBottom) {
this.adapter = adapter;
this.sectionLeft = sectionLeft;
this.sectionTop = sectionTop;
this.sectionRight = sectionRight;
this.sectionBottom = sectionBottom;
}
@CallSuper
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
final int position = parent.getChildAdapterPosition(view);
if (adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
outRect.left = sectionLeft;
outRect.top = sectionTop;
outRect.right = sectionRight;
outRect.bottom = sectionBottom;
}
}
}
|