1/*
2 * Copyright (C) 2016 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 */
16package android.support.v7.widget;
17
18
19import android.view.View;
20
21import java.util.ArrayList;
22import java.util.List;
23
24/**
25 * Simple class that can collect list of view attach and detach events so that we can assert on them
26 */
27public class AttachDetachCollector implements RecyclerView.OnChildAttachStateChangeListener {
28    private final List<View> mAttached = new ArrayList<>();
29    private final List<View> mDetached = new ArrayList<>();
30
31    public AttachDetachCollector(RecyclerView recyclerView) {
32        recyclerView.addOnChildAttachStateChangeListener(this);
33    }
34
35    @Override
36    public void onChildViewAttachedToWindow(View view) {
37        mAttached.add(view);
38    }
39
40    @Override
41    public void onChildViewDetachedFromWindow(View view) {
42        mDetached.add(view);
43    }
44
45    public void reset() {
46        mAttached.clear();
47        mDetached.clear();
48    }
49
50    public List<View> getAttached() {
51        return mAttached;
52    }
53
54    public List<View> getDetached() {
55        return mDetached;
56    }
57}
58