mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Finished renaming entry to item, reduced some visibility.
This commit is contained in:
@@ -9,14 +9,14 @@ import org.briarproject.api.sync.MessageId;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
public class ForumItem extends ThreadItem {
|
class ForumItem extends ThreadItem {
|
||||||
|
|
||||||
ForumItem(ForumPostHeader h, String body) {
|
ForumItem(ForumPostHeader h, String body) {
|
||||||
super(h.getId(), h.getParentId(), body, h.getTimestamp(), h.getAuthor(),
|
super(h.getId(), h.getParentId(), body, h.getTimestamp(), h.getAuthor(),
|
||||||
h.getAuthorStatus(), h.isRead());
|
h.getAuthorStatus(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForumItem(MessageId messageId, MessageId parentId, String text,
|
ForumItem(MessageId messageId, MessageId parentId, String text,
|
||||||
long timestamp, Author author, Status status) {
|
long timestamp, Author author, Status status) {
|
||||||
super(messageId, parentId, text, timestamp, author, status, true);
|
super(messageId, parentId, text, timestamp, author, status, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import org.briarproject.R;
|
|||||||
import org.briarproject.android.threaded.ThreadItemAdapter;
|
import org.briarproject.android.threaded.ThreadItemAdapter;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
public class NestedForumAdapter extends ThreadItemAdapter<ForumItem> {
|
class NestedForumAdapter extends ThreadItemAdapter<ForumItem> {
|
||||||
|
|
||||||
public NestedForumAdapter(ThreadItemListener<ForumItem> listener,
|
NestedForumAdapter(ThreadItemListener<ForumItem> listener,
|
||||||
LinearLayoutManager layoutManager) {
|
LinearLayoutManager layoutManager) {
|
||||||
super(listener, layoutManager);
|
super(listener, layoutManager);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import org.briarproject.api.sync.MessageId;
|
|||||||
|
|
||||||
class GroupMessageItem extends ThreadItem {
|
class GroupMessageItem extends ThreadItem {
|
||||||
|
|
||||||
public GroupMessageItem(MessageId messageId, MessageId parentId,
|
GroupMessageItem(MessageId messageId, MessageId parentId,
|
||||||
String text, long timestamp, Author author, Status status,
|
String text, long timestamp, Author author, Status status,
|
||||||
boolean isRead) {
|
boolean isRead) {
|
||||||
super(messageId, parentId, text, timestamp, author, status, isRead);
|
super(messageId, parentId, text, timestamp, author, status, isRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupMessageItem(GroupMessageHeader h, String text) {
|
GroupMessageItem(GroupMessageHeader h, String text) {
|
||||||
this(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
|
this(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
|
||||||
h.getAuthorStatus(), h.isRead());
|
h.getAuthorStatus(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,12 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
static final int UNDEFINED = -1;
|
static final int UNDEFINED = -1;
|
||||||
|
|
||||||
private final NestedTreeList<I> items =
|
private final NestedTreeList<I> items = new NestedTreeList<>();
|
||||||
new NestedTreeList<>();
|
private final Map<I, ValueAnimator> animatingItems = new HashMap<>();
|
||||||
private final Map<I, ValueAnimator> animatingItems =
|
|
||||||
new HashMap<>();
|
|
||||||
// highlight not dependant on time
|
// highlight not dependant on time
|
||||||
private I replyItem;
|
private I replyItem;
|
||||||
// temporary highlight
|
// temporary highlight
|
||||||
private I addedEntry;
|
private I addedItem;
|
||||||
|
|
||||||
private final ThreadItemListener<I> listener;
|
private final ThreadItemListener<I> listener;
|
||||||
private final LinearLayoutManager layoutManager;
|
private final LinearLayoutManager layoutManager;
|
||||||
@@ -53,7 +51,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return getVisiblePos(null);
|
return getVisiblePos(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public I getReplyItem() {
|
I getReplyItem() {
|
||||||
return replyItem;
|
return replyItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +63,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
public void add(I item) {
|
public void add(I item) {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
addedEntry = item;
|
addedItem = item;
|
||||||
if (item.getParentId() == null) {
|
if (item.getParentId() == null) {
|
||||||
notifyItemInserted(getVisiblePos(item));
|
notifyItemInserted(getVisiblePos(item));
|
||||||
} else {
|
} else {
|
||||||
@@ -96,7 +94,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollTo(I item) {
|
void scrollTo(I item) {
|
||||||
int visiblePos = getVisiblePos(item);
|
int visiblePos = getVisiblePos(item);
|
||||||
if (visiblePos == NO_POSITION && item.getParentId() != null) {
|
if (visiblePos == NO_POSITION && item.getParentId() != null) {
|
||||||
// The item is not visible due to being hidden by its parent item.
|
// The item is not visible due to being hidden by its parent item.
|
||||||
@@ -110,7 +108,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
showDescendants(higherItem);
|
showDescendants(higherItem);
|
||||||
int parentPos = getVisiblePos(higherItem);
|
int parentPos = getVisiblePos(higherItem);
|
||||||
if (parentPos != NO_POSITION) {
|
if (parentPos != NO_POSITION) {
|
||||||
// parent or ancestor is visible, entry's visibility
|
// parent or ancestor is visible, item's visibility
|
||||||
// is ensured
|
// is ensured
|
||||||
notifyItemChanged(parentPos);
|
notifyItemChanged(parentPos);
|
||||||
visiblePos = parentPos;
|
visiblePos = parentPos;
|
||||||
@@ -142,17 +140,17 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplyItem(@Nullable I entry) {
|
void setReplyItem(@Nullable I item) {
|
||||||
if (replyItem != null) {
|
if (replyItem != null) {
|
||||||
notifyItemChanged(getVisiblePos(replyItem));
|
notifyItemChanged(getVisiblePos(replyItem));
|
||||||
}
|
}
|
||||||
replyItem = entry;
|
replyItem = item;
|
||||||
if (replyItem != null) {
|
if (replyItem != null) {
|
||||||
notifyItemChanged(getVisiblePos(replyItem));
|
notifyItemChanged(getVisiblePos(replyItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplyItemById(MessageId id) {
|
void setReplyItemById(MessageId id) {
|
||||||
for (I item : items) {
|
for (I item : items) {
|
||||||
if (item.getId().equals(id)) {
|
if (item.getId().equals(id)) {
|
||||||
setReplyItem(item);
|
setReplyItem(item);
|
||||||
@@ -215,17 +213,18 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the visible item at the given position
|
* Returns the visible item at the given position
|
||||||
* @param position is visible entry index
|
*
|
||||||
* @return the visible entry at index position from an ordered list of
|
* @param position is visible item index
|
||||||
* visible entries, or null if position is larger than
|
* @return the visible item at index 'position' from an ordered list of
|
||||||
* the number of visible entries.
|
* visible items, or null if 'position' is larger than the number of
|
||||||
|
* visible items.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public I getVisibleItem(int position) {
|
public I getVisibleItem(int position) {
|
||||||
int levelLimit = UNDEFINED;
|
int levelLimit = UNDEFINED;
|
||||||
for (I item : items) {
|
for (I item : items) {
|
||||||
if (levelLimit >= 0) {
|
if (levelLimit >= 0) {
|
||||||
// skip hidden entries that their parent is hiding
|
// skip hidden items that their parent is hiding
|
||||||
if (item.getLevel() > levelLimit) {
|
if (item.getLevel() > levelLimit) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -241,33 +240,34 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible(I item) {
|
boolean isVisible(I item) {
|
||||||
return getVisiblePos(item) != NO_POSITION;
|
return getVisiblePos(item) != NO_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the visible position of the given ThreadItem
|
* Returns the visible position of the given item.
|
||||||
* @param item the ThreadItem to find the visible position of, or null to
|
*
|
||||||
* return the total count of visible elements
|
* @param item the item to find the visible position of, or null to
|
||||||
* @return the visible position of item, or the total number of visible
|
* return the total count of visible items.
|
||||||
* elements if sEntry is null. If item is not visible NO_POSITION is
|
* @return the visible position of 'item', or the total number of visible
|
||||||
|
* items if 'item' is null. If 'item' is not visible, NO_POSITION is
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
private int getVisiblePos(@Nullable I item) {
|
private int getVisiblePos(@Nullable I item) {
|
||||||
int visibleCounter = 0;
|
int visibleCounter = 0;
|
||||||
int levelLimit = UNDEFINED;
|
int levelLimit = UNDEFINED;
|
||||||
for (I iItem : items) {
|
for (I i : items) {
|
||||||
if (levelLimit >= 0) {
|
if (levelLimit >= 0) {
|
||||||
if (iItem.getLevel() > levelLimit) {
|
if (i.getLevel() > levelLimit) {
|
||||||
// skip all the entries below a non visible branch
|
// skip all the items below a non visible branch
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
levelLimit = UNDEFINED;
|
levelLimit = UNDEFINED;
|
||||||
}
|
}
|
||||||
if (item != null && item.equals(iItem)) {
|
if (item != null && item.equals(i)) {
|
||||||
return visibleCounter;
|
return visibleCounter;
|
||||||
} else if (!iItem.isShowingDescendants()) {
|
} else if (!i.isShowingDescendants()) {
|
||||||
levelLimit = iItem.getLevel();
|
levelLimit = i.getLevel();
|
||||||
}
|
}
|
||||||
visibleCounter++;
|
visibleCounter++;
|
||||||
}
|
}
|
||||||
@@ -275,11 +275,11 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
}
|
}
|
||||||
|
|
||||||
I getAddedItem() {
|
I getAddedItem() {
|
||||||
return addedEntry;
|
return addedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAddedItem() {
|
void clearAddedItem() {
|
||||||
addedEntry = null;
|
addedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addAnimatingItem(I item, ValueAnimator anim) {
|
void addAnimatingItem(I item, ValueAnimator anim) {
|
||||||
@@ -290,7 +290,8 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
animatingItems.remove(item);
|
animatingItems.remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ThreadItemListener<I> {
|
protected interface ThreadItemListener<I> {
|
||||||
|
|
||||||
void onItemVisible(I item);
|
void onItemVisible(I item);
|
||||||
|
|
||||||
void onReplyClick(I item);
|
void onReplyClick(I item);
|
||||||
|
|||||||
@@ -339,11 +339,11 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
|||||||
protected abstract void deleteNamedGroup(G groupItem) throws DbException;
|
protected abstract void deleteNamedGroup(G groupItem) throws DbException;
|
||||||
|
|
||||||
private List<I> buildItems(Collection<H> headers) {
|
private List<I> buildItems(Collection<H> headers) {
|
||||||
List<I> entries = new ArrayList<>();
|
List<I> items = new ArrayList<>();
|
||||||
for (H h : headers) {
|
for (H h : headers) {
|
||||||
entries.add(buildItem(h, bodyCache.get(h.getId())));
|
items.add(buildItem(h, bodyCache.get(h.getId())));
|
||||||
}
|
}
|
||||||
return entries;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract I buildItem(H header, String body);
|
protected abstract I buildItem(H header, String body);
|
||||||
|
|||||||
@@ -93,18 +93,16 @@ public class ForumActivityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<ForumItem> getDummyData() {
|
private List<ForumItem> getDummyData() {
|
||||||
ForumItem[] forumEntries = new ForumItem[6];
|
ForumItem[] forumItems = new ForumItem[6];
|
||||||
for (int i = 0; i < forumEntries.length; i++) {
|
for (int i = 0; i < forumItems.length; i++) {
|
||||||
AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||||
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
Author author = new Author(authorId, AUTHORS[i], publicKey);
|
Author author = new Author(authorId, AUTHORS[i], publicKey);
|
||||||
forumEntries[i] =
|
forumItems[i] = new ForumItem(AUTHOR_IDS[i], PARENT_AUTHOR_IDS[i],
|
||||||
new ForumItem(AUTHOR_IDS[i], PARENT_AUTHOR_IDS[i],
|
AUTHORS[i], System.currentTimeMillis(), author, UNKNOWN);
|
||||||
AUTHORS[i], System.currentTimeMillis(), author,
|
forumItems[i].setLevel(LEVELS[i]);
|
||||||
UNKNOWN);
|
|
||||||
forumEntries[i].setLevel(LEVELS[i]);
|
|
||||||
}
|
}
|
||||||
return new ArrayList<>(Arrays.asList(forumEntries));
|
return new ArrayList<>(Arrays.asList(forumItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user