189 | * Converts the cursor into a CharSequence. Subclasses should override this method to convert 190 | * their results. The default implementation returns an empty String for null values or the 191 | * default String representation of the value. 192 | *
193 | * 194 | * @param cursor the cursor to convert to a CharSequence 195 | * @return a CharSequence representing the value 196 | */ 197 | public CharSequence convertToString(Cursor cursor) { 198 | return cursor == null ? "" : cursor.toString(); 199 | } 200 | 201 | 202 | 203 | /** 204 | * Called when the {@link ContentObserver} on the cursor receives a change 205 | * notification. 206 | * The default implementation provides the auto-requery logic, but may be overridden by 207 | * sub classes. 208 | * 209 | * @see ContentObserver#onChange(boolean) 210 | */ 211 | protected void onContentChanged() { 212 | 213 | } 214 | 215 | private class ChangeObserver extends ContentObserver { 216 | public ChangeObserver() { 217 | super(new Handler()); 218 | } 219 | 220 | @Override 221 | public boolean deliverSelfNotifications() { 222 | return true; 223 | } 224 | 225 | @Override 226 | public void onChange(boolean selfChange) { 227 | onContentChanged(); 228 | } 229 | } 230 | 231 | private class CursorDataSetObserver extends DataSetObserver { 232 | @Override 233 | public void onChanged() { 234 | mDataValid = true; 235 | notifyDataSetChanged(); 236 | } 237 | 238 | @Override 239 | public void onInvalidated() { 240 | mDataValid = false; 241 | // There is no notifyDataSetInvalidated() method in RecyclerView.Adapter 242 | notifyDataSetChanged(); 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /imagepicker/src/main/java/com/imnjh/imagepicker/adapter/CommonHeaderFooterAdapter.java: -------------------------------------------------------------------------------- 1 | package com.imnjh.imagepicker.adapter; 2 | 3 | import java.util.ArrayList; 4 | 5 | import android.support.v7.widget.RecyclerView; 6 | import android.support.v7.widget.StaggeredGridLayoutManager; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | public class CommonHeaderFooterAdapter extends RecyclerView.Adapter