Added block toolbar

pull/209/head
M66B 2 years ago
parent 20d038f191
commit 74e671fa37

@ -3735,6 +3735,13 @@ See [this FAQ](#user-content-faq71) for a header condition to recognize receipts
<br />
*Block toolbar (version 1.1967+)*
When enabled in the three-dots overflow menu of the message editor,
a toolbar to perform operations (align text, insert list, indent text, insert blockquote) on a block of text (consecutive non-empty lines) will be shown.
<br />
<a name="faq126"></a>
**(126) Can message previews be sent to my wearable?**

@ -272,6 +272,7 @@ public class FragmentCompose extends FragmentBase {
private ImageButton ibReferenceImages;
private View vwAnchor;
private TextViewAutoCompleteAction etSearch;
private BottomNavigationView block_bar;
private BottomNavigationView style_bar;
private BottomNavigationView media_bar;
private BottomNavigationView bottom_navigation;
@ -291,6 +292,7 @@ public class FragmentCompose extends FragmentBase {
private String display_font;
private boolean dsn = true;
private Integer encrypt = null;
private boolean block = false;
private boolean media = true;
private boolean compact = false;
private int zoom = 0;
@ -347,8 +349,11 @@ public class FragmentCompose extends FragmentBase {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean experiments = prefs.getBoolean("experiments", false);
compose_font = prefs.getString("compose_font", "");
display_font = prefs.getString("display_font", "");
block = experiments && prefs.getBoolean("compose_block", false);
media = prefs.getBoolean("compose_media", true);
compact = prefs.getBoolean("compose_compact", false);
zoom = prefs.getInt("compose_zoom", compact ? 0 : 1);
@ -394,6 +399,7 @@ public class FragmentCompose extends FragmentBase {
ibReferenceImages = view.findViewById(R.id.ibReferenceImages);
vwAnchor = view.findViewById(R.id.vwAnchor);
etSearch = view.findViewById(R.id.etSearch);
block_bar = view.findViewById(R.id.block_bar);
style_bar = view.findViewById(R.id.style_bar);
media_bar = view.findViewById(R.id.media_bar);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
@ -1011,6 +1017,51 @@ public class FragmentCompose extends FragmentBase {
}
});
block_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int action = item.getItemId();
if (action == R.id.menu_blockquote) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
StyleHelper.setBlockQuote(etBody, block.first, block.second, false);
return true;
} else {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), block_bar.findViewById(action));
if (action == R.id.menu_alignment)
popupMenu.inflate(R.menu.popup_style_alignment);
else if (action == R.id.menu_list)
popupMenu.inflate(R.menu.popup_style_list);
else if (action == R.id.menu_indentation)
popupMenu.inflate(R.menu.popup_style_indentation);
popupMenu.insertIcons(getContext());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int itemId = item.getItemId();
boolean level = (itemId == R.id.menu_style_list_decrease || itemId == R.id.menu_style_list_increase);
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, !level);
if (block == null)
return false;
if (action == R.id.menu_alignment)
StyleHelper.setAlignment(item.getItemId(), etBody, block.first, block.second, false);
else if (action == R.id.menu_list) {
if (level)
StyleHelper.setListLevel(itemId, etBody, block.first, block.second, false);
else
StyleHelper.setList(itemId, etBody, block.first, block.second, false);
} else if (action == R.id.menu_indentation)
StyleHelper.setIndentation(item.getItemId(), etBody, block.first, block.second, false);
return true;
}
});
popupMenu.show();
return true;
}
}
});
style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@ -1102,6 +1153,7 @@ public class FragmentCompose extends FragmentBase {
ibReferenceImages.setVisibility(View.GONE);
tvReference.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE);
block_bar.setVisibility(View.GONE);
style_bar.setVisibility(View.GONE);
media_bar.setVisibility(View.GONE);
bottom_navigation.setVisibility(View.GONE);
@ -1848,6 +1900,7 @@ public class FragmentCompose extends FragmentBase {
ibZoom.setEnabled(state == State.LOADED);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean experiments = prefs.getBoolean("experiments", false);
boolean save_drafts = prefs.getBoolean("save_drafts", true);
boolean send_chips = prefs.getBoolean("send_chips", true);
boolean send_dialog = prefs.getBoolean("send_dialog", true);
@ -1857,6 +1910,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_send_chips).setChecked(send_chips);
menu.findItem(R.id.menu_send_dialog).setChecked(send_dialog);
menu.findItem(R.id.menu_image_dialog).setChecked(image_dialog);
menu.findItem(R.id.menu_block).setChecked(block).setVisible(experiments);
menu.findItem(R.id.menu_media).setChecked(media);
menu.findItem(R.id.menu_compact).setChecked(compact);
@ -1929,6 +1983,9 @@ public class FragmentCompose extends FragmentBase {
} else if (itemId == R.id.menu_image_dialog) {
onMenuImageDialog();
return true;
} else if (itemId == R.id.menu_block) {
onMenuBlockBar();
return true;
} else if (itemId == R.id.menu_media) {
onMenuMediaBar();
return true;
@ -2082,6 +2139,14 @@ public class FragmentCompose extends FragmentBase {
prefs.edit().putBoolean("image_dialog", !image_dialog).apply();
}
private void onMenuBlockBar() {
block = !block;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("compose_block", block).apply();
block_bar.setVisibility(block ? View.VISIBLE : View.GONE);
invalidateOptionsMenu();
}
private void onMenuMediaBar() {
media = !media;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -6767,6 +6832,7 @@ public class FragmentCompose extends FragmentBase {
@Override
protected void onPostExecute(Bundle args) {
pbWait.setVisibility(View.GONE);
block_bar.setVisibility(block ? View.VISIBLE : View.GONE);
media_bar.setVisibility(media ? View.VISIBLE : View.GONE);
bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision < draft.revisions);

@ -577,10 +577,23 @@
android:maxLines="1"
android:padding="6dp"
app:end_drawable="@drawable/twotone_fast_forward_24"
app:layout_constraintBottom_toTopOf="@id/style_bar"
app:layout_constraintBottom_toTopOf="@id/block_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/block_bar"
android:layout_width="0dp"
android:layout_height="36dp"
android:background="?attr/colorActionBackground"
app:itemIconTint="@color/action_foreground"
app:itemTextColor="@color/action_foreground"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toTopOf="@+id/style_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/action_compose_paragraph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/style_bar"
android:layout_width="0dp"

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_alignment"
android:icon="@drawable/twotone_format_align_center_24"
android:title="@string/title_style_align" />
<item
android:id="@+id/menu_list"
android:icon="@drawable/twotone_format_list_bulleted_24"
android:title="@string/title_style_list" />
<item
android:id="@+id/menu_indentation"
android:icon="@drawable/twotone_format_indent_increase_24"
android:title="@string/title_style_indentation" />
<item
android:id="@+id/menu_blockquote"
android:icon="@drawable/twotone_format_quote_24"
android:title="@string/title_style_blockquote" />
</menu>

@ -51,6 +51,14 @@
android:title="@string/title_image_dialog"
app:showAsAction="never" />
<item
android:id="@+id/menu_block"
android:checkable="true"
android:checked="false"
android:icon="@drawable/twotone_format_list_bulleted_24"
android:title="@string/title_block_toolbar"
app:showAsAction="never" />
<item
android:id="@+id/menu_media"
android:checkable="true"

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_style_align_start"
android:icon="@drawable/twotone_format_align_left_24"
android:title="@string/title_style_align_start" />
<item
android:id="@+id/menu_style_align_center"
android:icon="@drawable/twotone_format_align_center_24"
android:title="@string/title_style_align_center" />
<item
android:id="@+id/menu_style_align_end"
android:icon="@drawable/twotone_format_align_right_24"
android:title="@string/title_style_align_end" />
</menu>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_style_indentation_increase"
android:icon="@drawable/twotone_format_indent_increase_24"
android:title="@string/title_style_list_level_increase" />
<item
android:id="@+id/menu_style_indentation_decrease"
android:icon="@drawable/twotone_format_indent_decrease_24"
android:title="@string/title_style_list_level_decrease" />
</menu>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_style_list_bullets"
android:icon="@drawable/twotone_format_list_bulleted_24"
android:title="@string/title_style_list_bullets" />
<item
android:id="@+id/menu_style_list_numbered"
android:icon="@drawable/twotone_format_list_numbered_24"
android:title="@string/title_style_list_numbered" />
<item
android:id="@+id/menu_style_list_increase"
android:icon="@drawable/twotone_format_indent_increase_24"
android:title="@string/title_style_list_level_increase" />
<item
android:id="@+id/menu_style_list_decrease"
android:icon="@drawable/twotone_format_indent_decrease_24"
android:title="@string/title_style_list_level_decrease" />
</menu>

@ -1469,6 +1469,7 @@
<string name="title_save_drafts">Save drafts on the server</string>
<string name="title_send_dialog">Show send options</string>
<string name="title_image_dialog">Show image options</string>
<string name="title_block_toolbar">Block toolbar</string>
<string name="title_media_toolbar">Media toolbar</string>
<string name="title_manage_local_contacts">Manage local contacts</string>
<string name="title_insert_contact_group">Insert contact group</string>

Loading…
Cancel
Save