Clean up code for addItems() on ItemListAdapters.
This commit is contained in:
parent
63301ee771
commit
ebf91d27c7
|
@ -76,6 +76,7 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
private final InfoItemBuilder infoItemBuilder;
|
private final InfoItemBuilder infoItemBuilder;
|
||||||
private final ArrayList<InfoItem> infoItemList;
|
private final ArrayList<InfoItem> infoItemList;
|
||||||
private final HistoryRecordManager recordManager;
|
private final HistoryRecordManager recordManager;
|
||||||
|
|
||||||
private boolean useMiniVariant = false;
|
private boolean useMiniVariant = false;
|
||||||
private boolean useGridVariant = false;
|
private boolean useGridVariant = false;
|
||||||
private boolean showFooter = false;
|
private boolean showFooter = false;
|
||||||
|
@ -122,57 +123,52 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addInfoItemList(@Nullable final List<InfoItem> data) {
|
public void addInfoItemList(@Nullable final List<InfoItem> data) {
|
||||||
if (data != null) {
|
if (data == null) {
|
||||||
addInfoItemListImpl(data);
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addInfoItemListImpl(@NonNull List<InfoItem> data) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "addInfoItemList() before > infoItemList.size() = " + infoItemList.size() + ", data.size() = " + data.size());
|
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Log.d(TAG, "addInfoItemList() before > infoItemList.size() = " +
|
||||||
|
infoItemList.size() + ", data.size() = " + data.size());
|
||||||
|
|
||||||
int offsetStart = sizeConsideringHeaderOffset();
|
int offsetStart = sizeConsideringHeaderOffset();
|
||||||
infoItemList.addAll(data);
|
infoItemList.addAll(data);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) Log.d(TAG, "addInfoItemList() after > offsetStart = " + offsetStart +
|
||||||
Log.d(TAG, "addInfoItemList() after > offsetStart = " + offsetStart + ", infoItemList.size() = " + infoItemList.size() + ", header = " + header + ", footer = " + footer + ", showFooter = " + showFooter);
|
", infoItemList.size() = " + infoItemList.size() +
|
||||||
}
|
", header = " + header + ", footer = " + footer +
|
||||||
|
", showFooter = " + showFooter);
|
||||||
notifyItemRangeInserted(offsetStart, data.size());
|
notifyItemRangeInserted(offsetStart, data.size());
|
||||||
|
|
||||||
if (footer != null && showFooter) {
|
if (footer != null && showFooter) {
|
||||||
int footerNow = sizeConsideringHeaderOffset();
|
int footerNow = sizeConsideringHeaderOffset();
|
||||||
notifyItemMoved(offsetStart, footerNow);
|
notifyItemMoved(offsetStart, footerNow);
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "addInfoItemList() footer from " + offsetStart + " to " + footerNow);
|
if (DEBUG) Log.d(TAG, "addInfoItemList() footer from " + offsetStart +
|
||||||
|
" to " + footerNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addInfoItem(@Nullable InfoItem data) {
|
public void addInfoItem(@Nullable InfoItem data) {
|
||||||
if (data != null) {
|
if (data == null) {
|
||||||
addInfoItemImpl(data);
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addInfoItemImpl(@NonNull InfoItem data) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "addInfoItem() before > infoItemList.size() = " + infoItemList.size() + ", thread = " + Thread.currentThread());
|
|
||||||
}
|
}
|
||||||
|
if (DEBUG) Log.d(TAG, "addInfoItem() before > infoItemList.size() = " +
|
||||||
|
infoItemList.size() + ", thread = " + Thread.currentThread());
|
||||||
|
|
||||||
int positionInserted = sizeConsideringHeaderOffset();
|
int positionInserted = sizeConsideringHeaderOffset();
|
||||||
infoItemList.add(data);
|
infoItemList.add(data);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) Log.d(TAG, "addInfoItem() after > position = " + positionInserted +
|
||||||
Log.d(TAG, "addInfoItem() after > position = " + positionInserted + ", infoItemList.size() = " + infoItemList.size() + ", header = " + header + ", footer = " + footer + ", showFooter = " + showFooter);
|
", infoItemList.size() = " + infoItemList.size() +
|
||||||
}
|
", header = " + header + ", footer = " + footer +
|
||||||
|
", showFooter = " + showFooter);
|
||||||
notifyItemInserted(positionInserted);
|
notifyItemInserted(positionInserted);
|
||||||
|
|
||||||
if (footer != null && showFooter) {
|
if (footer != null && showFooter) {
|
||||||
int footerNow = sizeConsideringHeaderOffset();
|
int footerNow = sizeConsideringHeaderOffset();
|
||||||
notifyItemMoved(positionInserted, footerNow);
|
notifyItemMoved(positionInserted, footerNow);
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "addInfoItem() footer from " + positionInserted + " to " + footerNow);
|
if (DEBUG) Log.d(TAG, "addInfoItem() footer from " + positionInserted +
|
||||||
|
" to " + footerNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,27 +93,19 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItems(@Nullable List<? extends LocalItem> data) {
|
public void addItems(@Nullable List<? extends LocalItem> data) {
|
||||||
if (data != null) {
|
if (data == null) {
|
||||||
addItemsImpl(data);
|
return;
|
||||||
}
|
}
|
||||||
}
|
if (DEBUG) Log.d(TAG, "addItems() before > localItems.size() = " +
|
||||||
|
|
||||||
private void addItemsImpl(@NonNull List<? extends LocalItem> data) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "addItems() before > localItems.size() = " +
|
|
||||||
localItems.size() + ", data.size() = " + data.size());
|
localItems.size() + ", data.size() = " + data.size());
|
||||||
}
|
|
||||||
|
|
||||||
int offsetStart = sizeConsideringHeader();
|
int offsetStart = sizeConsideringHeader();
|
||||||
localItems.addAll(data);
|
localItems.addAll(data);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) Log.d(TAG, "addItems() after > offsetStart = " + offsetStart +
|
||||||
Log.d(TAG, "addItems() after > offsetStart = " + offsetStart +
|
|
||||||
", localItems.size() = " + localItems.size() +
|
", localItems.size() = " + localItems.size() +
|
||||||
", header = " + header + ", footer = " + footer +
|
", header = " + header + ", footer = " + footer +
|
||||||
", showFooter = " + showFooter);
|
", showFooter = " + showFooter);
|
||||||
}
|
|
||||||
|
|
||||||
notifyItemRangeInserted(offsetStart, data.size());
|
notifyItemRangeInserted(offsetStart, data.size());
|
||||||
|
|
||||||
if (footer != null && showFooter) {
|
if (footer != null && showFooter) {
|
||||||
|
|
Loading…
Reference in New Issue