Commit 8fe49d99 authored by Torsten Grote's avatar Torsten Grote

[android] Re-factor TextInputViews

parent f536cfda
......@@ -19,7 +19,7 @@ import org.briarproject.briar.android.controller.handler.UiExceptionHandler;
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import java.util.List;
......@@ -32,10 +32,11 @@ import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ReblogFragment extends BaseFragment implements TextInputListener {
public class ReblogFragment extends BaseFragment implements SendListener {
public static final String TAG = ReblogFragment.class.getName();
......@@ -80,7 +81,8 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
View v = inflater.inflate(R.layout.fragment_reblog, container, false);
ui = new ViewHolder(v);
ui.post.setTransitionName(postId);
ui.input.setSendButtonEnabled(false);
ui.input.setEnabled(false);
ui.input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
showProgressBar();
return v;
......@@ -116,7 +118,7 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
ui.post.hideReblogButton();
ui.input.setListener(this);
ui.input.setSendButtonEnabled(true);
ui.input.setEnabled(true);
ui.scrollView.post(() -> ui.scrollView.fullScroll(FOCUS_DOWN));
}
......
......@@ -4,8 +4,6 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.widget.ProgressBar;
......@@ -23,7 +21,7 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.BlogPost;
......@@ -40,13 +38,12 @@ import static android.view.View.VISIBLE;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
import static org.briarproject.bramble.util.StringUtils.truncateUtf8;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class WriteBlogPostActivity extends BriarActivity
implements OnEditorActionListener, TextInputListener {
implements OnEditorActionListener, SendListener {
private static final Logger LOG =
Logger.getLogger(WriteBlogPostActivity.class.getName());
......@@ -78,23 +75,7 @@ public class WriteBlogPostActivity extends BriarActivity
setContentView(R.layout.activity_write_blog_post);
input = findViewById(R.id.textInput);
input.setSendButtonEnabled(false);
input.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void afterTextChanged(Editable s) {
enableOrDisablePublishButton();
}
});
input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
input.setListener(this);
progressBar = findViewById(R.id.progressBar);
......@@ -134,20 +115,15 @@ public class WriteBlogPostActivity extends BriarActivity
return true;
}
private void enableOrDisablePublishButton() {
input.setSendButtonEnabled(!input.isEmpty());
}
@Override
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (isNullOrEmpty(text)) return;
if (isNullOrEmpty(text)) throw new AssertionError();
// hide publish button, show progress bar
input.hideSoftKeyboard();
input.setVisibility(GONE);
progressBar.setVisibility(VISIBLE);
text = truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
storePost(text);
}
......
......@@ -65,7 +65,7 @@ import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.AttachImageListener;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.client.ProtocolStateException;
......@@ -118,7 +118,6 @@ import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
import static org.briarproject.bramble.util.StringUtils.truncateUtf8;
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_IMAGE_ATTACHMENTS;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_ATTACH_IMAGE;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_INTRODUCTION;
......@@ -136,7 +135,7 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ConversationActivity extends BriarActivity
implements EventListener, ConversationListener, TextInputListener,
implements EventListener, ConversationListener, SendListener,
TextCache, AttachmentCache, AttachImageListener {
public static final String CONTACT_ID = "briar.CONTACT_ID";
......@@ -256,6 +255,8 @@ public class ConversationActivity extends BriarActivity
list.setEmptyText(getString(R.string.no_private_messages));
textInputView = findViewById(R.id.text_input_container);
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
textInputView.setEnabled(false);
textInputView.setListener(this);
if (FEATURE_FLAG_IMAGE_ATTACHMENTS) {
textInputView.setAttachImageListener(this);
......@@ -416,7 +417,7 @@ public class ConversationActivity extends BriarActivity
runOnUiThreadUnlessDestroyed(() -> {
if (revision == adapter.getRevision()) {
adapter.incrementRevision();
textInputView.setSendButtonEnabled(true);
textInputView.setEnabled(true);
List<ConversationItem> items = createItems(headers);
adapter.addAll(items);
list.showData();
......@@ -592,16 +593,15 @@ public class ConversationActivity extends BriarActivity
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (!imageUris.isEmpty()) {
Toast.makeText(this, "Not yet implemented.", LENGTH_LONG).show();
textInputView.setText("");
textInputView.clearText();
return;
}
if (isNullOrEmpty(text)) return;
text = truncateUtf8(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
if (isNullOrEmpty(text)) throw new AssertionError();
long timestamp = System.currentTimeMillis();
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
if (messagingGroupId == null) loadGroupId(text, timestamp);
else createMessage(text, timestamp);
textInputView.setText("");
textInputView.clearText();
}
private long getMinTimestampForNewMessage() {
......
......@@ -23,7 +23,7 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import org.briarproject.briar.api.introduction.IntroductionManager;
import java.util.List;
......@@ -40,14 +40,13 @@ import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.truncateUtf8;
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class IntroductionMessageFragment extends BaseFragment
implements TextInputListener {
implements SendListener {
public static final String TAG =
IntroductionMessageFragment.class.getName();
......@@ -103,7 +102,8 @@ public class IntroductionMessageFragment extends BaseFragment
View v = inflater.inflate(R.layout.introduction_message, container,
false);
ui = new ViewHolder(v);
ui.message.setSendButtonEnabled(false);
ui.message.setMaxTextLength(MAX_INTRODUCTION_TEXT_LENGTH);
ui.message.setEnabled(false);
return v;
}
......@@ -168,7 +168,7 @@ public class IntroductionMessageFragment extends BaseFragment
// show views
ui.notPossible.setVisibility(GONE);
ui.message.setVisibility(VISIBLE);
ui.message.setSendButtonEnabled(true);
ui.message.setEnabled(true);
ui.message.showSoftKeyboard();
} else {
ui.notPossible.setVisibility(VISIBLE);
......@@ -192,11 +192,8 @@ public class IntroductionMessageFragment extends BaseFragment
@Override
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
// disable button to prevent accidental double invitations
ui.message.setSendButtonEnabled(false);
ui.message.setEnabled(false);
if (text != null) {
text = truncateUtf8(text, MAX_INTRODUCTION_TEXT_LENGTH);
}
makeIntroduction(contact1, contact2, text);
// don't wait for the introduction to be made before finishing activity
......
......@@ -196,7 +196,7 @@ public class GroupActivity extends
private void setGroupEnabled(boolean enabled) {
isDissolved = !enabled;
textInput.setSendButtonEnabled(enabled);
textInput.setEnabled(enabled);
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
if (!enabled) {
......
package org.briarproject.briar.android.privategroup.creation;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......@@ -18,6 +20,7 @@ public interface CreateGroupController
ResultExceptionHandler<GroupId, DbException> result);
void sendInvitation(GroupId g, Collection<ContactId> contacts,
String text, ResultExceptionHandler<Void, DbException> result);
@Nullable String text,
ResultExceptionHandler<Void, DbException> result);
}
package org.briarproject.briar.android.privategroup.creation;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
......@@ -123,7 +125,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
@Override
public void sendInvitation(GroupId g, Collection<ContactId> contactIds,
String text, ResultExceptionHandler<Void, DbException> handler) {
@Nullable String text,
ResultExceptionHandler<Void, DbException> handler) {
runOnDbThread(() -> {
try {
LocalAuthor localAuthor = identityManager.getLocalAuthor();
......@@ -144,7 +147,7 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
}
private void signInvitations(GroupId g, LocalAuthor localAuthor,
Collection<Contact> contacts, String text,
Collection<Contact> contacts, @Nullable String text,
ResultExceptionHandler<Void, DbException> handler) {
cryptoExecutor.execute(() -> {
long timestamp = clock.currentTimeMillis();
......@@ -160,15 +163,14 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
}
private void sendInvitations(GroupId g,
Collection<InvitationContext> contexts, String text,
Collection<InvitationContext> contexts, @Nullable String text,
ResultExceptionHandler<Void, DbException> handler) {
runOnDbThread(() -> {
try {
String txt = text.isEmpty() ? null : text;
for (InvitationContext context : contexts) {
try {
groupInvitationManager.sendInvitation(g,
context.contactId, txt, context.timestamp,
context.contactId, text, context.timestamp,
context.signature);
} catch (NoSuchContactException e) {
// Continue
......
......@@ -55,7 +55,7 @@ public class GroupInviteActivity extends ContactSelectorActivity
}
@Override
public boolean onButtonClick(String text) {
public void onButtonClick(@Nullable String text) {
if (groupId == null)
throw new IllegalStateException("GroupId was not initialized");
controller.sendInvitation(groupId, contacts, text,
......@@ -72,7 +72,6 @@ public class GroupInviteActivity extends ContactSelectorActivity
handleDbException(exception);
}
});
return true;
}
@Override
......
......@@ -6,7 +6,6 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.UiThread;
import android.support.design.widget.Snackbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
......@@ -18,17 +17,14 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.LargeTextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import java.util.List;
import static android.support.design.widget.Snackbar.LENGTH_SHORT;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public abstract class BaseMessageFragment extends BaseFragment
implements TextInputListener {
implements SendListener {
protected LargeTextInputView message;
private MessageFragmentListener listener;
......@@ -48,6 +44,7 @@ public abstract class BaseMessageFragment extends BaseFragment
View v = inflater.inflate(R.layout.fragment_message, container,
false);
message = v.findViewById(R.id.messageView);
message.setMaxTextLength(listener.getMaximumTextLength());
message.setButtonText(getString(getButtonText()));
message.setHint(getHintText());
message.setListener(this);
......@@ -84,20 +81,11 @@ public abstract class BaseMessageFragment extends BaseFragment
@Override
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (text == null) return;
if (utf8IsTooLong(text, listener.getMaximumTextLength())) {
Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show();
return;
}
// disable button to prevent accidental double actions
message.setSendButtonEnabled(false);
message.setEnabled(false);
message.hideSoftKeyboard();
if(!listener.onButtonClick(text)) {
message.setSendButtonEnabled(true);
message.showSoftKeyboard();
}
listener.onButtonClick(text);
}
@UiThread
......@@ -108,8 +96,7 @@ public abstract class BaseMessageFragment extends BaseFragment
void setTitle(@StringRes int titleRes);
/** Returns true when the button click has been consumed. */
boolean onButtonClick(String text);
void onButtonClick(@Nullable String text);
int getMaximumTextLength();
......
......@@ -41,13 +41,12 @@ public abstract class ShareActivity extends ContactSelectorActivity
@UiThread
@Override
public boolean onButtonClick(String text) {
public void onButtonClick(@Nullable String text) {
share(contacts, text);
setResult(RESULT_OK);
supportFinishAfterTransition();
return true;
}
abstract void share(Collection<ContactId> contacts, String text);
abstract void share(Collection<ContactId> contacts, @Nullable String text);
}
......@@ -51,7 +51,7 @@ public class ShareBlogActivity extends ShareActivity {
}
@Override
void share(Collection<ContactId> contacts, String text) {
void share(Collection<ContactId> contacts, @Nullable String text) {
controller.share(groupId, contacts, text,
new UiExceptionHandler<DbException>(this) {
@Override
......
......@@ -9,10 +9,12 @@ import org.briarproject.briar.android.controller.handler.ExceptionHandler;
import java.util.Collection;
import javax.annotation.Nullable;
public interface ShareBlogController
extends ContactSelectorController<SelectableContactItem> {
void share(GroupId g, Collection<ContactId> contacts, String text,
void share(GroupId g, Collection<ContactId> contacts, @Nullable String text,
ExceptionHandler<DbException> handler);
}
......@@ -20,12 +20,12 @@ import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
@Immutable
@NotNullByDefault
......@@ -56,17 +56,16 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
}
@Override
public void share(GroupId g, Collection<ContactId> contacts, String text,
ExceptionHandler<DbException> handler) {
public void share(GroupId g, Collection<ContactId> contacts, @Nullable
String text, ExceptionHandler<DbException> handler) {
runOnDbThread(() -> {
try {
String txt = isNullOrEmpty(text) ? null : text;
for (ContactId c : contacts) {
try {
long time = Math.max(clock.currentTimeMillis(),
conversationManager.getGroupCount(c)
.getLatestMsgTime() + 1);
blogSharingManager.sendInvitation(g, c, txt, time);
blogSharingManager.sendInvitation(g, c, text, time);
} catch (NoSuchContactException | NoSuchGroupException e) {
logException(LOG, WARNING, e);
}
......
......@@ -51,7 +51,7 @@ public class ShareForumActivity extends ShareActivity {
}
@Override
void share(Collection<ContactId> contacts, String text) {
void share(Collection<ContactId> contacts, @Nullable String text) {
controller.share(groupId, contacts, text,
new UiExceptionHandler<DbException>(this) {
@Override
......
......@@ -9,10 +9,12 @@ import org.briarproject.briar.android.controller.handler.ExceptionHandler;
import java.util.Collection;
import javax.annotation.Nullable;
public interface ShareForumController
extends ContactSelectorController<SelectableContactItem> {
void share(GroupId g, Collection<ContactId> contacts, String text,
void share(GroupId g, Collection<ContactId> contacts, @Nullable String text,
ExceptionHandler<DbException> handler);
}
......@@ -13,19 +13,19 @@ import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
import org.briarproject.briar.api.forum.ForumSharingManager;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.forum.ForumSharingManager;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
@Immutable
@NotNullByDefault
......@@ -57,16 +57,15 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
@Override
public void share(GroupId g, Collection<ContactId> contacts,
String text, ExceptionHandler<DbException> handler) {
@Nullable String text, ExceptionHandler<DbException> handler) {
runOnDbThread(() -> {
try {
String txt = isNullOrEmpty(text) ? null : text;
for (ContactId c : contacts) {
try {
long time = Math.max(clock.currentTimeMillis(),
conversationManager.getGroupCount(c)
.getLatestMsgTime() + 1);
forumSharingManager.sendInvitation(g, c, txt, time);
forumSharingManager.sendInvitation(g, c, text, time);
} catch (NoSuchContactException | NoSuchGroupException e) {
logException(LOG, WARNING, e);
}
......
......@@ -28,7 +28,7 @@ import org.briarproject.briar.android.threaded.ThreadListController.ThreadListDa
import org.briarproject.briar.android.threaded.ThreadListController.ThreadListListener;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextInputView.SendListener;
import org.briarproject.briar.android.view.UnreadMessageButton;
import org.briarproject.briar.api.client.NamedGroup;
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
......@@ -44,14 +44,14 @@ import static android.support.design.widget.Snackbar.make;
import static android.support.v7.widget.RecyclerView.NO_POSITION;
import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE;
import static java.util.logging.Level.INFO;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UnreadCount;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadItem, A extends ThreadItemAdapter<I>>
extends BriarActivity
implements ThreadListListener<I>, TextInputListener, SharingListener,
implements ThreadListListener<I>, SendListener, SharingListener,
ThreadItemListener<I>, ThreadListDataSource {
protected static final String KEY_REPLY_ID = "replyId";
......@@ -88,6 +88,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
getController().setGroupId(groupId);
textInput = findViewById(R.id.text_input_container);
textInput.setMaxTextLength(getMaxTextLength());
textInput.setListener(this);
list = findViewById(R.id.list);
layoutManager = new LinearLayoutManager(this);
......@@ -268,7 +269,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onBackPressed() {
if (adapter.getHighlightedItem() != null) {
textInput.setText("");
textInput.clearText();
replyId = null;
updateTextInput();
} else {
......@@ -351,12 +352,8 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
@Override
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (text == null || text.trim().length() == 0)
return;
if (utf8IsTooLong(text, getMaxTextLength())) {
displaySnackbar(R.string.text_too_long);
return;
}
if (isNullOrEmpty(text)) throw new AssertionError();
I replyItem = adapter.getHighlightedItem();
UiResultExceptionHandler<I, DbException> handler =
new UiResultExceptionHandler<I, DbException>(this) {
......@@ -372,7 +369,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadI
};
getController().createAndStoreMessage(text, replyItem, handler);
textInput.hideSoftKeyboard();
textInput.setText("");
textInput.clearText();
replyId = null;
updateTextInput();
}
......
......@@ -12,8 +12,6 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.AbsSavedState;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.AppCompatImageButton;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
......@@ -22,7 +20,6 @@ import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.vanniktech.emoji.EmojiEditText;
import org.briarproject.briar.R;
import org.briarproject.briar.android.conversation.glide.GlideApp;
......@@ -48,23 +45,24 @@ import static com.bumptech.glide.load.engine.DiskCacheStrategy.NONE;
import static com.bumptech.glide.load.resource.bitmap.DownsampleStrategy.FIT_CENTER;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
@UiThread
class TextInputAttachmentController implements TextWatcher {
class TextAttachmentController extends TextSendController {
private final EmojiEditText editText;
private final View sendButton;
private final AppCompatImageButton imageButton;
private final ViewGroup imageLayout;
private final ImageView imageView;
private final AttachImageListener listener;
@Nullable
private AttachImageListener imageListener;
private String textHint;
private CharSequence textHint;
private List<Uri> imageUris = emptyList();
public TextInputAttachmentController(View v, EmojiEditText editText,
View sendButton, AttachImageListener listener) {
TextAttachmentController(View v, View sendButton,
TextInputController textInput) {
super(sendButton, textInput, true);
imageLayout = v.findViewById(R.id.imageLayout);
imageView = v.findViewById(R.id.imageView);
......@@ -72,20 +70,37 @@ class TextInputAttachmentController implements TextWatcher {
v.findViewById(R.id.imageCancelButton);
imageButton = v.findViewById(R.id.imageButton);
this.listener = listener;
this.sendButton = sendButton;
this.editText = editText;
this.textHint = editText.getHint().toString();
textHint = textInput.getHint();