From 619e49debcba70ebf7a530b8ab80e59b0e85e79f Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Mon, 7 Aug 2017 13:11:47 +0200 Subject: [PATCH] Remember the sort mode --- .../shadowice/flocke/andotp/MainActivity.java | 35 +++++++++ .../drawable/ic_sort_inverted_label_white.xml | 12 ++++ .../res/drawable/ic_sort_inverted_white.xml | 9 +++ app/src/main/res/drawable/ic_sort_white.xml | 9 --- app/src/main/res/menu/menu_main.xml | 2 +- app/src/main/res/values/settings.xml | 1 + assets/icons/ic_sort_inverted.svg | 60 ++++++++++++++++ assets/icons/ic_sort_inverted_label.svg | 71 +++++++++++++++++++ 8 files changed, 189 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/ic_sort_inverted_label_white.xml create mode 100644 app/src/main/res/drawable/ic_sort_inverted_white.xml delete mode 100644 app/src/main/res/drawable/ic_sort_white.xml create mode 100644 assets/icons/ic_sort_inverted.svg create mode 100644 assets/icons/ic_sort_inverted_label.svg diff --git a/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java index 4ef72c29..99ed8a18 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/MainActivity.java @@ -142,6 +142,23 @@ public class MainActivity extends BaseActivity .show(); } + private void restoreSortMode(EntriesCardAdapter adapter) { + if (sharedPref != null) { + String modeStr = sharedPref.getString(getString(R.string.settings_key_sort_mode), EntriesCardAdapter.SortMode.UNSORTED.toString()); + EntriesCardAdapter.SortMode mode = EntriesCardAdapter.SortMode.valueOf(modeStr); + + adapter.setSortMode(mode); + } + } + + private void saveSortMode(EntriesCardAdapter.SortMode mode) { + if (sharedPref != null) { + sharedPref.edit() + .putString(getString(R.string.settings_key_sort_mode), mode.toString()) + .apply(); + } + } + // Initialize the main application @Override protected void onCreate(Bundle savedInstanceState) { @@ -212,6 +229,8 @@ public class MainActivity extends BaseActivity } }); + restoreSortMode(adapter); + touchHelperCallback = new SimpleItemTouchHelperCallback(adapter); ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback); touchHelper.attachToRecyclerView(recList); @@ -322,6 +341,18 @@ public class MainActivity extends BaseActivity sortMenu = menu.findItem(R.id.menu_sort); + if (adapter != null) { + EntriesCardAdapter.SortMode mode = adapter.getSortMode(); + + if (mode == EntriesCardAdapter.SortMode.UNSORTED) { + sortMenu.setIcon(R.drawable.ic_sort_inverted_white); + menu.findItem(R.id.menu_sort_none).setChecked(true); + } else if (mode == EntriesCardAdapter.SortMode.LABEL) { + sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); + menu.findItem(R.id.menu_sort_label).setChecked(true); + } + } + MenuItem searchItem = menu.findItem(R.id.menu_search); searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @@ -377,12 +408,16 @@ public class MainActivity extends BaseActivity return true; } else if (id == R.id.menu_sort_none) { item.setChecked(true); + sortMenu.setIcon(R.drawable.ic_sort_inverted_white); + saveSortMode(EntriesCardAdapter.SortMode.UNSORTED); if (adapter != null) { adapter.setSortMode(EntriesCardAdapter.SortMode.UNSORTED); touchHelperCallback.setDragEnabled(true); } } else if (id == R.id.menu_sort_label) { item.setChecked(true); + sortMenu.setIcon(R.drawable.ic_sort_inverted_label_white); + saveSortMode(EntriesCardAdapter.SortMode.LABEL); if (adapter != null) { adapter.setSortMode(EntriesCardAdapter.SortMode.LABEL); touchHelperCallback.setDragEnabled(false); diff --git a/app/src/main/res/drawable/ic_sort_inverted_label_white.xml b/app/src/main/res/drawable/ic_sort_inverted_label_white.xml new file mode 100644 index 00000000..15acd4e2 --- /dev/null +++ b/app/src/main/res/drawable/ic_sort_inverted_label_white.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_sort_inverted_white.xml b/app/src/main/res/drawable/ic_sort_inverted_white.xml new file mode 100644 index 00000000..519cfe7c --- /dev/null +++ b/app/src/main/res/drawable/ic_sort_inverted_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_sort_white.xml b/app/src/main/res/drawable/ic_sort_white.xml deleted file mode 100644 index a0c153ad..00000000 --- a/app/src/main/res/drawable/ic_sort_white.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 408ea055..ff881cef 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -4,7 +4,7 @@ diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 1242d009..582edbba 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -14,6 +14,7 @@ pref_openpgp_verify pref_security_backup_warning_shown + pref_sort_mode light diff --git a/assets/icons/ic_sort_inverted.svg b/assets/icons/ic_sort_inverted.svg new file mode 100644 index 00000000..4bf9271a --- /dev/null +++ b/assets/icons/ic_sort_inverted.svg @@ -0,0 +1,60 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/assets/icons/ic_sort_inverted_label.svg b/assets/icons/ic_sort_inverted_label.svg new file mode 100644 index 00000000..d674ac80 --- /dev/null +++ b/assets/icons/ic_sort_inverted_label.svg @@ -0,0 +1,71 @@ + + + + + + image/svg+xml + + + + + + + + + + L +