mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Improve error reporting for SMS export.
This commit is contained in:
@@ -67,6 +67,17 @@ fun <T> Cursor.requireObject(column: String, serializer: StringSerializer<T>): T
|
||||
return serializer.deserialize(CursorUtil.requireString(this, column))
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun Cursor.readToSingleLong(defaultValue: Long = 0): Long {
|
||||
return use {
|
||||
if (it.moveToFirst()) {
|
||||
it.getLong(0)
|
||||
} else {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Cursor.readToList(predicate: (T) -> Boolean = { true }, mapper: (Cursor) -> T): List<T> {
|
||||
val list = mutableListOf<T>()
|
||||
use {
|
||||
|
||||
@@ -4,12 +4,16 @@ import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import io.reactivex.rxjava3.observers.DefaultObserver;
|
||||
|
||||
public class SimpleTask {
|
||||
|
||||
/**
|
||||
@@ -37,6 +41,35 @@ public class SimpleTask {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a task in the background and passes the result of the computation to a task that is run
|
||||
* on the main thread. Will only invoke the {@code foregroundTask} if the provided {@link Lifecycle}
|
||||
* is or enters in the future a valid (i.e. visible) state. In this way, it is very similar to
|
||||
* {@link AsyncTask}, but is safe in that you can guarantee your task won't be called when your
|
||||
* view is in an invalid state.
|
||||
*/
|
||||
public static <E> void runWhenValid(@NonNull Lifecycle lifecycle, @NonNull BackgroundTask<E> backgroundTask, @NonNull ForegroundTask<E> foregroundTask) {
|
||||
lifecycle.addObserver(new LifecycleEventObserver() {
|
||||
@Override public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) {
|
||||
if (isValid(lifecycle)) {
|
||||
lifecycle.removeObserver(this);
|
||||
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
final E result = backgroundTask.run();
|
||||
|
||||
if (isValid(lifecycle)) {
|
||||
ThreadUtil.runOnMain(() -> {
|
||||
if (isValid(lifecycle)) {
|
||||
foregroundTask.run(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a task in the background and passes the result of the computation to a task that is run on
|
||||
* the main thread. Essentially {@link AsyncTask}, but lambda-compatible.
|
||||
|
||||
Reference in New Issue
Block a user