Fix add download label crash when there is no label

This commit is contained in:
NekoInverter committed 2020-10-17 21:41:33 +08:00
1 parent b10df4f644
commit 405925c0ec
2 files changed
+24 -13

No files matched your search

@@ -1082,9 +1082,16 @@ public class DownloadsScene extends ToolbarScene
}
break;
case R.id.menu_label_remove:
mDownloadManager.deleteLabel(label);
mLabels.remove(position);
notifyDataSetChanged();
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.delete_label_title))
.setMessage(getString(R.string.delete_label_message, label))
.setPositiveButton(R.string.delete, (dialog, which) -> {
mDownloadManager.deleteLabel(label);
mLabels.remove(position);
notifyDataSetChanged();
})
.setNegativeButton(android.R.string.cancel, null)
.show();
break;
}
return false;
@@ -1582,8 +1589,9 @@ public class DownloadsScene extends ToolbarScene
mBuilder.setError(null);
mDialog.dismiss();
EhApplication.getDownloadManager(context).addLabel(text);
if (mAdapter != null && mLabels != null) {
mAdapter.notifyItemInserted(mLabels.size() - 1);
initLabels();
if (mLabelAdapter != null && mLabels != null) {
mLabelAdapter.notifyItemInserted(mLabels.size() - 1);
}
if (mViewTransition != null) {
if (mLabels != null && mLabels.size() > 0) {
@@ -1593,10 +1601,6 @@ public class DownloadsScene extends ToolbarScene
}
}
}
if (mLabelAdapter != null) {
initLabels();
mLabelAdapter.notifyDataSetChanged();
}
}
}
}
@@ -739,7 +739,7 @@ public final class GalleryListScene extends BaseScene
quickSearch.name = text;
EhDB.insertQuickSearch(quickSearch);
mQuickSearchList.add(quickSearch);
adapter.notifyDataSetChanged();
adapter.notifyItemInserted(mQuickSearchList.size() - 1);
if (0 == mQuickSearchList.size()) {
tip.setVisibility(View.VISIBLE);
@@ -1547,9 +1547,16 @@ public final class GalleryListScene extends BaseScene
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menu_qs_remove) {
EhDB.deleteQuickSearch(quickSearch);
mQuickSearchList.remove(position);
notifyDataSetChanged();
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.delete_quick_search_title))
.setMessage(getString(R.string.delete_quick_search_message, quickSearch.name))
.setPositiveButton(R.string.delete, (dialog, which) -> {
EhDB.deleteQuickSearch(quickSearch);
mQuickSearchList.remove(position);
notifyDataSetChanged();
})
.setNegativeButton(android.R.string.cancel, null)
.show();
return true;
}
return false;