lmw
2023-04-03 16ea883d3c03fd8b910f9282aa1bc08378d40d54
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
40
41
42
43
44
45
46
47
48
49
50
51
package com.beloo.widget.chipslayoutmanager.layouter;
 
import android.graphics.Rect;
 
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
 
import com.beloo.widget.chipslayoutmanager.anchor.AnchorViewState;
 
class ColumnsCreator implements ILayouterCreator {
 
    private RecyclerView.LayoutManager layoutManager;
 
    ColumnsCreator(RecyclerView.LayoutManager layoutManager) {
        this.layoutManager = layoutManager;
    }
 
    @Override
    public AbstractLayouter.Builder createBackwardBuilder() {
        return LeftLayouter.newBuilder();
    }
 
    @Override
    public AbstractLayouter.Builder createForwardBuilder() {
        return RightLayouter.newBuilder();
    }
 
    @Override
    public Rect createOffsetRectForBackwardLayouter(@NonNull AnchorViewState anchor) {
        Rect anchorRect = anchor.getAnchorViewRect();
 
        return new Rect(
                anchorRect == null ? 0 : anchorRect.left,
                0,
                anchorRect == null ? 0 : anchorRect.right,
                //we shouldn't include anchor view here, so anchorTop is a bottomOffset
                anchorRect == null ? 0 : anchorRect.top);
    }
 
    @Override
    public Rect createOffsetRectForForwardLayouter(@NonNull AnchorViewState anchor) {
        Rect anchorRect = anchor.getAnchorViewRect();
 
        return new Rect(
                anchorRect == null ? anchor.getPosition() == 0 ? layoutManager.getPaddingLeft() : 0 : anchorRect.left,
                //we should include anchor view here, so anchorTop is a topOffset
                anchorRect == null ? layoutManager.getPaddingTop() : anchorRect.top,
                anchorRect == null ? anchor.getPosition() == 0 ? layoutManager.getPaddingRight() : 0 : anchorRect.right,
                0);
    }
}