mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Make thread related utility methods available for use in all modules.
This commit is contained in:
@@ -11,13 +11,13 @@ import androidx.lifecycle.Observer;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
@@ -79,14 +79,14 @@ public final class LiveRecipient {
|
||||
* use {@link #removeObservers(LifecycleOwner)}.
|
||||
*/
|
||||
public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<Recipient> observer) {
|
||||
Util.postToMain(() -> observableLiveData.observe(owner, observer));
|
||||
ThreadUtil.postToMain(() -> observableLiveData.observe(owner, observer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all observers of this data registered for the given LifecycleOwner.
|
||||
*/
|
||||
public void removeObservers(@NonNull LifecycleOwner owner) {
|
||||
Util.runOnMain(() -> observableLiveData.removeObservers(owner));
|
||||
ThreadUtil.runOnMain(() -> observableLiveData.removeObservers(owner));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ public final class LiveRecipient {
|
||||
* {@link #observe(LifecycleOwner, Observer<Recipient>)} if possible, as it is lifecycle-safe.
|
||||
*/
|
||||
public void observeForever(@NonNull RecipientForeverObserver observer) {
|
||||
Util.postToMain(() -> {
|
||||
ThreadUtil.postToMain(() -> {
|
||||
if (observers.isEmpty()) {
|
||||
observableLiveData.observeForever(foreverObserver);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public final class LiveRecipient {
|
||||
* Unsubscribes the provided {@link RecipientForeverObserver} from future changes.
|
||||
*/
|
||||
public void removeForeverObserver(@NonNull RecipientForeverObserver observer) {
|
||||
Util.postToMain(() -> {
|
||||
ThreadUtil.postToMain(() -> {
|
||||
observers.remove(observer);
|
||||
|
||||
if (observers.isEmpty()) {
|
||||
@@ -127,7 +127,7 @@ public final class LiveRecipient {
|
||||
return current;
|
||||
}
|
||||
|
||||
if (Util.isMainThread()) {
|
||||
if (ThreadUtil.isMainThread()) {
|
||||
Log.w(TAG, "[Resolve][MAIN] " + getId(), new Throwable());
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public final class LiveRecipient {
|
||||
|
||||
if (getId().isUnknown()) return;
|
||||
|
||||
if (Util.isMainThread()) {
|
||||
if (ThreadUtil.isMainThread()) {
|
||||
Log.w(TAG, "[Refresh][MAIN] " + id, new Throwable());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.thoughtcrime.securesms.BlockUnblockDialog;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.VerifyIdentityActivity;
|
||||
@@ -30,7 +31,6 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
||||
import org.thoughtcrime.securesms.recipients.ui.managerecipient.ManageRecipientActivity;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -205,7 +205,7 @@ final class RecipientDialogViewModel extends ViewModel {
|
||||
|
||||
@WorkerThread
|
||||
private void showErrorToast(@NonNull GroupChangeFailureReason e) {
|
||||
Util.runOnMain(() -> Toast.makeText(context, GroupErrors.getUserDisplayMessage(e), Toast.LENGTH_LONG).show());
|
||||
ThreadUtil.runOnMain(() -> Toast.makeText(context, GroupErrors.getUserDisplayMessage(e), Toast.LENGTH_LONG).show());
|
||||
}
|
||||
|
||||
static class AdminActionStatus {
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.thoughtcrime.securesms.BlockUnblockDialog;
|
||||
import org.thoughtcrime.securesms.ExpirationDialog;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -38,7 +39,6 @@ import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
|
||||
import java.util.List;
|
||||
@@ -207,11 +207,11 @@ public final class ManageRecipientViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
void onAddToGroupButton(@NonNull Activity activity) {
|
||||
manageRecipientRepository.getGroupMembership(existingGroups -> Util.runOnMain(() -> activity.startActivity(AddToGroupsActivity.newIntent(activity, manageRecipientRepository.getRecipientId(), existingGroups))));
|
||||
manageRecipientRepository.getGroupMembership(existingGroups -> ThreadUtil.runOnMain(() -> activity.startActivity(AddToGroupsActivity.newIntent(activity, manageRecipientRepository.getRecipientId(), existingGroups))));
|
||||
}
|
||||
|
||||
private void withRecipient(@NonNull Consumer<Recipient> mainThreadRecipientCallback) {
|
||||
manageRecipientRepository.getRecipient(recipient -> Util.runOnMain(() -> mainThreadRecipientCallback.accept(recipient)));
|
||||
manageRecipientRepository.getRecipient(recipient -> ThreadUtil.runOnMain(() -> mainThreadRecipientCallback.accept(recipient)));
|
||||
}
|
||||
|
||||
private static @NonNull List<Recipient> filterSharedGroupList(@NonNull List<Recipient> groups,
|
||||
|
||||
Reference in New Issue
Block a user