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 -6
View File
@@ -57,12 +57,7 @@ public final class Assert {
// This is called from FactoryImpl once the Gservices class is initialized.
public static void initializeGservices (final BugleGservices gservices) {
gservices.registerForChanges(new Runnable() {
@Override
public void run() {
refreshGservices(gservices);
}
});
gservices.registerForChanges(() -> refreshGservices(gservices));
refreshGservices(gservices);
}
@@ -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.
@@ -20,7 +21,6 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.UserManager;
import android.text.TextUtils;
@@ -68,13 +68,7 @@ public class BugleActivityUtil {
.setMessage(R.string.requires_sms_permissions_message)
.setCancelable(false)
.setNegativeButton(R.string.requires_sms_permissions_close_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog,
final int button) {
System.exit(0);
}
})
(dialog, button) -> System.exit(0))
.show();
return false;
}
+6 -19
View File
@@ -22,7 +22,6 @@ import android.app.AlertDialog;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
@@ -50,7 +49,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.StreamCorruptedException;
@@ -193,13 +191,7 @@ public class DebugUtils {
}
});
builder.setAdapter(arrayAdapter,
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface arg0, final int pos) {
arrayAdapter.getItem(pos).run();
}
});
builder.setAdapter(arrayAdapter, (arg0, pos) -> arrayAdapter.getItem(pos).run());
builder.create().show();
}
@@ -231,16 +223,11 @@ public class DebugUtils {
@Override
protected String[] doInBackgroundTimed(final Void... params) {
final File dir = DebugUtils.getDebugFilesDir();
return dir.list(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String filename) {
return filename != null
&& ((mAction == DebugSmsMmsFromDumpFileDialogFragment.ACTION_EMAIL
&& filename.equals(DumpDatabaseAction.DUMP_NAME))
|| filename.startsWith(MmsUtils.MMS_DUMP_PREFIX)
|| filename.startsWith(MmsUtils.SMS_DUMP_PREFIX));
}
});
return dir.list((dir1, filename) -> filename != null
&& ((mAction == DebugSmsMmsFromDumpFileDialogFragment.ACTION_EMAIL
&& filename.equals(DumpDatabaseAction.DUMP_NAME))
|| filename.startsWith(MmsUtils.MMS_DUMP_PREFIX)
|| filename.startsWith(MmsUtils.SMS_DUMP_PREFIX)));
}
}
+2 -6
View File
@@ -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.
@@ -58,12 +59,7 @@ public class LogUtil {
// This is called from FactoryImpl once the Gservices class is initialized.
public static void initializeGservices (final BugleGservices gservices) {
gservices.registerForChanges(new Runnable() {
@Override
public void run() {
refreshGservices(gservices);
}
});
gservices.registerForChanges(() -> refreshGservices(gservices));
refreshGservices(gservices);
}
@@ -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.
@@ -42,15 +43,12 @@ public class MediaUtilImpl extends MediaUtil {
afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(final MediaPlayer mp) {
if (completionListener != null) {
completionListener.onCompletion();
}
mp.stop();
mp.release();
mediaPlayer.setOnCompletionListener(mp -> {
if (completionListener != null) {
completionListener.onCompletion();
}
mp.stop();
mp.release();
});
mediaPlayer.seekTo(0);
mediaPlayer.start();
@@ -63,4 +61,4 @@ public class MediaUtilImpl extends MediaUtil {
completionListener.onCompletion();
}
}
}
}
@@ -96,15 +96,12 @@ public abstract class SafeAsyncTask<Params, Progress, Result>
Assert.isTrue(mThreadPoolRequested);
if (mCancelExecutionOnTimeout) {
ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() {
@Override
public void run() {
if (getStatus() == Status.RUNNING) {
// Cancel the task if it's still running.
LogUtil.w(LogUtil.BUGLE_TAG, String.format("%s timed out and is canceled",
this));
cancel(true /* mayInterruptIfRunning */);
}
ThreadUtil.getMainThreadHandler().postDelayed(() -> {
if (getStatus() == Status.RUNNING) {
// Cancel the task if it's still running.
LogUtil.w(LogUtil.BUGLE_TAG, String.format("%s timed out and is canceled",
this));
cancel(true /* mayInterruptIfRunning */);
}
}, mMaxExecutionTimeMillis);
}
@@ -160,14 +157,11 @@ public abstract class SafeAsyncTask<Params, Progress, Result>
if (withWakeLock) {
final Intent intent = new Intent();
sWakeLock.acquire(Factory.get().getApplicationContext(), intent, WAKELOCK_OP);
THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
try {
runnable.run();
} finally {
sWakeLock.release(intent, WAKELOCK_OP);
}
THREAD_POOL_EXECUTOR.execute(() -> {
try {
runnable.run();
} finally {
sWakeLock.release(intent, WAKELOCK_OP);
}
});
} else {