Messaging: Let there be lambdas

Change-Id: Iee1fc46c92ea9159abb10d92d34baee937bdee0c
This commit is contained in:
Michael W
2024-12-26 14:55:12 +01:00
parent c1b4aa4dfe
commit d43b6ff1c4
84 changed files with 991 additions and 1697 deletions
@@ -71,35 +71,22 @@ public class AttachmentPreview extends ScrollView implements OnAttachmentClickLi
protected void onFinishInflate() {
super.onFinishInflate();
mCloseButton = (ImageButton) findViewById(R.id.close_button);
mCloseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
mComposeMessageView.clearAttachments();
}
});
mCloseButton.setOnClickListener(view -> mComposeMessageView.clearAttachments());
mAttachmentView = (FrameLayout) findViewById(R.id.attachment_view);
// The attachment preview is a scroll view so that it can show the bottom portion of the
// attachment whenever the space is tight (e.g. when in landscape mode). Per design
// request we'd like to make the attachment view always scrolled to the bottom.
addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(final View v, final int left, final int top, final int right,
final int bottom, final int oldLeft, final int oldTop, final int oldRight,
final int oldBottom) {
post(new Runnable() {
@Override
public void run() {
final int childCount = getChildCount();
if (childCount > 0) {
final View lastChild = getChildAt(childCount - 1);
scrollTo(getScrollX(), lastChild.getBottom() - getHeight());
}
}
});
addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight,
oldBottom) -> post(() ->
{
final int childCount = getChildCount();
if (childCount > 0) {
final View lastChild = getChildAt(childCount - 1);
scrollTo(getScrollX(), lastChild.getBottom() - getHeight());
}
});
}));
mPendingFirstUpdate = true;
}
@@ -129,18 +116,14 @@ public class AttachmentPreview extends ScrollView implements OnAttachmentClickLi
mPendingHideCanceled = false;
final View viewToHide = mAttachmentView.getChildCount() > 1 ?
mAttachmentView : mAttachmentView.getChildAt(0);
UiUtils.revealOrHideViewWithAnimation(viewToHide, INVISIBLE,
new Runnable() {
@Override
public void run() {
// Only hide if we are didn't get overruled by showing
if (!mPendingHideCanceled) {
stopPopupAnimation();
mAttachmentView.removeAllViews();
setVisibility(GONE);
}
}
});
UiUtils.revealOrHideViewWithAnimation(viewToHide, INVISIBLE, () -> {
// Only hide if we are didn't get overruled by showing
if (!mPendingHideCanceled) {
stopPopupAnimation();
mAttachmentView.removeAllViews();
setVisibility(GONE);
}
});
} else {
mAttachmentView.removeAllViews();
setVisibility(GONE);
@@ -164,14 +147,11 @@ public class AttachmentPreview extends ScrollView implements OnAttachmentClickLi
.getQuantityString(R.plurals.attachment_preview_close_content_description,
combinedAttachmentCount));
if (combinedAttachmentCount == 0) {
mHideRunnable = new Runnable() {
@Override
public void run() {
mHideRunnable = null;
// Only start the hiding if there are still no attachments
if (attachments.size() + pendingAttachments.size() == 0) {
hideAttachmentPreview();
}
mHideRunnable = () -> {
mHideRunnable = null;
// Only start the hiding if there are still no attachments
if (attachments.size() + pendingAttachments.size() == 0) {
hideAttachmentPreview();
}
};
if (draftMessageData.isSending()) {
@@ -196,13 +176,11 @@ public class AttachmentPreview extends ScrollView implements OnAttachmentClickLi
if (!isFirstUpdate) {
// Reveal the close button after the view animates in.
mCloseButton.setVisibility(INVISIBLE);
ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() {
@Override
public void run() {
ThreadUtil.getMainThreadHandler().postDelayed(() ->
UiUtils.revealOrHideViewWithAnimation(mCloseButton, VISIBLE,
null /* onFinishRunnable */);
}
}, UiUtils.MEDIAPICKER_TRANSITION_DURATION + CLOSE_BUTTON_REVEAL_STAGGER_MILLIS);
null /* onFinishRunnable */),
UiUtils.MEDIAPICKER_TRANSITION_DURATION +
CLOSE_BUTTON_REVEAL_STAGGER_MILLIS);
}
}