return number of confirm messages sent

This commit is contained in:
ameba23
2022-02-24 13:11:09 +01:00
parent a665179377
commit 5bd4ab689b

View File

@@ -24,6 +24,8 @@ public class RemoteWipeActivatedViewModel extends AndroidViewModel implements
private final DatabaseComponent db; private final DatabaseComponent db;
private final MutableLiveEvent<Boolean> confirmSent = private final MutableLiveEvent<Boolean> confirmSent =
new MutableLiveEvent<>(); new MutableLiveEvent<>();
private int numberOfConfirmMessages;
private int messagesSent = 0;
@Inject @Inject
RemoteWipeActivatedViewModel( RemoteWipeActivatedViewModel(
@@ -33,15 +35,15 @@ public class RemoteWipeActivatedViewModel extends AndroidViewModel implements
super(application); super(application);
this.remoteWipeManager = remoteWipeManager; this.remoteWipeManager = remoteWipeManager;
this.db = db; this.db = db;
eventBus.addListener(this); eventBus.addListener(this);
} }
public void sendConfirmMessages() { public void sendConfirmMessages() {
try { try {
db.transaction(false, numberOfConfirmMessages = db.transactionWithResult(false,
remoteWipeManager::sendConfirmMessages); remoteWipeManager::sendConfirmMessages);
} catch (DbException | FormatException e) { } catch (DbException | FormatException e) {
System.out.println(e);
// If there is a problem sending the messages, just wipe // If there is a problem sending the messages, just wipe
confirmSent.postEvent(true); confirmSent.postEvent(true);
} }
@@ -53,9 +55,12 @@ public class RemoteWipeActivatedViewModel extends AndroidViewModel implements
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
// As soon as we know a message is sent, we can wipe // As soon as we know the confirm messages are sent, we can wipe
if (e instanceof MessagesSentEvent) { if (e instanceof MessagesSentEvent) {
confirmSent.postEvent(true); messagesSent++;
if (messagesSent >= numberOfConfirmMessages) {
confirmSent.postEvent(true);
}
} }
} }
} }