mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Get rid of SENDING state and publish new live data in order on UiThread
This commit is contained in:
@@ -72,7 +72,6 @@ import static org.briarproject.bramble.util.LogUtils.now;
|
|||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENDING;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
@@ -328,7 +327,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
@UiThread
|
@UiThread
|
||||||
LiveData<SendState> sendMessage(@Nullable String text,
|
LiveData<SendState> sendMessage(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedTimer) {
|
List<AttachmentHeader> headers, long expectedTimer) {
|
||||||
MutableLiveData<SendState> liveData = new MutableLiveData<>(SENDING);
|
MutableLiveData<SendState> liveData = new MutableLiveData<>();
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, txn -> {
|
db.transaction(false, txn -> {
|
||||||
@@ -345,9 +344,11 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
m.getAutoDeleteTimer());
|
m.getAutoDeleteTimer());
|
||||||
// TODO add text to cache when available here
|
// TODO add text to cache when available here
|
||||||
MessageId id = message.getId();
|
MessageId id = message.getId();
|
||||||
txn.attach(() -> attachmentCreator.onAttachmentsSent(id));
|
txn.attach(() -> {
|
||||||
liveData.postValue(SENT);
|
attachmentCreator.onAttachmentsSent(id);
|
||||||
addedHeader.postEvent(h);
|
liveData.setValue(SENT);
|
||||||
|
addedHeader.setEvent(h);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (UnexpectedTimerException e) {
|
} catch (UnexpectedTimerException e) {
|
||||||
liveData.postValue(UNEXPECTED_TIMER);
|
liveData.postValue(UNEXPECTED_TIMER);
|
||||||
@@ -365,8 +366,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
// Sending is only possible (setReady(true)) after loading all messages
|
// Sending is only possible (setReady(true)) after loading all messages
|
||||||
// which happens after the contact has been loaded.
|
// which happens after the contact has been loaded.
|
||||||
// privateMessageFormat is loaded together with contact
|
// privateMessageFormat is loaded together with contact
|
||||||
Contact contact =
|
Contact contact = requireNonNull(contactItem.getValue()).getContact();
|
||||||
requireNonNull(this.contactItem.getValue()).getContact();
|
|
||||||
GroupId groupId = messagingManager.getContactGroup(contact).getId();
|
GroupId groupId = messagingManager.getContactGroup(contact).getId();
|
||||||
PrivateMessageFormat format =
|
PrivateMessageFormat format =
|
||||||
requireNonNull(privateMessageFormat.getValue());
|
requireNonNull(privateMessageFormat.getValue());
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ public class TextSendController implements TextInputListener {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SendState {SENDING, SENT, ERROR, UNEXPECTED_TIMER}
|
public enum SendState {SENT, ERROR, UNEXPECTED_TIMER}
|
||||||
|
|
||||||
public interface SendListener extends LifecycleOwner {
|
public interface SendListener extends LifecycleOwner {
|
||||||
LiveData<SendState> onSendClick(@Nullable String text,
|
LiveData<SendState> onSendClick(@Nullable String text,
|
||||||
|
|||||||
Reference in New Issue
Block a user