Remember the sort mode
This commit is contained in:
parent
0165a00ffb
commit
619e49debc
8 changed files with 189 additions and 10 deletions
|
@ -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);
|
||||
|
|
12
app/src/main/res/drawable/ic_sort_inverted_label_white.xml
Normal file
12
app/src/main/res/drawable/ic_sort_inverted_label_white.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:width="24dp"
|
||||
android:height="24dp">
|
||||
<path
|
||||
android:pathData="M21 18l-6 0 0 -2 6 0zM21 6L21 8 3 8 3 6Zm0 7l-12 0 0 -2 12 0z"
|
||||
android:fillColor="#FFFFFFFF" />
|
||||
<path
|
||||
android:pathData="M8.9582594 21l-5.9471846 0 0 -8.245212 2.1263677 0 0 6.650436 3.8208169 0 0 1.594776z"
|
||||
android:fillColor="#FFFFFFFF" />
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_sort_inverted_white.xml
Normal file
9
app/src/main/res/drawable/ic_sort_inverted_white.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:width="24dp"
|
||||
android:height="24dp">
|
||||
<path
|
||||
android:pathData="M21 18l-6 0 0 -2 6 0zM21 6L21 8 3 8 3 6Zm0 7l-12 0 0 -2 12 0z"
|
||||
android:fillColor="#FFFFFFFF" />
|
||||
</vector>
|
|
@ -1,9 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
|
||||
</vector>
|
|
@ -4,7 +4,7 @@
|
|||
<item
|
||||
android:id="@+id/menu_sort"
|
||||
android:title="@string/menu_main_sort"
|
||||
android:icon="@drawable/ic_sort_white"
|
||||
android:icon="@drawable/ic_sort_inverted_white"
|
||||
app:showAsAction="always" >
|
||||
|
||||
<menu>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<string name="settings_key_openpgp_verify" translatable="false">pref_openpgp_verify</string>
|
||||
|
||||
<string name="settings_key_security_backup_warning" translatable="false">pref_security_backup_warning_shown</string>
|
||||
<string name="settings_key_sort_mode" translatable="false">pref_sort_mode</string>
|
||||
|
||||
<!-- Default values -->
|
||||
<string name="settings_default_theme" translatable="false">light</string>
|
||||
|
|
60
assets/icons/ic_sort_inverted.svg
Normal file
60
assets/icons/ic_sort_inverted.svg
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
fill="#000000"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
version="1.1"
|
||||
id="svg6"
|
||||
sodipodi:docname="ic_sort_inverted.svg"
|
||||
inkscape:version="0.92.1 r">
|
||||
<metadata
|
||||
id="metadata12">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs10" />
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1021"
|
||||
id="namedview8"
|
||||
showgrid="false"
|
||||
inkscape:zoom="9.8333333"
|
||||
inkscape:cx="46.991118"
|
||||
inkscape:cy="-11.02535"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="31"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg6" />
|
||||
<path
|
||||
d="m 21,18 h -6 v -2 h 6 z M 21,6 V 8 H 3 V 6 Z m 0,7 H 9 v -2 h 12 z"
|
||||
id="path2"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="M0 0h24v24H0z"
|
||||
fill="none"
|
||||
id="path4" />
|
||||
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
71
assets/icons/ic_sort_inverted_label.svg
Normal file
71
assets/icons/ic_sort_inverted_label.svg
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
fill="#000000"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
width="24"
|
||||
version="1.1"
|
||||
id="svg6"
|
||||
sodipodi:docname="ic_sort_label_black_24px.svg"
|
||||
inkscape:version="0.92.1 r">
|
||||
<metadata
|
||||
id="metadata12">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs10" />
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1021"
|
||||
id="namedview8"
|
||||
showgrid="false"
|
||||
inkscape:zoom="9.8333333"
|
||||
inkscape:cx="46.991118"
|
||||
inkscape:cy="-11.02535"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="31"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg6" />
|
||||
<path
|
||||
d="m 21,18 h -6 v -2 h 6 z M 21,6 V 8 H 3 V 6 Z m 0,7 H 9 v -2 h 12 z"
|
||||
id="path2"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
d="M0 0h24v24H0z"
|
||||
fill="none"
|
||||
id="path4" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:11.34062767px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.28351569"
|
||||
x="1.9589658"
|
||||
y="21"
|
||||
id="text29"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan27"
|
||||
x="1.9589658"
|
||||
y="21"
|
||||
style="stroke-width:0.28351569">L</tspan></text>
|
||||
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in a new issue