mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
@@ -66,31 +66,29 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
revision++;
|
revision++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBottomItem(MessageId messageId) {
|
// Useful when the adapter has not calculated the dimension yet
|
||||||
|
void postSetItemWithIdVisible(@Nullable final MessageId messageId) {
|
||||||
|
new Handler().post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setItemWithIdVisible(messageId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setItemWithIdVisible(@Nullable MessageId messageId) {
|
||||||
if (messageId != null) {
|
if (messageId != null) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (I item : items) {
|
for (I item : items) {
|
||||||
if (item.getId().equals(messageId)) {
|
if (item.getId().equals(messageId)) {
|
||||||
scrollToPosition(pos);
|
layoutManager.scrollToPosition(pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToPosition(final int pos) {
|
|
||||||
// Post call ensures that the list scrolls AFTER it has been propagated
|
|
||||||
// and the layout has been calculated.
|
|
||||||
handler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
layoutManager.scrollToPosition(pos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItems(Collection<I> items) {
|
public void setItems(Collection<I> items) {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
this.items.addAll(items);
|
this.items.addAll(items);
|
||||||
|
|||||||
@@ -148,7 +148,8 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageId getBottomVisibleMessageId() {
|
@Nullable
|
||||||
|
public MessageId getLastVisibleMessageId() {
|
||||||
if (layoutManager != null && adapter != null) {
|
if (layoutManager != null && adapter != null) {
|
||||||
int position =
|
int position =
|
||||||
layoutManager.findLastCompletelyVisibleItemPosition();
|
layoutManager.findLastCompletelyVisibleItemPosition();
|
||||||
@@ -190,7 +191,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
|||||||
list.showData();
|
list.showData();
|
||||||
} else {
|
} else {
|
||||||
adapter.setItems(items);
|
adapter.setItems(items);
|
||||||
adapter.setBottomItem(
|
adapter.postSetItemWithIdVisible(
|
||||||
items.getBottomVisibleItemId());
|
items.getBottomVisibleItemId());
|
||||||
list.showData();
|
list.showData();
|
||||||
updateTextInput(replyId);
|
updateTextInput(replyId);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public interface ThreadListController<G extends NamedGroup, I extends ThreadItem
|
|||||||
|
|
||||||
void deleteNamedGroup(ExceptionHandler<DbException> handler);
|
void deleteNamedGroup(ExceptionHandler<DbException> handler);
|
||||||
|
|
||||||
interface ThreadListListener<H> extends DestroyableContext {
|
interface ThreadListListener<H> extends ThreadListDataSource {
|
||||||
@UiThread
|
@UiThread
|
||||||
void onHeaderReceived(H header);
|
void onHeaderReceived(H header);
|
||||||
|
|
||||||
@@ -53,10 +53,10 @@ public interface ThreadListController<G extends NamedGroup, I extends ThreadItem
|
|||||||
void onInvitationAccepted(ContactId c);
|
void onInvitationAccepted(ContactId c);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ThreadListDataSource {
|
interface ThreadListDataSource extends DestroyableContext {
|
||||||
|
|
||||||
@UiThread @Nullable
|
@UiThread @Nullable
|
||||||
MessageId getBottomVisibleMessageId();
|
MessageId getLastVisibleMessageId();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
|||||||
protected volatile L listener;
|
protected volatile L listener;
|
||||||
@Inject
|
@Inject
|
||||||
MessageTracker messageTracker;
|
MessageTracker messageTracker;
|
||||||
private ThreadListDataSource source;
|
|
||||||
|
|
||||||
protected ThreadListControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
protected ThreadListControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
@@ -83,13 +82,6 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityCreate(Activity activity) {
|
public void onActivityCreate(Activity activity) {
|
||||||
listener = (L) activity;
|
listener = (L) activity;
|
||||||
if (activity instanceof ThreadListDataSource) {
|
|
||||||
source = (ThreadListDataSource) activity;
|
|
||||||
} else {
|
|
||||||
throw new ClassCastException(
|
|
||||||
"Activity " + activity.getClass().getSimpleName() +
|
|
||||||
" must implement ThreadListDataSource");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -111,9 +103,10 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
|||||||
try {
|
try {
|
||||||
messageTracker
|
messageTracker
|
||||||
.storeMessageId(groupId,
|
.storeMessageId(groupId,
|
||||||
source.getBottomVisibleMessageId());
|
listener.getLastVisibleMessageId());
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
e.printStackTrace();
|
if (LOG.isLoggable(WARNING))
|
||||||
|
LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class MessageTrackerImpl implements MessageTracker {
|
|||||||
try {
|
try {
|
||||||
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(g);
|
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(g);
|
||||||
byte[] msgBytes = d.getOptionalRaw(GROUP_KEY_STORED_MESSAGE_ID);
|
byte[] msgBytes = d.getOptionalRaw(GROUP_KEY_STORED_MESSAGE_ID);
|
||||||
return msgBytes != null? new MessageId(msgBytes) : null;
|
return msgBytes != null ? new MessageId(msgBytes) : null;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user