From 991d68112d75e312def7fb55fde88dcead271c58 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 24 Oct 2018 12:06:04 +0000 Subject: [PATCH] Multiple select actions --- .../eu/faircode/email/FragmentMessages.java | 47 ++- .../main/res/drawable/baseline_report_24.xml | 10 + app/src/main/res/layout/fragment_messages.xml | 331 +++++++++--------- app/src/main/res/menu/action_answer.xml | 9 +- app/src/main/res/menu/action_compose.xml | 12 +- app/src/main/res/menu/action_message.xml | 18 +- app/src/main/res/menu/action_multiple.xml | 23 ++ 7 files changed, 247 insertions(+), 203 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_report_24.xml create mode 100644 app/src/main/res/menu/action_multiple.xml diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 4bef31eb..10e849ce 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -74,6 +74,7 @@ public class FragmentMessages extends FragmentEx { private ImageButton ibHintActions; private TextView tvNoEmail; private RecyclerView rvMessage; + private BottomNavigationView multiple; private BottomNavigationView bottom_navigation; private ProgressBar pbWait; private Group grpSupport; @@ -95,10 +96,9 @@ public class FragmentMessages extends FragmentEx { private List trashes = new ArrayList<>(); private AdapterMessage.ViewType viewType; + private SelectionTracker selectionTracker = null; private LiveData> messages = null; - private SelectionTracker selectionTracker; - private int autoCount = 0; private boolean autoExpand = true; private List expanded = new ArrayList<>(); @@ -149,6 +149,7 @@ public class FragmentMessages extends FragmentEx { ibHintActions = view.findViewById(R.id.ibHintActions); tvNoEmail = view.findViewById(R.id.tvNoEmail); rvMessage = view.findViewById(R.id.rvFolder); + multiple = view.findViewById(R.id.multiple); bottom_navigation = view.findViewById(R.id.bottom_navigation); pbWait = view.findViewById(R.id.pbWait); grpSupport = view.findViewById(R.id.grpSupport); @@ -233,21 +234,24 @@ public class FragmentMessages extends FragmentEx { }); rvMessage.setAdapter(adapter); - selectionTracker = new SelectionTracker.Builder<>( - "messages-selection", - rvMessage, - new ItemKeyProviderMessage(rvMessage), - new ItemDetailsLookupMessage(rvMessage), - StorageStrategy.createLongStorage()) - .withSelectionPredicate(new SelectionPredicateMessage()) - .build(); - adapter.setSelectionTracker(selectionTracker); - - selectionTracker.addObserver(new SelectionTracker.SelectionObserver() { - @Override - public void onSelectionChanged() { - } - }); + if (viewType == AdapterMessage.ViewType.FOLDER) { + selectionTracker = new SelectionTracker.Builder<>( + "messages-selection", + rvMessage, + new ItemKeyProviderMessage(rvMessage), + new ItemDetailsLookupMessage(rvMessage), + StorageStrategy.createLongStorage()) + .withSelectionPredicate(new SelectionPredicateMessage()) + .build(); + adapter.setSelectionTracker(selectionTracker); + + selectionTracker.addObserver(new SelectionTracker.SelectionObserver() { + @Override + public void onSelectionChanged() { + multiple.setVisibility(selectionTracker.hasSelection() ? View.VISIBLE : View.GONE); + } + }); + } new ItemTouchHelper(new ItemTouchHelper.Callback() { @Override @@ -518,6 +522,7 @@ public class FragmentMessages extends FragmentEx { // Initialize tvNoEmail.setVisibility(View.GONE); + multiple.setVisibility(View.GONE); bottom_navigation.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -535,7 +540,8 @@ public class FragmentMessages extends FragmentEx { outState.putLongArray("expanded", Helper.toLongArray(expanded)); outState.putLongArray("headers", Helper.toLongArray(headers)); outState.putLongArray("images", Helper.toLongArray(images)); - selectionTracker.onSaveInstanceState(outState); + if (selectionTracker != null) + selectionTracker.onSaveInstanceState(outState); } @Override @@ -548,7 +554,8 @@ public class FragmentMessages extends FragmentEx { expanded = Helper.fromLongArray(savedInstanceState.getLongArray("expanded")); headers = Helper.fromLongArray(savedInstanceState.getLongArray("headers")); images = Helper.fromLongArray(savedInstanceState.getLongArray("images")); - selectionTracker.onRestoreInstanceState(savedInstanceState); + if (selectionTracker != null) + selectionTracker.onRestoreInstanceState(savedInstanceState); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); @@ -637,6 +644,8 @@ public class FragmentMessages extends FragmentEx { } }); + multiple.setVisibility(selectionTracker != null && selectionTracker.hasSelection() ? View.VISIBLE : View.GONE); + if (viewType == AdapterMessage.ViewType.THREAD) { // Navigation ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); diff --git a/app/src/main/res/drawable/baseline_report_24.xml b/app/src/main/res/drawable/baseline_report_24.xml new file mode 100644 index 00000000..d8544cb9 --- /dev/null +++ b/app/src/main/res/drawable/baseline_report_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index b32b996d..d3b4c94f 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -6,163 +6,169 @@ android:layout_height="match_parent" tools:context=".ActivityView"> - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + app:backgroundTint="?attr/colorAccent" /> + + diff --git a/app/src/main/res/menu/action_answer.xml b/app/src/main/res/menu/action_answer.xml index 107cad80..11299f84 100644 --- a/app/src/main/res/menu/action_answer.xml +++ b/app/src/main/res/menu/action_answer.xml @@ -1,16 +1,13 @@ - + + android:title="@string/title_delete" /> + android:title="@string/title_save" /> diff --git a/app/src/main/res/menu/action_compose.xml b/app/src/main/res/menu/action_compose.xml index 8b15df4a..83ee9356 100644 --- a/app/src/main/res/menu/action_compose.xml +++ b/app/src/main/res/menu/action_compose.xml @@ -1,22 +1,18 @@ - + + android:title="@string/title_discard" /> + android:title="@string/title_save" /> + android:title="@string/title_send" /> diff --git a/app/src/main/res/menu/action_message.xml b/app/src/main/res/menu/action_message.xml index 4fe28c7d..e774cd65 100644 --- a/app/src/main/res/menu/action_message.xml +++ b/app/src/main/res/menu/action_message.xml @@ -1,34 +1,28 @@ - + + android:title="@string/title_more" /> + android:title="@string/title_trash" /> + android:title="@string/title_move" /> + android:title="@string/title_archive" /> + android:title="@string/title_reply" /> diff --git a/app/src/main/res/menu/action_multiple.xml b/app/src/main/res/menu/action_multiple.xml new file mode 100644 index 00000000..902c31c0 --- /dev/null +++ b/app/src/main/res/menu/action_multiple.xml @@ -0,0 +1,23 @@ + + + + + + + + + + +