From a0cc3c32bcad6e8b61bd2c1cceb5441d79956324 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 16 Sep 2020 15:15:37 +0200 Subject: [PATCH] Use media bar for style actions --- .../eu/faircode/email/FragmentCompose.java | 29 +++++++++++++++---- app/src/main/res/layout/fragment_compose.xml | 1 - 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index b0b56668ce..99db6c2bf2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -466,9 +466,25 @@ public class FragmentCompose extends FragmentBase { }); etBody.setSelectionListener(new EditTextCompose.ISelection() { + private boolean style = false; + private boolean styling = false; + @Override public void onSelected(boolean selection) { - style_bar.setVisibility(selection ? View.VISIBLE : View.GONE); + if (media) { + style = selection; + getMainHandler().postDelayed(new Runnable() { + @Override + public void run() { + if (style != styling) { + styling = style; + media_bar.getMenu().clear(); + media_bar.inflateMenu(styling ? R.menu.action_compose_style : R.menu.action_compose_media); + } + } + }, 20); + } else + style_bar.setVisibility(selection ? View.VISIBLE : View.GONE); } }); @@ -726,7 +742,8 @@ public class FragmentCompose extends FragmentBase { style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { - return onActionStyle(item.getItemId()); + int action = item.getItemId(); + return onActionStyle(action, style_bar.findViewById(action)); } }); @@ -751,7 +768,7 @@ public class FragmentCompose extends FragmentBase { onActionLink(); return true; default: - return false; + return onActionStyle(action, media_bar.findViewById(action)); } } }); @@ -1513,6 +1530,8 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); prefs.edit().putBoolean("compose_media", media).apply(); media_bar.setVisibility(media ? View.VISIBLE : View.GONE); + media_bar.getMenu().clear(); + media_bar.inflateMenu(media && etBody.hasSelection() ? R.menu.action_compose_style : R.menu.action_compose_media); } private void onMenuCompact() { @@ -1674,9 +1693,9 @@ public class FragmentCompose extends FragmentBase { }.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "compose:answer"); } - private boolean onActionStyle(int action) { + private boolean onActionStyle(int action, View anchor) { Log.i("Style action=" + action); - return StyleHelper.apply(action, view.findViewById(action), etBody); + return StyleHelper.apply(action, anchor, etBody); } private void onActionRecordAudio() { diff --git a/app/src/main/res/layout/fragment_compose.xml b/app/src/main/res/layout/fragment_compose.xml index 277c01363a..97ad285e8c 100644 --- a/app/src/main/res/layout/fragment_compose.xml +++ b/app/src/main/res/layout/fragment_compose.xml @@ -477,7 +477,6 @@ android:id="@+id/style_bar" android:layout_width="0dp" android:layout_height="36dp" - android:layout_marginBottom="1dp" android:background="?attr/colorActionBackground" app:itemIconTint="@color/action_foreground" app:itemTextColor="@color/action_foreground"