Improve error reporting for SMS export.

This commit is contained in:
Cody Henthorne
2022-10-19 22:11:31 -04:00
committed by GitHub
parent 262f762d7f
commit 690e1e60ba
33 changed files with 933 additions and 95 deletions

View File

@@ -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 {

View File

@@ -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.