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