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
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +37,6 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import com.android.messaging.R;
@@ -182,12 +182,7 @@ public class ContactPickerFragment extends Fragment implements ContactPickerData
mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_light);
mToolbar.setNavigationContentDescription(R.string.back);
mToolbar.setNavigationOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
mHost.onBackButtonPressed();
}
});
mToolbar.setNavigationOnClickListener(v -> mHost.onBackButtonPressed());
mToolbar.inflateMenu(R.menu.compose_menu);
mToolbar.setOnMenuItemClickListener(this);
@@ -325,13 +320,10 @@ public class ContactPickerFragment extends Fragment implements ContactPickerData
// showImeKeyboard() won't work until the layout is ready, so wait until layout is complete
// before showing the soft keyboard.
UiUtils.doOnceAfterLayoutChange(mRootView, new Runnable() {
@Override
public void run() {
final Activity activity = getActivity();
if (activity != null) {
ImeUtil.get().showImeKeyboard(activity, mRecipientTextView);
}
UiUtils.doOnceAfterLayoutChange(mRootView, () -> {
final Activity activity = getActivity();
if (activity != null) {
ImeUtil.get().showImeKeyboard(activity, mRecipientTextView);
}
});
mRecipientTextView.invalidate();
@@ -541,19 +533,13 @@ public class ContactPickerFragment extends Fragment implements ContactPickerData
mCustomHeaderViewPager.animate().alpha(show ? 1F : 0F)
.setStartDelay(!show ? UiUtils.COMPOSE_TRANSITION_DURATION : 0)
.withStartAction(new Runnable() {
@Override
public void run() {
mCustomHeaderViewPager.setVisibility(View.VISIBLE);
mCustomHeaderViewPager.setAlpha(show ? 0F : 1F);
}
.withStartAction(() -> {
mCustomHeaderViewPager.setVisibility(View.VISIBLE);
mCustomHeaderViewPager.setAlpha(show ? 0F : 1F);
})
.withEndAction(new Runnable() {
@Override
public void run() {
mCustomHeaderViewPager.setVisibility(show ? View.VISIBLE : View.GONE);
mCustomHeaderViewPager.setAlpha(1F);
}
.withEndAction(() -> {
mCustomHeaderViewPager.setVisibility(show ? View.VISIBLE : View.GONE);
mCustomHeaderViewPager.setAlpha(1F);
});
}
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,38 +60,35 @@ public class ContactRecipientPhotoManager implements PhotoManager {
public void populatePhotoBytesAsync(final RecipientEntry entry,
final PhotoManagerCallback callback) {
// Post all media resource request to the main thread.
ThreadUtil.getMainThreadHandler().post(new Runnable() {
@Override
public void run() {
final Uri avatarUri = AvatarUriUtil.createAvatarUri(
ParticipantData.getFromRecipientEntry(entry));
final AvatarRequestDescriptor descriptor =
new AvatarRequestDescriptor(avatarUri, mIconSize, mIconSize);
final BindableMediaRequest<ImageResource> req = descriptor.buildAsyncMediaRequest(
mContext,
new MediaResourceLoadListener<ImageResource>() {
@Override
public void onMediaResourceLoaded(final MediaRequest<ImageResource> request,
final ImageResource resource, final boolean isCached) {
entry.setPhotoBytes(resource.getBytes());
callback.onPhotoBytesAsynchronouslyPopulated();
}
ThreadUtil.getMainThreadHandler().post(() -> {
final Uri avatarUri = AvatarUriUtil.createAvatarUri(
ParticipantData.getFromRecipientEntry(entry));
final AvatarRequestDescriptor descriptor =
new AvatarRequestDescriptor(avatarUri, mIconSize, mIconSize);
final BindableMediaRequest<ImageResource> req = descriptor.buildAsyncMediaRequest(
mContext,
new MediaResourceLoadListener<ImageResource>() {
@Override
public void onMediaResourceLoaded(final MediaRequest<ImageResource> request,
final ImageResource resource, final boolean isCached) {
entry.setPhotoBytes(resource.getBytes());
callback.onPhotoBytesAsynchronouslyPopulated();
}
@Override
public void onMediaResourceLoadError(final MediaRequest<ImageResource> request,
final Exception exception) {
LogUtil.e(LogUtil.BUGLE_TAG, "Photo bytes loading failed due to " +
exception + " request key=" + request.getKey());
@Override
public void onMediaResourceLoadError(final MediaRequest<ImageResource> request,
final Exception exception) {
LogUtil.e(LogUtil.BUGLE_TAG, "Photo bytes loading failed due to " +
exception + " request key=" + request.getKey());
// Fall back to the default avatar image.
callback.onPhotoBytesAsyncLoadFailed();
}});
// Fall back to the default avatar image.
callback.onPhotoBytesAsyncLoadFailed();
}});
// Statically bind the request since it's not bound to any specific piece of UI.
req.bind(IMAGE_BYTES_REQUEST_STATIC_BINDING_ID);
// Statically bind the request since it's not bound to any specific piece of UI.
req.bind(IMAGE_BYTES_REQUEST_STATIC_BINDING_ID);
Factory.get().getMediaResourceManager().requestMediaResourceAsync(req);
}
Factory.get().getMediaResourceManager().requestMediaResourceAsync(req);
});
}
}