From 9cc05ea6eee94c80dba9de16f342a3520c0c17d8 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 16 Aug 2019 15:25:06 +0200 Subject: [PATCH] Added reply fab --- .../eu/faircode/email/FragmentMessages.java | 69 ++++++++++++++----- app/src/main/res/layout/fragment_messages.xml | 39 ++++++++--- 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 5069af9ea9..6bde9b6395 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -173,7 +173,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private Group grpHintSwipe; private Group grpHintSelect; private Group grpReady; - private FloatingActionButton fab; + private FloatingActionButton fabReply; + private FloatingActionButton fabCompose; private FloatingActionButton fabMore; private FloatingActionButton fabSearch; private FloatingActionButton fabError; @@ -353,9 +354,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. grpHintSwipe = view.findViewById(R.id.grpHintSwipe); grpHintSelect = view.findViewById(R.id.grpHintSelect); grpReady = view.findViewById(R.id.grpReady); - fab = view.findViewById(R.id.fab); - fabSearch = view.findViewById(R.id.fabSearch); + + fabReply = view.findViewById(R.id.fabReply); + fabCompose = view.findViewById(R.id.fabCompose); fabMore = view.findViewById(R.id.fabMore); + fabSearch = view.findViewById(R.id.fabSearch); fabError = view.findViewById(R.id.fabError); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); @@ -693,7 +696,20 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); - fab.setOnClickListener(new View.OnClickListener() { + fabReply.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (values.containsKey("expanded") && values.get("expanded").size() > 0) { + long id = values.get("expanded").get(0); + Intent reply = new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "reply") + .putExtra("reference", id); + startActivity(reply); + } + } + }); + + fabCompose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(getContext(), ActivityCompose.class) @@ -703,7 +719,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); - fab.setOnLongClickListener(new View.OnLongClickListener() { + fabCompose.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Bundle args = new Bundle(); @@ -740,6 +756,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); + fabMore.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onMore(); + } + }); + fabSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -801,13 +824,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); - fabMore.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onMore(); - } - }); - fabError.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -828,11 +844,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. ibUp.setVisibility(View.GONE); bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(false); bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(false); - bottom_navigation.setVisibility(View.GONE); + bottom_navigation.setVisibility(actionbar ? View.INVISIBLE : View.GONE); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); - fab.hide(); + fabReply.hide(); + fabCompose.hide(); if (viewType == AdapterMessage.ViewType.SEARCH && !server) fabSearch.show(); else @@ -2213,9 +2230,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override public void onChanged(List identities) { if (identities == null || identities.size() == 0) - fab.hide(); + fabCompose.hide(); else - fab.show(); + fabCompose.show(); } }); } @@ -2782,6 +2799,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Log.i("Submit messages=" + messages.size()); adapter.submitList(messages); + updateExpanded(); + // This is to workaround not drawing when the search is expanded new Handler().post(new Runnable() { @Override @@ -2984,9 +3003,21 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } private void updateExpanded() { - boolean expanded = (values.containsKey("expanded") && values.get("expanded").size() > 0); - ibDown.setVisibility(expanded ? View.VISIBLE : View.GONE); - ibUp.setVisibility(expanded ? View.VISIBLE : View.GONE); + int expanded = (values.containsKey("expanded") ? values.get("expanded").size() : 0); + + if (expanded == 1) { + long id = values.get("expanded").get(0); + int pos = adapter.getPositionForKey(id); + TupleMessageEx message = adapter.getItemAtPosition(pos); + if (message != null && message.content && !EntityFolder.OUTBOX.equals(message.folderType)) + fabReply.show(); + else + fabReply.hide(); + } else + fabReply.hide(); + + ibDown.setVisibility(expanded > 0 ? View.VISIBLE : View.GONE); + ibUp.setVisibility(expanded > 0 ? View.VISIBLE : View.GONE); } private void handleExpand(long id) { diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index 2e0a4bc049..b96eb7f0c9 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -179,13 +179,16 @@ app:layout_constraintStart_toStartOf="@id/rvMessage" app:layout_constraintTop_toTopOf="@id/rvMessage" /> - + android:layout_gravity="end|bottom" + android:layout_margin="@dimen/fab_padding" + android:src="@drawable/baseline_reply_24" + android:tint="@color/colorActionForeground" + app:layout_constraintBottom_toTopOf="@+id/seekBar" + app:layout_constraintEnd_toEndOf="parent" /> + android:tint="?attr/colorSeparator" + app:layout_constraintBottom_toTopOf="@+id/seekBar" + app:layout_constraintEnd_toStartOf="@+id/ibUp" + app:layout_constraintHorizontal_chainStyle="packed" + app:layout_constraintStart_toStartOf="parent" /> + android:tint="?attr/colorSeparator" + app:layout_constraintBottom_toTopOf="@+id/seekBar" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_chainStyle="packed" + app:layout_constraintStart_toEndOf="@+id/ibDown" /> + +