mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
thread list: fix redundant load and dissolved dialog showing again after screen rotation
This commit is contained in:
@@ -79,7 +79,7 @@ public class GroupActivity extends
|
||||
|
||||
// start with group disabled and enable when not dissolved
|
||||
setGroupEnabled(false);
|
||||
viewModel.isDissolved().observe(this, dissolved -> {
|
||||
viewModel.isDissolved().observeEvent(this, dissolved -> {
|
||||
setGroupEnabled(!dissolved);
|
||||
if (dissolved) onGroupDissolved();
|
||||
});
|
||||
@@ -153,7 +153,7 @@ public class GroupActivity extends
|
||||
|
||||
@Override
|
||||
public void onReplyClick(GroupMessageItem item) {
|
||||
Boolean isDissolved = viewModel.isDissolved().getValue();
|
||||
Boolean isDissolved = viewModel.isDissolved().getLastValue();
|
||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.briar.android.sharing.SharingController;
|
||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
@@ -70,8 +72,8 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
private final MutableLiveData<PrivateGroup> privateGroup =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> isDissolved =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveEvent<Boolean> isDissolved =
|
||||
new MutableLiveEvent<>();
|
||||
|
||||
@Inject
|
||||
GroupViewModel(Application application,
|
||||
@@ -128,7 +130,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
} else if (e instanceof GroupDissolvedEvent) {
|
||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||
if (g.getGroupId().equals(groupId)) {
|
||||
isDissolved.setValue(true);
|
||||
isDissolved.setEvent(true);
|
||||
}
|
||||
} else {
|
||||
super.eventOccurred(e);
|
||||
@@ -136,8 +138,8 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupId(GroupId groupId) {
|
||||
super.setGroupId(groupId);
|
||||
protected void performInitialLoad() {
|
||||
super.performInitialLoad();
|
||||
loadPrivateGroup(groupId);
|
||||
}
|
||||
|
||||
@@ -163,7 +165,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
loadList(txn -> {
|
||||
// check first if group is dissolved
|
||||
isDissolved
|
||||
.postValue(privateGroupManager.isDissolved(txn, groupId));
|
||||
.postEvent(privateGroupManager.isDissolved(txn, groupId));
|
||||
// now continue to load the items
|
||||
long start = now();
|
||||
List<GroupMessageHeader> headers =
|
||||
@@ -275,7 +277,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
return isCreator;
|
||||
}
|
||||
|
||||
LiveData<Boolean> isDissolved() {
|
||||
LiveEvent<Boolean> isDissolved() {
|
||||
return isDissolved;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,9 +115,14 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
||||
* Needs to be called right after initialization,
|
||||
* before calling any other methods.
|
||||
*/
|
||||
@CallSuper
|
||||
public void setGroupId(GroupId groupId) {
|
||||
public final void setGroupId(GroupId groupId) {
|
||||
boolean needsInitialLoad = this.groupId == null;
|
||||
this.groupId = groupId;
|
||||
if (needsInitialLoad) performInitialLoad();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
protected void performInitialLoad() {
|
||||
loadStoredMessageId();
|
||||
loadItems();
|
||||
loadSharingContacts();
|
||||
|
||||
@@ -39,6 +39,17 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
|
||||
super.observeForever(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last value of the event (even if already consumed)
|
||||
* or null if there hasn't been any value so far.
|
||||
*/
|
||||
@Nullable
|
||||
public T getLastValue() {
|
||||
ConsumableEvent<T> event = getValue();
|
||||
if (event == null) return null;
|
||||
return event.content;
|
||||
}
|
||||
|
||||
static class ConsumableEvent<T> {
|
||||
|
||||
private final T content;
|
||||
|
||||
Reference in New Issue
Block a user