Finishing touches of ThreadListViewModel migration

docs and minor improvements
This commit is contained in:
Torsten Grote
2021-01-29 08:33:28 -03:00
parent d670179e30
commit ae4a04bada
2 changed files with 13 additions and 7 deletions

View File

@@ -26,7 +26,6 @@ import org.briarproject.briar.android.threaded.ThreadListViewModel;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.client.MessageTracker;
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.ForumInvitationResponse;
import org.briarproject.briar.api.forum.ForumManager;
@@ -151,11 +150,10 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
}, this::setItems);
}
private ForumPostItem loadItem(Transaction txn, PostHeader header)
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
throws DbException {
if (!(header instanceof ForumPostHeader)) throw new AssertionError();
String text = forumManager.getPostText(txn, header.getId());
return new ForumPostItem((ForumPostHeader) header, text);
return new ForumPostItem(header, text);
}
@Override

View File

@@ -39,6 +39,7 @@ import androidx.annotation.UiThread;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -47,8 +48,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public abstract class ThreadListViewModel<I extends ThreadItem>
extends DbViewModel
implements EventListener {
extends DbViewModel implements EventListener {
private static final Logger LOG =
getLogger(ThreadListViewModel.class.getName());
@@ -73,6 +73,9 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
protected volatile GroupId groupId;
@Nullable
private MessageId replyId;
/**
* Stored list position. Needs to be loaded and set before the list itself.
*/
private final AtomicReference<MessageId> storedMessageId =
new AtomicReference<>();
@@ -118,6 +121,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
@CallSuper
protected void performInitialLoad() {
// load stored MessageId (last list position) before the list itself
loadStoredMessageId();
loadItems();
loadSharingContacts();
@@ -179,7 +183,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
} else {
messageTree.clear();
// not null, because hasError() is false
messageTree.add(items.getResultOrNull());
messageTree.add(requireNonNull(items.getResultOrNull()));
LiveResult<List<I>> result =
new LiveResult<>(messageTree.depthFirstOrder());
this.items.setValue(result);
@@ -223,6 +227,10 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
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
MessageId getAndResetRestoredMessageId() {
return storedMessageId.getAndSet(null);