mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
fixed unread buttons for threaded lists and akwizgran's comments
This commit is contained in:
@@ -17,7 +17,7 @@ public class DbControllerImpl implements DbController {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(DbControllerImpl.class.getName());
|
||||
|
||||
private final Executor dbExecutor;
|
||||
protected final Executor dbExecutor;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.briar.android.forum.ForumController.ForumListener;
|
||||
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||
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.forum.Forum;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||
@@ -55,10 +56,10 @@ class ForumControllerImpl extends
|
||||
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||
@CryptoExecutor Executor cryptoExecutor,
|
||||
ForumManager forumManager, ForumSharingManager forumSharingManager,
|
||||
EventBus eventBus, Clock clock,
|
||||
EventBus eventBus, Clock clock, MessageTracker messageTracker,
|
||||
AndroidNotificationManager notificationManager) {
|
||||
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||
eventBus, clock, notificationManager);
|
||||
eventBus, clock, notificationManager, messageTracker);
|
||||
this.forumManager = forumManager;
|
||||
this.forumSharingManager = forumSharingManager;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.briar.android.privategroup.conversation.GroupController.GroupListener;
|
||||
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||
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.privategroup.GroupMember;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||
@@ -60,9 +61,10 @@ class GroupControllerImpl extends
|
||||
@CryptoExecutor Executor cryptoExecutor,
|
||||
PrivateGroupManager privateGroupManager,
|
||||
GroupMessageFactory groupMessageFactory, EventBus eventBus,
|
||||
Clock clock, AndroidNotificationManager notificationManager) {
|
||||
MessageTracker messageTracker, Clock clock,
|
||||
AndroidNotificationManager notificationManager) {
|
||||
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||
eventBus, clock, notificationManager);
|
||||
eventBus, clock, notificationManager, messageTracker);
|
||||
this.privateGroupManager = privateGroupManager;
|
||||
this.groupMessageFactory = groupMessageFactory;
|
||||
}
|
||||
|
||||
@@ -66,17 +66,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
||||
revision++;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
void setItemWithIdVisible(MessageId messageId) {
|
||||
if (messageId != null) {
|
||||
int pos = 0;
|
||||
for (I item : items) {
|
||||
@@ -169,7 +159,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
||||
/**
|
||||
* Returns the position of the first unread item below the current viewport
|
||||
*/
|
||||
public int getVisibleUnreadPosBottom() {
|
||||
int getVisibleUnreadPosBottom() {
|
||||
final int positionBottom = layoutManager.findLastVisibleItemPosition();
|
||||
if (positionBottom == NO_POSITION) return NO_POSITION;
|
||||
for (int i = positionBottom + 1; i < items.size(); i++) {
|
||||
@@ -181,7 +171,7 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
||||
/**
|
||||
* Returns the position of the first unread item above the current viewport
|
||||
*/
|
||||
public int getVisibleUnreadPosTop() {
|
||||
int getVisibleUnreadPosTop() {
|
||||
final int positionTop = layoutManager.findFirstVisibleItemPosition();
|
||||
int position = NO_POSITION;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import javax.annotation.Nullable;
|
||||
public interface ThreadItemList<I extends ThreadItem> extends List<I> {
|
||||
|
||||
@Nullable
|
||||
MessageId getBottomVisibleItemId();
|
||||
MessageId getFirstVisibleItemId();
|
||||
|
||||
void setBottomVisibleItemId(@Nullable MessageId bottomVisibleItemId);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ThreadItemListImpl<I extends ThreadItem> extends ArrayList<I>
|
||||
private MessageId bottomVisibleItemId;
|
||||
|
||||
@Override
|
||||
public MessageId getBottomVisibleItemId() {
|
||||
public MessageId getFirstVisibleItemId() {
|
||||
return bottomVisibleItemId;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,11 +149,12 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MessageId getLastVisibleMessageId() {
|
||||
public MessageId getFirstVisibleMessageId() {
|
||||
if (layoutManager != null && adapter != null) {
|
||||
int position =
|
||||
layoutManager.findLastCompletelyVisibleItemPosition();
|
||||
return adapter.getItemAt(position).getId();
|
||||
layoutManager.findFirstVisibleItemPosition();
|
||||
I i = adapter.getItemAt(position);
|
||||
return i == null ? null : adapter.getItemAt(position).getId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -190,10 +191,7 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
||||
if (items.isEmpty()) {
|
||||
list.showData();
|
||||
} else {
|
||||
adapter.setItems(items);
|
||||
adapter.postSetItemWithIdVisible(
|
||||
items.getBottomVisibleItemId());
|
||||
list.showData();
|
||||
initList(items);
|
||||
updateTextInput(replyId);
|
||||
}
|
||||
} else {
|
||||
@@ -209,6 +207,15 @@ public abstract class ThreadListActivity<G extends NamedGroup, A extends ThreadI
|
||||
});
|
||||
}
|
||||
|
||||
private void initList(final ThreadItemList<I> items) {
|
||||
adapter.setItems(items);
|
||||
MessageId messageId = items.getFirstVisibleItemId();
|
||||
if (messageId != null)
|
||||
adapter.setItemWithIdVisible(messageId);
|
||||
updateUnreadCount();
|
||||
list.showData();
|
||||
}
|
||||
|
||||
protected void loadSharingContacts() {
|
||||
getController().loadSharingContacts(
|
||||
new UiResultExceptionHandler<Collection<ContactId>, DbException>(
|
||||
|
||||
@@ -56,7 +56,7 @@ public interface ThreadListController<G extends NamedGroup, I extends ThreadItem
|
||||
interface ThreadListDataSource extends DestroyableContext {
|
||||
|
||||
@UiThread @Nullable
|
||||
MessageId getLastVisibleMessageId();
|
||||
MessageId getFirstVisibleMessageId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
@@ -56,20 +54,21 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
protected final AndroidNotificationManager notificationManager;
|
||||
protected final Executor cryptoExecutor;
|
||||
protected final Clock clock;
|
||||
private final MessageTracker messageTracker;
|
||||
protected volatile L listener;
|
||||
@Inject
|
||||
MessageTracker messageTracker;
|
||||
|
||||
protected ThreadListControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||
@CryptoExecutor Executor cryptoExecutor, EventBus eventBus,
|
||||
Clock clock, AndroidNotificationManager notificationManager) {
|
||||
Clock clock, AndroidNotificationManager notificationManager,
|
||||
MessageTracker messageTracker) {
|
||||
super(dbExecutor, lifecycleManager);
|
||||
this.identityManager = identityManager;
|
||||
this.cryptoExecutor = cryptoExecutor;
|
||||
this.notificationManager = notificationManager;
|
||||
this.clock = clock;
|
||||
this.eventBus = eventBus;
|
||||
this.messageTracker = messageTracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,14 +99,19 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
|
||||
@Override
|
||||
public void onActivityDestroy() {
|
||||
try {
|
||||
messageTracker
|
||||
.storeMessageId(groupId,
|
||||
listener.getLastVisibleMessageId());
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
dbExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
messageTracker
|
||||
.storeMessageId(groupId,
|
||||
listener.getFirstVisibleMessageId());
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@@ -304,19 +308,16 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
@DatabaseExecutor
|
||||
protected abstract void deleteNamedGroup(G groupItem) throws DbException;
|
||||
|
||||
private ThreadItemList<I> buildItems(Collection<H> headers) {
|
||||
private ThreadItemList<I> buildItems(Collection<H> headers)
|
||||
throws DbException {
|
||||
ThreadItemList<I> items = new ThreadItemListImpl<>();
|
||||
for (H h : headers) {
|
||||
items.add(buildItem(h, bodyCache.get(h.getId())));
|
||||
}
|
||||
try {
|
||||
MessageId msgId = messageTracker.loadStoredMessageId(groupId);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loaded last top visible message id " + msgId);
|
||||
items.setBottomVisibleItemId(msgId);
|
||||
} catch (DbException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MessageId msgId = messageTracker.loadStoredMessageId(groupId);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loaded last top visible message id " + msgId);
|
||||
items.setBottomVisibleItemId(msgId);
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class UnreadMessageButton extends FrameLayout {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater
|
||||
.inflate(R.layout.unread_message_button, this, true);
|
||||
inflater.inflate(R.layout.unread_message_button, this, true);
|
||||
|
||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
unread = (TextView) findViewById(R.id.unreadCountView);
|
||||
@@ -64,15 +63,11 @@ public class UnreadMessageButton extends FrameLayout {
|
||||
|
||||
public void setUnreadCount(int count) {
|
||||
if (count == 0) {
|
||||
fab.setVisibility(GONE);
|
||||
// fab.hide();
|
||||
unread.setVisibility(GONE);
|
||||
setVisibility(INVISIBLE);
|
||||
} else {
|
||||
// FIXME: Use animations when upgrading to support library 24.2.0
|
||||
// https://code.google.com/p/android/issues/detail?id=216469
|
||||
fab.setVisibility(VISIBLE);
|
||||
// if (!fab.isShown()) fab.show();
|
||||
unread.setVisibility(VISIBLE);
|
||||
setVisibility(VISIBLE);
|
||||
unread.setText(String.valueOf(count));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user