From 8fed18b2acdd1844d6a999330dea3f99714a5f23 Mon Sep 17 00:00:00 2001 From: kapodamy Date: Sat, 15 Dec 2018 20:58:28 -0300 Subject: [PATCH] Update MissionAdapter.java * check if the iterator is initialized --- .../giga/ui/adapter/MissionAdapter.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index df5f9e429..5057ed6db 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -158,7 +158,7 @@ public class MissionAdapter extends Adapter { str = R.string.missions_header_pending; } else { str = R.string.missions_header_finished; - setClearButtonVisibility(true); + mClear.setVisible(true); } ((ViewHolderHeader) view).header.setText(str); @@ -437,7 +437,7 @@ public class MissionAdapter extends Adapter { public void clearFinishedDownloads() { mDownloadManager.forgetFinishedDownloads(); applyChanges(); - setClearButtonVisibility(false); + mClear.setVisible(false); } private boolean handlePopupItem(@NonNull ViewHolderItem h, @NonNull MenuItem option) { @@ -506,11 +506,7 @@ public class MissionAdapter extends Adapter { mIterator.end(); checkEmptyMessageVisibility(); - - if (mIterator.getOldListSize() > 0) { - int lastItemType = mIterator.getSpecialAtItem(mIterator.getOldListSize() - 1); - setClearButtonVisibility(lastItemType == DownloadManager.SPECIAL_FINISHED); - } + checkClearButtonVisibility(mClear); } public void forceUpdate() { @@ -529,15 +525,18 @@ public class MissionAdapter extends Adapter { } public void setClearButton(MenuItem clearButton) { - if (mClear == null) { - int lastItemType = mIterator.getSpecialAtItem(mIterator.getOldListSize() - 1); - clearButton.setVisible(lastItemType == DownloadManager.SPECIAL_FINISHED); - } + if (mClear == null) checkClearButtonVisibility(clearButton); mClear = clearButton; } - private void setClearButtonVisibility(boolean flag) { - mClear.setVisible(flag); + private void checkClearButtonVisibility(MenuItem clearButton) { + if (mIterator.getOldListSize() < 1) { + clearButton.setVisible(false); + return; + } + + DownloadManager.MissionItem item = mIterator.getItem(mIterator.getOldListSize() - 1); + clearButton.setVisible(item.special == DownloadManager.SPECIAL_FINISHED || item.mission instanceof FinishedMission); } private void checkEmptyMessageVisibility() {