From fe921c062293ecb80d9da7af577584200e669416 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Wed, 1 Nov 2017 21:56:38 +0100 Subject: [PATCH] adding image keyboard support (and some cleanup) --- .../keylesspalace/tusky/ComposeActivity.java | 18 ++++-------- .../tusky/view/EditTextTyped.java | 29 ------------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 24085a70..6f991fc7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -144,7 +144,6 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption private static final String REPLYING_STATUS_CONTENT_EXTRA = "replying_status_content"; private static TootDao tootDao = TuskyApplication.getDB().tootDao(); - private TextView replyTextView; private TextView replyContentTextView; private EditTextTyped textEditor; private LinearLayout mediaPreviewBar; @@ -183,7 +182,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose); - replyTextView = findViewById(R.id.reply_tv); + TextView replyTextView = findViewById(R.id.reply_tv); replyContentTextView = findViewById(R.id.reply_content_tv); textEditor = findViewById(R.id.compose_edit_field); mediaPreviewBar = findViewById(R.id.compose_media_preview_bar); @@ -377,7 +376,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption updateVisibleCharactersLeft(); // Setup the main text field. - setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" } + setEditTextMimeTypes(); // new String[] { "image/gif", "image/webp" } final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color); SpanUtils.highlightSpans(textEditor.getText(), mentionColour); textEditor.addTextChangedListener(new TextWatcher() { @@ -861,13 +860,8 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption .apply(); } - private void setEditTextMimeTypes(String[] contentMimeTypes) { - final String[] mimeTypes; - if (contentMimeTypes == null || contentMimeTypes.length == 0) { - mimeTypes = new String[0]; - } else { - mimeTypes = Arrays.copyOf(contentMimeTypes, contentMimeTypes.length); - } + private void setEditTextMimeTypes() { + final String[] mimeTypes = new String[] {"image/*"}; textEditor.setMimeTypes(mimeTypes, new InputConnectionCompat.OnCommitContentListener() { @Override public boolean onCommitContent(InputContentInfoCompat inputContentInfo, @@ -950,7 +944,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption Callback callback = new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { onSendSuccess(); } else { @@ -959,7 +953,7 @@ public final class ComposeActivity extends BaseActivity implements ComposeOption } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { onSendFailure(); } }; diff --git a/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java b/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java index a6ad6be7..8de38513 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java +++ b/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java @@ -29,7 +29,6 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView { private InputConnectionCompat.OnCommitContentListener onCommitContentListener; private String[] mimeTypes; - private OnPasteListener onPasteListener; public EditTextTyped(Context context) { super(context); @@ -39,10 +38,6 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView { super(context, attributeSet); } - public void addOnPasteListener(OnPasteListener mOnPasteListener) { - this.onPasteListener = mOnPasteListener; - } - public void setMimeTypes(String[] types, InputConnectionCompat.OnCommitContentListener listener) { mimeTypes = types; @@ -61,28 +56,4 @@ public class EditTextTyped extends AppCompatMultiAutoCompleteTextView { return connection; } } - - @Override - public boolean onTextContextMenuItem(int id) { - boolean consumed = super.onTextContextMenuItem(id); - switch (id) { - case android.R.id.paste: - onPaste(); - break; - } - return consumed; - } - - /** - * Text was pasted into the EditText. - */ - public void onPaste() { - if (onPasteListener != null) { - onPasteListener.onPaste(); - } - } - - public interface OnPasteListener { - void onPaste(); - } }