14510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar/* 24510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * Copyright (C) 2016 The Android Open Source Project 34510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * 44510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 54510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * you may not use this file except in compliance with the License. 64510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * You may obtain a copy of the License at 74510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * 84510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 94510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * 104510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * Unless required by applicable law or agreed to in writing, software 114510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 124510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * See the License for the specific language governing permissions and 144510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * limitations under the License. 154510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar */ 164510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyarpackage android.support.v7.widget; 174510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 184510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 194510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyarimport android.view.View; 204510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 214510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyarimport java.util.ArrayList; 224510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyarimport java.util.List; 234510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 244510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar/** 254510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar * Simple class that can collect list of view attach and detach events so that we can assert on them 264510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar */ 274510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyarpublic class AttachDetachCollector implements RecyclerView.OnChildAttachStateChangeListener { 284510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar private final List<View> mAttached = new ArrayList<>(); 294510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar private final List<View> mDetached = new ArrayList<>(); 304510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 314510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public AttachDetachCollector(RecyclerView recyclerView) { 324510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar recyclerView.addOnChildAttachStateChangeListener(this); 334510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 344510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 354510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar @Override 364510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public void onChildViewAttachedToWindow(View view) { 374510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar mAttached.add(view); 384510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 394510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 404510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar @Override 414510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public void onChildViewDetachedFromWindow(View view) { 424510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar mDetached.add(view); 434510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 444510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 454510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public void reset() { 464510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar mAttached.clear(); 474510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar mDetached.clear(); 484510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 494510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 504510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public List<View> getAttached() { 514510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar return mAttached; 524510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 534510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar 544510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar public List<View> getDetached() { 554510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar return mDetached; 564510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar } 574510b5c24adad2b94df9b84c6b73f5534ffe9b57Yigit Boyar} 58