Commit 5e5705c7 authored by akwizgran's avatar akwizgran

Merge branch '1438-send-image-attachments-ui' into 'master'

Implement UX for sending image attachments

See merge request !1004
parents 52ec56d6 e6229a3a
Pipeline #2860 passed with stage
in 11 minutes and 10 seconds
......@@ -105,6 +105,7 @@ dependencies {
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:support-annotations:$supportVersion"
implementation "com.android.support:exifinterface:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "android.arch.lifecycle:extensions:1.1.1"
......
......@@ -32,7 +32,7 @@ import org.briarproject.briar.BriarCoreModule;
import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
import org.briarproject.briar.android.login.SignInReminderReceiver;
import org.briarproject.briar.android.reporting.BriarReportSender;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.EmojiTextInputView;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.android.DozeWatchdog;
import org.briarproject.briar.api.android.LockManager;
......@@ -169,7 +169,7 @@ public interface AndroidComponent
void inject(NotificationCleanupService notificationCleanupService);
void inject(TextInputView textInputView);
void inject(EmojiTextInputView textInputView);
void inject(BriarModelLoader briarModelLoader);
......
......@@ -30,4 +30,10 @@ public interface TestingConstants {
long EXPIRY_DATE = IS_DEBUG_BUILD || IS_BETA_BUILD ?
BuildConfig.BuildTimestamp + 90 * 24 * 60 * 60 * 1000L :
Long.MAX_VALUE;
/**
* Feature flag for enabling image attachments.
*/
boolean FEATURE_FLAG_IMAGE_ATTACHMENTS = IS_DEBUG_BUILD;
}
......@@ -14,5 +14,6 @@ public interface RequestCodes {
int REQUEST_BLUETOOTH_DISCOVERABLE = 10;
int REQUEST_UNLOCK = 11;
int REQUEST_KEYGUARD_UNLOCK = 12;
int REQUEST_ATTACH_IMAGE = 13;
}
package org.briarproject.briar.android.blog;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
......@@ -18,7 +19,10 @@ 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.TextSendController;
import org.briarproject.briar.android.view.TextSendController.SendListener;
import java.util.List;
import javax.annotation.Nullable;
import javax.inject.Inject;
......@@ -29,10 +33,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();
......@@ -77,7 +82,11 @@ 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);
TextSendController sendController =
new TextSendController(ui.input, this, true);
ui.input.setSendController(sendController);
ui.input.setEnabled(false);
ui.input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
showProgressBar();
return v;
......@@ -112,16 +121,14 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
ui.post.bindItem(item);
ui.post.hideReblogButton();
ui.input.setListener(this);
ui.input.setSendButtonEnabled(true);
ui.input.setEnabled(true);
ui.scrollView.post(() -> ui.scrollView.fullScroll(FOCUS_DOWN));
}
@Override
public void onSendClick(String text) {
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
ui.input.hideSoftKeyboard();
String comment = getComment();
feedController.repeatPost(item, comment,
feedController.repeatPost(item, text,
new UiExceptionHandler<DbException>(this) {
@Override
public void onExceptionUi(DbException exception) {
......@@ -131,12 +138,6 @@ public class ReblogFragment extends BaseFragment implements TextInputListener {
finish();
}
@Nullable
private String getComment() {
if (ui.input.getText().length() == 0) return null;
return ui.input.getText().toString();
}
private void showProgressBar() {
ui.progressBar.setVisibility(VISIBLE);
ui.input.setVisibility(GONE);
......
package org.briarproject.briar.android.blog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.widget.ProgressBar;
......@@ -14,19 +14,22 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.util.StringUtils;
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.TextSendController;
import org.briarproject.briar.android.view.TextSendController.SendListener;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.BlogPost;
import org.briarproject.briar.api.blog.BlogPostFactory;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
......@@ -35,10 +38,13 @@ import static android.view.View.GONE;
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.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());
......@@ -58,9 +64,8 @@ public class WriteBlogPostActivity extends BriarActivity
@Inject
volatile BlogManager blogManager;
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle state) {
public void onCreate(@Nullable Bundle state) {
super.onCreate(state);
Intent i = getIntent();
......@@ -71,24 +76,10 @@ 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.setListener(this);
TextSendController sendController =
new TextSendController(input, this, false);
input.setSendController(sendController);
input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
progressBar = findViewById(R.id.progressBar);
}
......@@ -127,18 +118,15 @@ public class WriteBlogPostActivity extends BriarActivity
return true;
}
private void enableOrDisablePublishButton() {
input.setSendButtonEnabled(input.getText().length() > 0);
}
@Override
public void onSendClick(String text) {
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (isNullOrEmpty(text)) throw new AssertionError();
// hide publish button, show progress bar
input.hideSoftKeyboard();
input.setVisibility(GONE);
progressBar.setVisibility(VISIBLE);
text = StringUtils.truncateUtf8(text, MAX_BLOG_POST_TEXT_LENGTH);
storePost(text);
}
......
......@@ -6,6 +6,7 @@ import android.arch.lifecycle.ViewModelProvider;
import android.arch.lifecycle.ViewModelProviders;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
......@@ -52,7 +53,6 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
......@@ -63,8 +63,12 @@ import org.briarproject.briar.android.forum.ForumActivity;
import org.briarproject.briar.android.introduction.IntroductionActivity;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.android.view.ImagePreview;
import org.briarproject.briar.android.view.TextAttachmentController;
import org.briarproject.briar.android.view.TextAttachmentController.AttachImageListener;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
import org.briarproject.briar.android.view.TextSendController;
import org.briarproject.briar.android.view.TextSendController.SendListener;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.client.ProtocolStateException;
......@@ -106,6 +110,7 @@ import static android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAn
import static android.support.v4.view.ViewCompat.setTransitionName;
import static android.support.v7.util.SortedList.INVALID_POSITION;
import static android.view.Gravity.RIGHT;
import static android.widget.Toast.LENGTH_LONG;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.Collections.emptyList;
import static java.util.Collections.sort;
......@@ -115,6 +120,9 @@ import static java.util.logging.Level.WARNING;
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.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;
import static org.briarproject.briar.android.conversation.ImageActivity.ATTACHMENT;
import static org.briarproject.briar.android.conversation.ImageActivity.DATE;
......@@ -130,8 +138,8 @@ import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.S
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class ConversationActivity extends BriarActivity
implements EventListener, ConversationListener, TextInputListener,
TextCache, AttachmentCache {
implements EventListener, ConversationListener, SendListener,
TextCache, AttachmentCache, AttachImageListener {
public static final String CONTACT_ID = "briar.CONTACT_ID";
......@@ -161,6 +169,7 @@ public class ConversationActivity extends BriarActivity
private BriarRecyclerView list;
private LinearLayoutManager layoutManager;
private TextInputView textInputView;
private TextSendController sendController;
// Fields that are accessed from background threads must be volatile
@Inject
......@@ -250,7 +259,16 @@ public class ConversationActivity extends BriarActivity
list.setEmptyText(getString(R.string.no_private_messages));
textInputView = findViewById(R.id.text_input_container);
textInputView.setListener(this);
if (FEATURE_FLAG_IMAGE_ATTACHMENTS) {
ImagePreview imagePreview = findViewById(R.id.imagePreview);
sendController = new TextAttachmentController(textInputView,
imagePreview, this, this);
} else {
sendController = new TextSendController(textInputView, this, false);
}
textInputView.setSendController(sendController);
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
textInputView.setEnabled(false);
}
@Override
......@@ -267,6 +285,9 @@ public class ConversationActivity extends BriarActivity
Snackbar.LENGTH_SHORT);
snackbar.getView().setBackgroundResource(R.color.briar_primary);
snackbar.show();
} else if (request == REQUEST_ATTACH_IMAGE && result == RESULT_OK) {
// remove cast when removing FEATURE_FLAG_IMAGE_ATTACHMENTS
((TextAttachmentController) sendController).onImageReceived(data);
}
}
......@@ -405,7 +426,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();
......@@ -573,14 +594,23 @@ public class ConversationActivity extends BriarActivity
}
@Override
public void onSendClick(String text) {
if (text.isEmpty()) return;
text = StringUtils.truncateUtf8(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
public void onAttachImage(Intent intent) {
startActivityForResult(intent, REQUEST_ATTACH_IMAGE);
}
@Override
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
if (!imageUris.isEmpty()) {
Toast.makeText(this, "Not yet implemented.", LENGTH_LONG).show();
textInputView.clearText();
return;
}
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() {
......
package org.briarproject.briar.android.introduction;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
......@@ -17,14 +17,17 @@ import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
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.TextSendController;
import org.briarproject.briar.android.view.TextSendController.SendListener;
import org.briarproject.briar.api.introduction.IntroductionManager;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Inject;
......@@ -41,8 +44,10 @@ import static org.briarproject.bramble.util.LogUtils.logException;
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();
......@@ -84,8 +89,9 @@ public class IntroductionMessageFragment extends BaseFragment
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
// change toolbar text
ActionBar actionBar = introductionActivity.getSupportActionBar();
......@@ -97,7 +103,11 @@ public class IntroductionMessageFragment extends BaseFragment
View v = inflater.inflate(R.layout.introduction_message, container,
false);
ui = new ViewHolder(v);
ui.message.setSendButtonEnabled(false);
TextSendController sendController =
new TextSendController(ui.message, this, true);
ui.message.setSendController(sendController);
ui.message.setMaxTextLength(MAX_INTRODUCTION_TEXT_LENGTH);
ui.message.setEnabled(false);
return v;
}
......@@ -156,13 +166,10 @@ public class IntroductionMessageFragment extends BaseFragment
ui.progressBar.setVisibility(GONE);
if (possible) {
// set button action
ui.message.setListener(IntroductionMessageFragment.this);
// 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);
......@@ -184,14 +191,11 @@ public class IntroductionMessageFragment extends BaseFragment
}
@Override
public void onSendClick(@NonNull String text) {
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
// disable button to prevent accidental double invitations
ui.message.setSendButtonEnabled(false);
ui.message.setEnabled(false);
String txt = ui.message.getText().toString();
if (txt.isEmpty()) txt = null;
else txt = StringUtils.truncateUtf8(txt, MAX_INTRODUCTION_TEXT_LENGTH);
makeIntroduction(contact1, contact2, txt);
makeIntroduction(contact1, contact2, text);
// don't wait for the introduction to be made before finishing activity
introductionActivity.hideSoftKeyboard(ui.message);
......
......@@ -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
......
package org.briarproject.briar.android.sharing;
import android.content.Context;
import android.net.Uri;
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;
import android.view.ViewGroup;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
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.TextSendController;
import org.briarproject.briar.android.view.TextSendController.SendListener;
import static android.support.design.widget.Snackbar.LENGTH_SHORT;
import static org.briarproject.bramble.util.StringUtils.truncateUtf8;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
import java.util.List;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public abstract class BaseMessageFragment extends BaseFragment
implements TextInputListener {
implements SendListener {
protected LargeTextInputView message;
private MessageFragmentListener listener;
......@@ -34,16 +37,20 @@ public abstract class BaseMessageFragment extends BaseFragment
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(@Nullable LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
// inflate view
View v = inflater.inflate(R.layout.fragment_message, container,
false);
message = v.findViewById(R.id.messageView);
TextSendController sendController =
new TextSendController(message, this, true);
message.setSendController(sendController);
message.setMaxTextLength(listener.getMaximumTextLength());
message.setButtonText(getString(getButtonText()));
message.setHint(getHintText());
message.setListener(this);
return v;
}
......@@ -76,21 +83,12 @@ public abstract class BaseMessageFragment extends BaseFragment
}
@Override
public void onSendClick(String text) {
if (utf8IsTooLong(text, listener.getMaximumTextLength())) {
Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show();
return;
}
public void onSendClick(@Nullable String text, List<Uri> imageUris) {
// disable button to prevent accidental double actions
message.setSendButtonEnabled(false);
message.setEnabled(false);
message.hideSoftKeyboard();
text = truncateUtf8(text, MAX_INVITATION_TEXT_LENGTH);
if(!listener.onButtonClick(text)) {
message.setSendButtonEnabled(true);
message.showSoftKeyboard();
}
listener.onButtonClick(text);
}
@UiThread
......@@ -101,8 +99,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;
}