1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 12:32:31 +01:00

Update MissionAdapter.java

* check if the iterator is initialized
This commit is contained in:
kapodamy 2018-12-15 20:58:28 -03:00
parent ecabbb57e6
commit 8fed18b2ac

View File

@ -158,7 +158,7 @@ public class MissionAdapter extends Adapter<ViewHolder> {
str = R.string.missions_header_pending; str = R.string.missions_header_pending;
} else { } else {
str = R.string.missions_header_finished; str = R.string.missions_header_finished;
setClearButtonVisibility(true); mClear.setVisible(true);
} }
((ViewHolderHeader) view).header.setText(str); ((ViewHolderHeader) view).header.setText(str);
@ -437,7 +437,7 @@ public class MissionAdapter extends Adapter<ViewHolder> {
public void clearFinishedDownloads() { public void clearFinishedDownloads() {
mDownloadManager.forgetFinishedDownloads(); mDownloadManager.forgetFinishedDownloads();
applyChanges(); applyChanges();
setClearButtonVisibility(false); mClear.setVisible(false);
} }
private boolean handlePopupItem(@NonNull ViewHolderItem h, @NonNull MenuItem option) { private boolean handlePopupItem(@NonNull ViewHolderItem h, @NonNull MenuItem option) {
@ -506,11 +506,7 @@ public class MissionAdapter extends Adapter<ViewHolder> {
mIterator.end(); mIterator.end();
checkEmptyMessageVisibility(); checkEmptyMessageVisibility();
checkClearButtonVisibility(mClear);
if (mIterator.getOldListSize() > 0) {
int lastItemType = mIterator.getSpecialAtItem(mIterator.getOldListSize() - 1);
setClearButtonVisibility(lastItemType == DownloadManager.SPECIAL_FINISHED);
}
} }
public void forceUpdate() { public void forceUpdate() {
@ -529,15 +525,18 @@ public class MissionAdapter extends Adapter<ViewHolder> {
} }
public void setClearButton(MenuItem clearButton) { public void setClearButton(MenuItem clearButton) {
if (mClear == null) { if (mClear == null) checkClearButtonVisibility(clearButton);
int lastItemType = mIterator.getSpecialAtItem(mIterator.getOldListSize() - 1);
clearButton.setVisible(lastItemType == DownloadManager.SPECIAL_FINISHED);
}
mClear = clearButton; mClear = clearButton;
} }
private void setClearButtonVisibility(boolean flag) { private void checkClearButtonVisibility(MenuItem clearButton) {
mClear.setVisible(flag); 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() { private void checkEmptyMessageVisibility() {