Persistent kitchensink

pull/210/head
M66B 2 years ago
parent 49962289d7
commit 6d5c9f279a

@ -662,6 +662,12 @@ public class ApplicationEx extends Application
else if (version < 1994) { else if (version < 1994) {
// 2022-10-28 Spamcop blocks Google's addresses // 2022-10-28 Spamcop blocks Google's addresses
editor.putBoolean("blocklist.Spamcop", false); editor.putBoolean("blocklist.Spamcop", false);
} else if (version < 2013) {
if (prefs.contains("compose_block")) {
if (prefs.getBoolean("experiments", false))
editor.putBoolean("compose_style", prefs.getBoolean("compose_block", false));
editor.remove("compose_block");
}
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)

@ -287,6 +287,7 @@ public class FragmentCompose extends FragmentBase {
private String display_font; private String display_font;
private boolean dsn = true; private boolean dsn = true;
private Integer encrypt = null; private Integer encrypt = null;
private boolean style = false;
private boolean media = true; private boolean media = true;
private boolean compact = false; private boolean compact = false;
private int zoom = 0; private int zoom = 0;
@ -349,6 +350,7 @@ public class FragmentCompose extends FragmentBase {
compose_font = prefs.getString("compose_font", ""); compose_font = prefs.getString("compose_font", "");
display_font = prefs.getString("display_font", ""); display_font = prefs.getString("display_font", "");
style = prefs.getBoolean("compose_style", false);
media = prefs.getBoolean("compose_media", true); media = prefs.getBoolean("compose_media", true);
compact = prefs.getBoolean("compose_compact", false); compact = prefs.getBoolean("compose_compact", false);
zoom = prefs.getInt("compose_zoom", compact ? 0 : 1); zoom = prefs.getInt("compose_zoom", compact ? 0 : 1);
@ -626,8 +628,8 @@ public class FragmentCompose extends FragmentBase {
return; return;
if (styling != selection) { if (styling != selection) {
styling = selection; styling = selection;
media_bar.setVisibility(styling ? View.GONE : View.VISIBLE); style_bar.setVisibility(style || styling ? View.VISIBLE : View.GONE);
style_bar.setVisibility(styling ? View.VISIBLE : View.GONE); media_bar.setVisibility(!style && styling ? View.GONE : View.VISIBLE);
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
} }
@ -1921,6 +1923,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_translate).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_translate).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_translate).setVisible(DeepL.isAvailable(context)); menu.findItem(R.id.menu_translate).setVisible(DeepL.isAvailable(context));
menu.findItem(R.id.menu_zoom).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_zoom).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_style).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_media).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_media).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_compact).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_compact).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_contact_group).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_contact_group).setEnabled(state == State.LOADED);
@ -1971,7 +1974,6 @@ public class FragmentCompose extends FragmentBase {
ibZoom.setEnabled(state == State.LOADED); ibZoom.setEnabled(state == State.LOADED);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean experiments = prefs.getBoolean("experiments", false);
boolean save_drafts = prefs.getBoolean("save_drafts", true); boolean save_drafts = prefs.getBoolean("save_drafts", true);
boolean send_chips = prefs.getBoolean("send_chips", true); boolean send_chips = prefs.getBoolean("send_chips", true);
boolean send_dialog = prefs.getBoolean("send_dialog", true); boolean send_dialog = prefs.getBoolean("send_dialog", true);
@ -1981,6 +1983,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_send_chips).setChecked(send_chips); 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_send_dialog).setChecked(send_dialog);
menu.findItem(R.id.menu_image_dialog).setChecked(image_dialog); menu.findItem(R.id.menu_image_dialog).setChecked(image_dialog);
menu.findItem(R.id.menu_style).setChecked(style);
menu.findItem(R.id.menu_media).setChecked(media); menu.findItem(R.id.menu_media).setChecked(media);
menu.findItem(R.id.menu_compact).setChecked(compact); menu.findItem(R.id.menu_compact).setChecked(compact);
@ -2053,6 +2056,9 @@ public class FragmentCompose extends FragmentBase {
} else if (itemId == R.id.menu_image_dialog) { } else if (itemId == R.id.menu_image_dialog) {
onMenuImageDialog(); onMenuImageDialog();
return true; return true;
} else if (itemId == R.id.menu_style) {
onMenuStyleBar();
return true;
} else if (itemId == R.id.menu_media) { } else if (itemId == R.id.menu_media) {
onMenuMediaBar(); onMenuMediaBar();
return true; return true;
@ -2209,15 +2215,22 @@ public class FragmentCompose extends FragmentBase {
prefs.edit().putBoolean("image_dialog", !image_dialog).apply(); prefs.edit().putBoolean("image_dialog", !image_dialog).apply();
} }
private void onMenuStyleBar() {
style = !style;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("compose_style", style).apply();
style_bar.setVisibility(style ? View.VISIBLE : View.GONE);
media_bar.setVisibility(media ? View.VISIBLE : View.GONE);
invalidateOptionsMenu();
}
private void onMenuMediaBar() { private void onMenuMediaBar() {
media = !media; media = !media;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean("compose_media", media).apply(); prefs.edit().putBoolean("compose_media", media).apply();
etBody.setSelection(etBody.getSelectionStart()); etBody.setSelection(etBody.getSelectionStart());
media_bar.getMenu().clear(); style_bar.setVisibility(style ? View.VISIBLE : View.GONE);
media_bar.inflateMenu(R.menu.action_compose_media);
media_bar.setVisibility(media ? View.VISIBLE : View.GONE); media_bar.setVisibility(media ? View.VISIBLE : View.GONE);
style_bar.setVisibility(View.GONE);
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
@ -6905,6 +6918,7 @@ public class FragmentCompose extends FragmentBase {
@Override @Override
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
style_bar.setVisibility(style ? View.VISIBLE : View.GONE);
media_bar.setVisibility(media ? 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_undo).setVisible(draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision < draft.revisions); bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision < draft.revisions);

@ -150,6 +150,18 @@ public class StyleHelper {
_end = tmp; _end = tmp;
} }
if (_start == _end &&
itemId != R.id.menu_style_align && groupId != R.id.group_style_align &&
itemId != R.id.menu_style_list && groupId != R.id.group_style_list &&
itemId != R.id.menu_style_indentation && groupId != R.id.group_style_indentation &&
itemId != R.id.menu_style_blockquote && groupId != R.id.group_style_blockquote) {
Pair<Integer, Integer> word = getWord(etBody);
if (word == null)
return false;
_start = word.first;
_end = word.second;
}
final Editable edit = etBody.getText(); final Editable edit = etBody.getText();
final int start = _start; final int start = _start;
final int end = _end; final int end = _end;
@ -350,7 +362,6 @@ public class StyleHelper {
} else if (groupId == R.id.group_style_font_standard || } else if (groupId == R.id.group_style_font_standard ||
groupId == R.id.group_style_font_custom) { groupId == R.id.group_style_font_custom) {
Log.breadcrumb("style", "action", "font");
return setFont(etBody, start, end, (String) args[0]); return setFont(etBody, start, end, (String) args[0]);
} else if (itemId == R.id.menu_style_align) { } else if (itemId == R.id.menu_style_align) {
@ -358,6 +369,12 @@ public class StyleHelper {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor);
popupMenu.inflate(R.menu.popup_style_alignment); popupMenu.inflate(R.menu.popup_style_alignment);
if (start == end) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
@ -370,15 +387,31 @@ public class StyleHelper {
popupMenu.show(); popupMenu.show();
} else if (groupId == R.id.group_style_align) { } else if (groupId == R.id.group_style_align) {
return setAlignment(itemId, etBody, start, end, true); if (start == end) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
return setAlignment(itemId, etBody, block.first, block.second, false);
} else
return setAlignment(itemId, etBody, start, end, true);
} else if (itemId == R.id.menu_style_list) { } else if (itemId == R.id.menu_style_list) {
Context context = anchor.getContext(); Context context = anchor.getContext();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor);
popupMenu.inflate(R.menu.popup_style_list); popupMenu.inflate(R.menu.popup_style_list);
Integer maxLevel = getMaxListLevel(edit, start, end); int s = start;
IndentSpan[] indents = edit.getSpans(start, end, IndentSpan.class); int e = end;
if (s == e) {
Pair<Integer, Integer> p = StyleHelper.getParagraph(etBody, false);
if (p == null)
return false;
s = p.first;
e = p.second;
}
Integer maxLevel = getMaxListLevel(edit, s, e);
IndentSpan[] indents = edit.getSpans(s, e, IndentSpan.class);
popupMenu.getMenu().findItem(R.id.menu_style_list_bullets).setEnabled(indents.length == 0); popupMenu.getMenu().findItem(R.id.menu_style_list_bullets).setEnabled(indents.length == 0);
popupMenu.getMenu().findItem(R.id.menu_style_list_numbered).setEnabled(indents.length == 0); popupMenu.getMenu().findItem(R.id.menu_style_list_numbered).setEnabled(indents.length == 0);
@ -397,19 +430,40 @@ public class StyleHelper {
popupMenu.show(); popupMenu.show();
} else if (groupId == R.id.group_style_list) { } else if (groupId == R.id.group_style_list) {
if (itemId == R.id.menu_style_list_increase || boolean level = (itemId == R.id.menu_style_list_decrease || itemId == R.id.menu_style_list_increase);
itemId == R.id.menu_style_list_decrease) if (start == end) {
return setListLevel(itemId, etBody, start, end, true); Pair<Integer, Integer> p = StyleHelper.getParagraph(etBody, false);
else if (p == null)
return setList(itemId, etBody, start, end, true); return false;
if (level)
StyleHelper.setListLevel(itemId, etBody, p.first, p.second, false);
else
StyleHelper.setList(itemId, etBody, p.first, p.second, false);
return true;
} else {
if (level)
return setListLevel(itemId, etBody, start, end, true);
else
return setList(itemId, etBody, start, end, true);
}
} else if (itemId == R.id.menu_style_indentation) { } else if (itemId == R.id.menu_style_indentation) {
Context context = anchor.getContext(); Context context = anchor.getContext();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor);
popupMenu.inflate(R.menu.popup_style_indentation); popupMenu.inflate(R.menu.popup_style_indentation);
Integer maxLevel = getMaxListLevel(edit, start, end); int s = start;
IndentSpan[] indents = edit.getSpans(start, end, IndentSpan.class); int e = end;
if (s == e) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
s = block.first;
e = block.second;
}
Integer maxLevel = getMaxListLevel(edit, s, e);
IndentSpan[] indents = edit.getSpans(s, e, IndentSpan.class);
popupMenu.getMenu().findItem(R.id.menu_style_indentation_increase).setEnabled(maxLevel == null); popupMenu.getMenu().findItem(R.id.menu_style_indentation_increase).setEnabled(maxLevel == null);
popupMenu.getMenu().findItem(R.id.menu_style_indentation_decrease).setEnabled(indents.length > 0); popupMenu.getMenu().findItem(R.id.menu_style_indentation_decrease).setEnabled(indents.length > 0);
@ -426,10 +480,23 @@ public class StyleHelper {
popupMenu.show(); popupMenu.show();
} else if (groupId == R.id.group_style_indentation) { } else if (groupId == R.id.group_style_indentation) {
return setIndentation(itemId, etBody, start, end, true); if (start == end) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
StyleHelper.setIndentation(itemId, etBody, block.first, block.second, false);
} else
return setIndentation(itemId, etBody, start, end, true);
} else if (itemId == R.id.menu_style_blockquote || groupId == R.id.group_style_blockquote) { } else if (itemId == R.id.menu_style_blockquote || groupId == R.id.group_style_blockquote) {
return setBlockQuote(etBody, start, end, true); if (start == end) {
Pair<Integer, Integer> block = StyleHelper.getParagraph(etBody, true);
if (block == null)
return false;
StyleHelper.setBlockQuote(etBody, block.first, block.second, false);
return true;
} else
return setBlockQuote(etBody, start, end, true);
} else if (itemId == R.id.menu_style_mark || groupId == R.id.group_style_mark) { } else if (itemId == R.id.menu_style_mark || groupId == R.id.group_style_mark) {
return setMark(etBody, start, end, itemId == R.id.menu_style_mark); return setMark(etBody, start, end, itemId == R.id.menu_style_mark);
@ -1137,6 +1204,34 @@ public class StyleHelper {
return new Pair<>(start, end); return new Pair<>(start, end);
} }
static private Pair<Integer, Integer> getWord(TextView tvBody) {
int start = tvBody.getSelectionStart();
int end = tvBody.getSelectionEnd();
Spannable edit = (Spannable) tvBody.getText();
if (start < 0 || end < 0)
return null;
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
// Expand selection at start
while (start > 0 && edit.charAt(start - 1) != ' ' && edit.charAt(start - 1) != '\n')
start--;
// Expand selection at end
while (end < edit.length() && edit.charAt(end) != ' ' && edit.charAt(end) != '\n')
end++;
if (start == end)
return null;
return new Pair<>(start, end);
}
public static Pair<Integer, Integer> getParagraph(TextView tvBody) { public static Pair<Integer, Integer> getParagraph(TextView tvBody) {
return getParagraph(tvBody, false); return getParagraph(tvBody, false);
} }

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

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

Loading…
Cancel
Save