From ebf91d27c7efc4e771feeffd3197c64c34c15f94 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 14 Aug 2019 13:11:16 +0200 Subject: [PATCH] Clean up code for addItems() on ItemListAdapters. --- .../newpipe/info_list/InfoListAdapter.java | 46 +++++++++---------- .../newpipe/local/LocalItemListAdapter.java | 24 ++++------ 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 40164a6be..d8515e4ba 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -76,6 +76,7 @@ public class InfoListAdapter extends RecyclerView.Adapter infoItemList; private final HistoryRecordManager recordManager; + private boolean useMiniVariant = false; private boolean useGridVariant = false; private boolean showFooter = false; @@ -122,57 +123,52 @@ public class InfoListAdapter extends RecyclerView.Adapter data) { - if (data != null) { - addInfoItemListImpl(data); - } - } - - private void addInfoItemListImpl(@NonNull List data) { - if (DEBUG) { - Log.d(TAG, "addInfoItemList() before > infoItemList.size() = " + infoItemList.size() + ", data.size() = " + data.size()); + if (data == null) { + return; } + if (DEBUG) Log.d(TAG, "addInfoItemList() before > infoItemList.size() = " + + infoItemList.size() + ", data.size() = " + data.size()); int offsetStart = sizeConsideringHeaderOffset(); infoItemList.addAll(data); - if (DEBUG) { - Log.d(TAG, "addInfoItemList() after > offsetStart = " + offsetStart + ", infoItemList.size() = " + infoItemList.size() + ", header = " + header + ", footer = " + footer + ", showFooter = " + showFooter); - } - + if (DEBUG) Log.d(TAG, "addInfoItemList() after > offsetStart = " + offsetStart + + ", infoItemList.size() = " + infoItemList.size() + + ", header = " + header + ", footer = " + footer + + ", showFooter = " + showFooter); notifyItemRangeInserted(offsetStart, data.size()); if (footer != null && showFooter) { int footerNow = sizeConsideringHeaderOffset(); 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) { - if (data != null) { - addInfoItemImpl(data); - } - } - - private void addInfoItemImpl(@NonNull InfoItem data) { - if (DEBUG) { - Log.d(TAG, "addInfoItem() before > infoItemList.size() = " + infoItemList.size() + ", thread = " + Thread.currentThread()); + if (data == null) { + return; } + if (DEBUG) Log.d(TAG, "addInfoItem() before > infoItemList.size() = " + + infoItemList.size() + ", thread = " + Thread.currentThread()); int positionInserted = sizeConsideringHeaderOffset(); infoItemList.add(data); - if (DEBUG) { - Log.d(TAG, "addInfoItem() after > position = " + positionInserted + ", infoItemList.size() = " + infoItemList.size() + ", header = " + header + ", footer = " + footer + ", showFooter = " + showFooter); - } + if (DEBUG) Log.d(TAG, "addInfoItem() after > position = " + positionInserted + + ", infoItemList.size() = " + infoItemList.size() + + ", header = " + header + ", footer = " + footer + + ", showFooter = " + showFooter); notifyItemInserted(positionInserted); if (footer != null && showFooter) { int footerNow = sizeConsideringHeaderOffset(); 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); } } diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java index 286eb25d6..4b1a1f363 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -93,27 +93,19 @@ public class LocalItemListAdapter extends RecyclerView.Adapter data) { - if (data != null) { - addItemsImpl(data); - } - } - - private void addItemsImpl(@NonNull List data) { - if (DEBUG) { - Log.d(TAG, "addItems() before > localItems.size() = " + - localItems.size() + ", data.size() = " + data.size()); + if (data == null) { + return; } + if (DEBUG) Log.d(TAG, "addItems() before > localItems.size() = " + + localItems.size() + ", data.size() = " + data.size()); int offsetStart = sizeConsideringHeader(); localItems.addAll(data); - if (DEBUG) { - Log.d(TAG, "addItems() after > offsetStart = " + offsetStart + - ", localItems.size() = " + localItems.size() + - ", header = " + header + ", footer = " + footer + - ", showFooter = " + showFooter); - } - + if (DEBUG) Log.d(TAG, "addItems() after > offsetStart = " + offsetStart + + ", localItems.size() = " + localItems.size() + + ", header = " + header + ", footer = " + footer + + ", showFooter = " + showFooter); notifyItemRangeInserted(offsetStart, data.size()); if (footer != null && showFooter) {