mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
dc05bae98a
commit
3b559f9ff2
|
@ -947,7 +947,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
onMenuCompact();
|
||||
return true;
|
||||
case R.id.menu_clear:
|
||||
onMenuClear();
|
||||
StyleHelper.apply(R.id.menu_clear, etBody);
|
||||
return true;
|
||||
case R.id.menu_contact_group:
|
||||
onMenuContactGroup();
|
||||
|
@ -1014,38 +1014,6 @@ public class FragmentCompose extends FragmentBase {
|
|||
bottom_navigation.setLayoutParams(params);
|
||||
}
|
||||
|
||||
private void onMenuClear() {
|
||||
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;
|
||||
}
|
||||
|
||||
boolean selected = (start != end);
|
||||
if (start == end) {
|
||||
start = 0;
|
||||
end = etBody.length();
|
||||
}
|
||||
|
||||
SpannableString ss = new SpannableString(etBody.getText());
|
||||
|
||||
for (Object span : ss.getSpans(start, end, Object.class))
|
||||
if (!(span instanceof ImageSpan))
|
||||
ss.removeSpan(span);
|
||||
|
||||
etBody.setText(ss);
|
||||
if (selected)
|
||||
etBody.setSelection(start, end);
|
||||
}
|
||||
|
||||
private void onMenuContactGroup() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("working", working);
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.graphics.Typeface;
|
|||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.URLSpan;
|
||||
|
@ -125,6 +126,24 @@ public class StyleHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
case R.id.menu_clear: {
|
||||
boolean selected = (start != end);
|
||||
if (start == end) {
|
||||
start = 0;
|
||||
end = etBody.length();
|
||||
}
|
||||
|
||||
for (Object span : ss.getSpans(start, end, Object.class))
|
||||
if (!(span instanceof ImageSpan))
|
||||
ss.removeSpan(span);
|
||||
|
||||
etBody.setText(ss);
|
||||
if (selected)
|
||||
etBody.setSelection(start, end);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue