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