From 6b457cee9421746e162a95fedec8c29c2fb358a1 Mon Sep 17 00:00:00 2001 From: IF-ACT <44696723+IF-ACT@users.noreply.github.com> Date: Sat, 23 May 2020 06:28:43 +0800 Subject: [PATCH] Fixed null exception in All notes, Favourite, and Uncategorized notes --- .../activity/NotesListViewActivity.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index 9d3fd50c..63f134b4 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -397,6 +397,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter binding.drawerLayout.closeDrawer(GravityCompat.START); } refreshLists(true); + updateSortMethodIcon(); } @Override @@ -609,6 +610,27 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter new LoadCategoryListTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + /** + * Updates sorting method icon. + */ + private void updateSortMethodIcon() { + if (localAccount == null) { + return; + } + MenuItem sortMethod = currentMenu.findItem(R.id.sorting_method); + if (navigationSelection.category != null && !navigationSelection.category.isEmpty()) { + sortMethod.setVisible(true); + CategorySortingMethod method = db.getCategoryOrderByTitle(localAccount.getId(), navigationSelection.category); + if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) { + sortMethod.setIcon(R.drawable.alphabetical_asc); + } else { + sortMethod.setIcon(R.drawable.modification_desc); + } + } else { + sortMethod.setVisible(false); + } + } + /** * Responses to two sorting method icons on the menu. * @param item The touched item. @@ -624,14 +646,13 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter method = db.getCategoryOrderByTitle(localAccount.getId(), navigationSelection.category); if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) { - item.setIcon(R.drawable.modification_desc); method = CategorySortingMethod.SORT_MODIFIED_DESC; } else { - item.setIcon(R.drawable.alphabetical_asc); method = CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC; } db.modifyCategoryOrderByTitle(localAccount.getId(), navigationSelection.category, method); refreshLists(); + updateSortMethodIcon(); return true; } else { return super.onOptionsItemSelected(item); @@ -639,14 +660,13 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter } /** - * Initiates sorting method icons. + * Gets menu object. * @param menu Menu. * @return boolean */ @Override public boolean onPrepareOptionsMenu(Menu menu) { currentMenu = menu; - return super.onPrepareOptionsMenu(menu); } @@ -916,12 +936,5 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter mActionMode.finish(); searchView.setIconified(true); refreshLists(); - - CategorySortingMethod method = db.getCategoryOrderByTitle(localAccount.getId(), navigationSelection.category); - if (method == CategorySortingMethod.SORT_LEXICOGRAPHICAL_ASC) { - currentMenu.findItem(R.id.sorting_method).setIcon(R.drawable.alphabetical_asc); - } else { - currentMenu.findItem(R.id.sorting_method).setIcon(R.drawable.modification_desc); - } } }