mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Finishing touches of ThreadListViewModel migration
docs and minor improvements
This commit is contained in:
@@ -26,7 +26,6 @@ import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|||||||
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;
|
||||||
import org.briarproject.briar.api.client.PostHeader;
|
|
||||||
import org.briarproject.briar.api.forum.Forum;
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
import org.briarproject.briar.api.forum.ForumManager;
|
import org.briarproject.briar.api.forum.ForumManager;
|
||||||
@@ -151,11 +150,10 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
}, this::setItems);
|
}, this::setItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ForumPostItem loadItem(Transaction txn, PostHeader header)
|
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
if (!(header instanceof ForumPostHeader)) throw new AssertionError();
|
|
||||||
String text = forumManager.getPostText(txn, header.getId());
|
String text = forumManager.getPostText(txn, header.getId());
|
||||||
return new ForumPostItem((ForumPostHeader) header, text);
|
return new ForumPostItem(header, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import androidx.annotation.UiThread;
|
|||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -47,8 +48,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public abstract class ThreadListViewModel<I extends ThreadItem>
|
public abstract class ThreadListViewModel<I extends ThreadItem>
|
||||||
extends DbViewModel
|
extends DbViewModel implements EventListener {
|
||||||
implements EventListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ThreadListViewModel.class.getName());
|
getLogger(ThreadListViewModel.class.getName());
|
||||||
@@ -73,6 +73,9 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
protected volatile GroupId groupId;
|
protected volatile GroupId groupId;
|
||||||
@Nullable
|
@Nullable
|
||||||
private MessageId replyId;
|
private MessageId replyId;
|
||||||
|
/**
|
||||||
|
* Stored list position. Needs to be loaded and set before the list itself.
|
||||||
|
*/
|
||||||
private final AtomicReference<MessageId> storedMessageId =
|
private final AtomicReference<MessageId> storedMessageId =
|
||||||
new AtomicReference<>();
|
new AtomicReference<>();
|
||||||
|
|
||||||
@@ -118,6 +121,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
protected void performInitialLoad() {
|
protected void performInitialLoad() {
|
||||||
|
// load stored MessageId (last list position) before the list itself
|
||||||
loadStoredMessageId();
|
loadStoredMessageId();
|
||||||
loadItems();
|
loadItems();
|
||||||
loadSharingContacts();
|
loadSharingContacts();
|
||||||
@@ -179,7 +183,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
} else {
|
} else {
|
||||||
messageTree.clear();
|
messageTree.clear();
|
||||||
// not null, because hasError() is false
|
// not null, because hasError() is false
|
||||||
messageTree.add(items.getResultOrNull());
|
messageTree.add(requireNonNull(items.getResultOrNull()));
|
||||||
LiveResult<List<I>> result =
|
LiveResult<List<I>> result =
|
||||||
new LiveResult<>(messageTree.depthFirstOrder());
|
new LiveResult<>(messageTree.depthFirstOrder());
|
||||||
this.items.setValue(result);
|
this.items.setValue(result);
|
||||||
@@ -223,6 +227,10 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
|
|
||||||
protected abstract void markItemRead(I item);
|
protected abstract void markItemRead(I item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link MessageId} of the item that was at the top of the
|
||||||
|
* list last time or null if there has been nothing stored, yet.
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
MessageId getAndResetRestoredMessageId() {
|
MessageId getAndResetRestoredMessageId() {
|
||||||
return storedMessageId.getAndSet(null);
|
return storedMessageId.getAndSet(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user