From 3dab7989ff3b7f91dab634c564380bca6511b3e0 Mon Sep 17 00:00:00 2001
From: IF-ACT <44696723+IF-ACT@users.noreply.github.com>
Date: Sat, 23 May 2020 05:16:55 +0800
Subject: [PATCH] Add icon and frontend code
---
.../activity/NotesListViewActivity.java | 52 ++++++++++++++++++-
.../main/res/drawable/alphabetical_asc.xml | 11 ++++
.../main/res/drawable/modification_desc.xml | 11 ++++
.../res/layout/activity_notes_list_view.xml | 2 +-
app/src/main/res/menu/menu_list_view.xml | 5 ++
app/src/main/res/values/strings.xml | 1 +
6 files changed, 80 insertions(+), 2 deletions(-)
create mode 100644 app/src/main/res/drawable/alphabetical_asc.xml
create mode 100644 app/src/main/res/drawable/modification_desc.xml
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 e61bb2c2..9d3fd50c 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
@@ -4,6 +4,7 @@ import android.app.SearchManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteConstraintException;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -68,6 +69,7 @@ import it.niedermann.owncloud.notes.persistence.LoadNotesListTask;
import it.niedermann.owncloud.notes.persistence.LoadNotesListTask.NotesLoadedListener;
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
+import it.niedermann.owncloud.notes.util.CategorySortingMethod;
import it.niedermann.owncloud.notes.util.NoteUtil;
import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;
@@ -109,6 +111,8 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
protected ItemAdapter adapter = null;
+ private Menu currentMenu;
+
protected NotesDatabase db = null;
private ActionBarDrawerToggle drawerToggle;
private NavigationAdapter adapterCategories;
@@ -368,7 +372,6 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
private void selectItem(NavigationItem item, boolean closeNavigation) {
adapterCategories.setSelectedItem(item.id);
-
// update current selection
if (itemRecent.equals(item)) {
navigationSelection = new Category(null, null);
@@ -606,6 +609,46 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
new LoadCategoryListTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
+ /**
+ * Responses to two sorting method icons on the menu.
+ * @param item The touched item.
+ * @return boolean
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ final String unexpectedSortMethod = "Unexpected sort method";
+ CategorySortingMethod method;
+
+ if (item.getItemId() == R.id.sorting_method) {
+ Log.d("onOptionsItemSelected", navigationSelection.category + localAccount.getId());
+ 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();
+ return true;
+ } else {
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ /**
+ * Initiates sorting method icons.
+ * @param menu Menu.
+ * @return boolean
+ */
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ currentMenu = menu;
+
+ return super.onPrepareOptionsMenu(menu);
+ }
/**
* Adds the Menu Items to the Action Bar.
@@ -873,5 +916,12 @@ 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);
+ }
}
}
diff --git a/app/src/main/res/drawable/alphabetical_asc.xml b/app/src/main/res/drawable/alphabetical_asc.xml
new file mode 100644
index 00000000..d400979a
--- /dev/null
+++ b/app/src/main/res/drawable/alphabetical_asc.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/modification_desc.xml b/app/src/main/res/drawable/modification_desc.xml
new file mode 100644
index 00000000..bcad189b
--- /dev/null
+++ b/app/src/main/res/drawable/modification_desc.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_notes_list_view.xml b/app/src/main/res/layout/activity_notes_list_view.xml
index 2915f416..4df0e857 100644
--- a/app/src/main/res/layout/activity_notes_list_view.xml
+++ b/app/src/main/res/layout/activity_notes_list_view.xml
@@ -21,7 +21,7 @@
app:elevation="4dp"
app:titleMarginStart="0dp"
tools:navigationIcon="@drawable/ic_arrow_back_white_24dp"
- tools:title="@string/app_name" />
+ tools:title="@string/app_name"/>
+
- Settings
Deleted notes
Search
+ Sorting method
Cancel
Edit
Save