1/*
2 * Copyright 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.recyclerview.selection.testing;
18
19import android.view.MotionEvent;
20
21import androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails;
22import androidx.recyclerview.widget.RecyclerView;
23
24public final class TestItemDetails extends ItemDetails<String> {
25
26    private int mPosition;
27    private String mSelectionKey;
28    private boolean mInDragRegion;
29    private boolean mInSelectionHotspot;
30
31    public TestItemDetails() {
32        mPosition = RecyclerView.NO_POSITION;
33    }
34
35    public TestItemDetails(TestItemDetails source) {
36        mPosition = source.mPosition;
37        mSelectionKey = source.mSelectionKey;
38        mInDragRegion = source.mInDragRegion;
39        mInSelectionHotspot = source.mInSelectionHotspot;
40    }
41
42    public void at(int position) {
43        mPosition = position;  // this is both "adapter position" and "item position".
44        mSelectionKey = (position == RecyclerView.NO_POSITION)
45                ? null
46                : String.valueOf(position);
47    }
48
49    public void setInItemDragRegion(boolean inHotspot) {
50        mInDragRegion = inHotspot;
51    }
52
53    public void setInItemSelectRegion(boolean over) {
54        mInSelectionHotspot = over;
55    }
56
57    @Override
58    public boolean inDragRegion(MotionEvent event) {
59        return mInDragRegion;
60    }
61
62    @Override
63    public int hashCode() {
64        return mPosition;
65    }
66
67    @Override
68    public boolean equals(Object o) {
69        if (this == o) {
70            return true;
71        }
72
73        if (!(o instanceof TestItemDetails)) {
74            return false;
75        }
76
77        TestItemDetails other = (TestItemDetails) o;
78        return mPosition == other.mPosition
79                && mSelectionKey == other.mSelectionKey;
80    }
81
82    @Override
83    public int getPosition() {
84        return mPosition;
85    }
86
87    @Override
88    public String getSelectionKey() {
89        return mSelectionKey;
90    }
91
92    @Override
93    public boolean inSelectionHotspot(MotionEvent e) {
94        return mInSelectionHotspot;
95    }
96}
97