mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
[android] first round of review comments for attaching images
This commit is contained in:
@@ -23,9 +23,7 @@ import org.briarproject.briar.android.view.TextInputView.TextInputListener;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.support.design.widget.Snackbar.LENGTH_SHORT;
|
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.bramble.util.StringUtils.utf8IsTooLong;
|
||||||
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -96,7 +94,6 @@ public abstract class BaseMessageFragment extends BaseFragment
|
|||||||
message.setSendButtonEnabled(false);
|
message.setSendButtonEnabled(false);
|
||||||
message.hideSoftKeyboard();
|
message.hideSoftKeyboard();
|
||||||
|
|
||||||
text = truncateUtf8(text, MAX_INVITATION_TEXT_LENGTH);
|
|
||||||
if(!listener.onButtonClick(text)) {
|
if(!listener.onButtonClick(text)) {
|
||||||
message.setSendButtonEnabled(true);
|
message.setSendButtonEnabled(true);
|
||||||
message.showSoftKeyboard();
|
message.showSoftKeyboard();
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import static com.bumptech.glide.load.resource.bitmap.DownsampleStrategy.FIT_CEN
|
|||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
|
@UiThread
|
||||||
class TextInputAttachmentController implements TextWatcher {
|
class TextInputAttachmentController implements TextWatcher {
|
||||||
|
|
||||||
private final EmojiEditText editText;
|
private final EmojiEditText editText;
|
||||||
@@ -78,7 +79,10 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
|
|
||||||
editText.addTextChangedListener(this);
|
editText.addTextChangedListener(this);
|
||||||
imageButton.setOnClickListener(view -> onImageButtonClicked());
|
imageButton.setOnClickListener(view -> onImageButtonClicked());
|
||||||
imageCancelButton.setOnClickListener(view -> afterSendButtonClicked());
|
imageCancelButton.setOnClickListener(view -> {
|
||||||
|
editText.setText(null);
|
||||||
|
reset();
|
||||||
|
});
|
||||||
showImageButton(true);
|
showImageButton(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +91,7 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
ACTION_OPEN_DOCUMENT : ACTION_GET_CONTENT);
|
ACTION_OPEN_DOCUMENT : ACTION_GET_CONTENT);
|
||||||
intent.addCategory(CATEGORY_OPENABLE);
|
intent.addCategory(CATEGORY_OPENABLE);
|
||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
if (SDK_INT >= 18)
|
if (SDK_INT >= 18) // TODO set true to allow attaching multiple images
|
||||||
intent.putExtra(EXTRA_ALLOW_MULTIPLE, false);
|
intent.putExtra(EXTRA_ALLOW_MULTIPLE, false);
|
||||||
listener.onAttachImage(intent);
|
listener.onAttachImage(intent);
|
||||||
}
|
}
|
||||||
@@ -122,6 +126,7 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
public boolean onLoadFailed(@Nullable GlideException e,
|
public boolean onLoadFailed(@Nullable GlideException e,
|
||||||
Object model, Target<Bitmap> target,
|
Object model, Target<Bitmap> target,
|
||||||
boolean isFirstResource) {
|
boolean isFirstResource) {
|
||||||
|
reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +162,11 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
sendButton.setVisibility(INVISIBLE);
|
sendButton.setVisibility(INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
sendButton.clearAnimation();
|
sendButton.clearAnimation();
|
||||||
sendButton.animate().alpha(0f).withEndAction(
|
sendButton.setEnabled(false);
|
||||||
() -> sendButton.setVisibility(INVISIBLE)
|
sendButton.animate().alpha(0f).withEndAction(() -> {
|
||||||
).start();
|
sendButton.setVisibility(INVISIBLE);
|
||||||
|
imageButton.setEnabled(true);
|
||||||
|
}).start();
|
||||||
imageButton.clearAnimation();
|
imageButton.clearAnimation();
|
||||||
imageButton.animate().alpha(1f).start();
|
imageButton.animate().alpha(1f).start();
|
||||||
}
|
}
|
||||||
@@ -171,9 +178,11 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
sendButton.clearAnimation();
|
sendButton.clearAnimation();
|
||||||
sendButton.animate().alpha(1f).start();
|
sendButton.animate().alpha(1f).start();
|
||||||
imageButton.clearAnimation();
|
imageButton.clearAnimation();
|
||||||
imageButton.animate().alpha(0f).withEndAction(
|
imageButton.setEnabled(false);
|
||||||
() -> imageButton.setVisibility(INVISIBLE)
|
imageButton.animate().alpha(0f).withEndAction(() -> {
|
||||||
).start();
|
imageButton.setVisibility(INVISIBLE);
|
||||||
|
sendButton.setEnabled(true);
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +198,7 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
int count) {
|
int count) {
|
||||||
if (start != 0 || !imageUris.isEmpty()) return;
|
if (start != 0 || !imageUris.isEmpty()) return;
|
||||||
if (s.length() > 0) showImageButton(false);
|
if (s.length() > 0) showImageButton(false);
|
||||||
else if (s.length() == 0) showImageButton(true);
|
else showImageButton(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -205,7 +214,7 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
textHint = hint;
|
textHint = hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void afterSendButtonClicked() {
|
void reset() {
|
||||||
// restore hint
|
// restore hint
|
||||||
editText.setHint(textHint);
|
editText.setHint(textHint);
|
||||||
// hide image layout
|
// hide image layout
|
||||||
@@ -242,7 +251,6 @@ class TextInputAttachmentController implements TextWatcher {
|
|||||||
super(in);
|
super(in);
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
imageUris = in.readArrayList(Uri.class.getClassLoader());
|
imageUris = in.readArrayList(Uri.class.getClassLoader());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class TextInputView extends KeyboardAwareLinearLayout {
|
|||||||
listener.onSendClick(text, imageUris);
|
listener.onSendClick(text, imageUris);
|
||||||
}
|
}
|
||||||
if (attachmentController != null) {
|
if (attachmentController != null) {
|
||||||
attachmentController.afterSendButtonClicked();
|
attachmentController.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user