Use media bar for style actions

This commit is contained in:
M66B 2020-09-16 15:15:37 +02:00
parent aa1b7bd12d
commit a0cc3c32bc
2 changed files with 24 additions and 6 deletions

View File

@ -466,8 +466,24 @@ public class FragmentCompose extends FragmentBase {
});
etBody.setSelectionListener(new EditTextCompose.ISelection() {
private boolean style = false;
private boolean styling = false;
@Override
public void onSelected(boolean selection) {
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() {

View File

@ -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"