1 /* 2 * Copyright (C) 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 17 package androidx.paging.integration.testapp; 18 19 import android.graphics.Color; 20 import android.view.ViewGroup; 21 import android.widget.TextView; 22 23 import androidx.paging.PagedListAdapter; 24 import androidx.recyclerview.widget.RecyclerView; 25 26 /** 27 * Sample PagedList item Adapter, which uses a AsyncPagedListDiffer. 28 */ 29 class PagedListItemAdapter extends PagedListAdapter<Item, RecyclerView.ViewHolder> { 30 31 PagedListItemAdapter() { 32 super(Item.DIFF_CALLBACK); 33 } 34 35 @Override 36 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 37 RecyclerView.ViewHolder holder = new RecyclerView.ViewHolder( 38 new TextView(parent.getContext())) {}; 39 holder.itemView.setMinimumHeight(400); 40 return holder; 41 } 42 43 @Override 44 public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 45 Item item = getItem(position); 46 if (item != null) { 47 ((TextView) (holder.itemView)).setText(item.text); 48 holder.itemView.setBackgroundColor(item.bgColor); 49 } else { 50 ((TextView) (holder.itemView)).setText(R.string.loading); 51 holder.itemView.setBackgroundColor(Color.TRANSPARENT); 52 } 53 } 54 } 55