Simplify code
This commit is contained in:
parent
aab09c0c65
commit
50b85a7734
1 changed files with 17 additions and 17 deletions
|
@ -34,30 +34,30 @@ public final class NewPipeTextViewHelper {
|
||||||
* deselecting it, otherwise an exception
|
* deselecting it, otherwise an exception
|
||||||
*/
|
*/
|
||||||
public static boolean shareSelectedTextWithShareUtils(@NonNull final TextView textView) {
|
public static boolean shareSelectedTextWithShareUtils(@NonNull final TextView textView) {
|
||||||
if (textView instanceof NewPipeTextView) {
|
if (!(textView instanceof NewPipeEditText)) {
|
||||||
final NewPipeTextView newPipeTextView = (NewPipeTextView) textView;
|
final CharSequence textViewText;
|
||||||
final CharSequence text = newPipeTextView.getText();
|
if (textView instanceof NewPipeTextView) {
|
||||||
final CharSequence selectedText = getSelectedText(newPipeTextView, text);
|
final NewPipeTextView newPipeTextView = (NewPipeTextView) textView;
|
||||||
|
textViewText = newPipeTextView.getText();
|
||||||
|
} else {
|
||||||
|
textViewText = textView.getText();
|
||||||
|
}
|
||||||
|
|
||||||
shareSelectedTextIfNotNullAndNotEmpty(newPipeTextView, selectedText);
|
final CharSequence selectedText = getSelectedText(textView, textViewText);
|
||||||
|
shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText);
|
||||||
|
|
||||||
final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null;
|
final Spannable spannable = (textViewText instanceof Spannable)
|
||||||
Selection.setSelection(spannable, newPipeTextView.getSelectionEnd());
|
? (Spannable) textViewText : null;
|
||||||
} else if (textView instanceof NewPipeEditText) {
|
if (spannable != null) {
|
||||||
|
Selection.setSelection(spannable, textView.getSelectionEnd());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
final NewPipeEditText editText = (NewPipeEditText) textView;
|
final NewPipeEditText editText = (NewPipeEditText) textView;
|
||||||
final Spannable text = editText.getText();
|
final Spannable text = editText.getText();
|
||||||
|
|
||||||
final CharSequence selectedText = getSelectedText(textView, text);
|
final CharSequence selectedText = getSelectedText(textView, text);
|
||||||
shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText);
|
shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText);
|
||||||
Selection.setSelection(text, editText.getSelectionEnd());
|
Selection.setSelection(text, editText.getSelectionEnd());
|
||||||
} else {
|
|
||||||
final CharSequence text = textView.getText();
|
|
||||||
final CharSequence selectedText = getSelectedText(textView, text);
|
|
||||||
|
|
||||||
shareSelectedTextIfNotNullAndNotEmpty(textView, selectedText);
|
|
||||||
|
|
||||||
final Spannable spannable = (text instanceof Spannable) ? (Spannable) text : null;
|
|
||||||
Selection.setSelection(spannable, textView.getSelectionEnd());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -65,7 +65,7 @@ public final class NewPipeTextViewHelper {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static CharSequence getSelectedText(@NonNull final TextView textView,
|
private static CharSequence getSelectedText(@NonNull final TextView textView,
|
||||||
@Nullable final CharSequence text) {
|
@Nullable final CharSequence text) {
|
||||||
if (!textView.hasSelection() || text == null) {
|
if (!textView.hasSelection() || text == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue