1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Style fixes and improvements

This commit is contained in:
M66B 2019-05-01 16:40:39 +02:00
parent 10029366bc
commit 467da4b6d4

View file

@ -369,23 +369,20 @@ public class FragmentCompose extends FragmentBase {
if (item.getGroupId() != 1)
return false;
int s = etBody.getSelectionStart();
int e = etBody.getSelectionEnd();
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (s < 0)
s = 0;
if (e < 0)
e = 0;
if (start < 0)
start = 0;
if (end < 0)
end = 0;
if (s > e) {
int tmp = s;
s = e;
e = tmp;
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
final int start = s;
final int end = e;
final SpannableString ss = new SpannableString(etBody.getText());
switch (item.getItemId()) {
@ -442,11 +439,13 @@ public class FragmentCompose extends FragmentBase {
etBody.setText(ss);
etBody.setSelection(end);
return false;
}
case R.string.title_style_color: {
final int s = start;
final int e = end;
ForegroundColorSpan[] spans = ss.getSpans(start, end, ForegroundColorSpan.class);
int color = (spans.length > 0 ? spans[0].getForegroundColor() : Color.TRANSPARENT);
@ -456,11 +455,11 @@ public class FragmentCompose extends FragmentBase {
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
for (ForegroundColorSpan span : ss.getSpans(start, end, ForegroundColorSpan.class))
for (ForegroundColorSpan span : ss.getSpans(s, e, ForegroundColorSpan.class))
ss.removeSpan(span);
ss.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new ForegroundColorSpan(color), s, e, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(ss);
etBody.setSelection(end);
etBody.setSelection(e);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
@ -501,9 +500,8 @@ public class FragmentCompose extends FragmentBase {
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int action = item.getItemId();
switch (action) {
case R.id.menu_clear:
case R.id.menu_link:
onMenuStyle(item.getItemId());
onMenuLink();
return true;
case R.id.menu_image:
onActionImage();
@ -976,7 +974,7 @@ public class FragmentCompose extends FragmentBase {
onActionAttachment();
return true;
case R.id.menu_clear:
onMenuStyle(item.getItemId());
onMenuClear();
return true;
case R.id.menu_contact_group:
onMenuContactGroup();
@ -1031,34 +1029,22 @@ public class FragmentCompose extends FragmentBase {
edit_bar.setVisibility(style ? View.VISIBLE : View.GONE);
}
private void onMenuStyle(int id) {
int s = etBody.getSelectionStart();
int e = etBody.getSelectionEnd();
private void onMenuClear() {
int end = etBody.getSelectionEnd();
if (end < 0)
end = 0;
if (s < 0)
s = 0;
if (e < 0)
e = 0;
SpannableString ss = new SpannableString(etBody.getText());
if (s > e) {
int tmp = s;
s = e;
e = tmp;
}
final int start = s;
final int end = e;
final SpannableString ss = new SpannableString(etBody.getText());
switch (id) {
case R.id.menu_clear:
for (Object span : ss.getSpans(0, ss.length(), Object.class))
if (!(span instanceof ImageSpan))
ss.removeSpan(span);
break;
case R.id.menu_link:
etBody.setText(ss);
etBody.setSelection(end);
}
private void onMenuLink() {
Uri uri = null;
ClipboardManager cbm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
@ -1096,7 +1082,32 @@ public class FragmentCompose extends FragmentBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ss.setSpan(new URLSpan(etLink.getText().toString()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (start < 0)
start = 0;
if (end < 0)
end = 0;
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
String link = etLink.getText().toString();
if (start == end) {
etBody.setText(etBody.getText().insert(start, link));
end = start + link.length();
}
SpannableString ss = new SpannableString(etBody.getText());
for (URLSpan span : ss.getSpans(start, end, URLSpan.class))
ss.removeSpan(span);
ss.setSpan(new URLSpan(link), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(ss);
etBody.setSelection(end);
}
@ -1108,12 +1119,6 @@ public class FragmentCompose extends FragmentBase {
etLink.requestFocus();
}
});
return;
}
etBody.setText(ss);
etBody.setSelection(end);
}
private void onMenuContactGroup() {