Finished renaming entry to item, reduced some visibility.

This commit is contained in:
akwizgran
2016-10-19 18:24:09 +01:00
parent 690142ce07
commit b3e5d1ff85
6 changed files with 48 additions and 49 deletions

View File

@@ -9,14 +9,14 @@ import org.briarproject.api.sync.MessageId;
import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe
public class ForumItem extends ThreadItem {
class ForumItem extends ThreadItem {
ForumItem(ForumPostHeader h, String body) {
super(h.getId(), h.getParentId(), body, h.getTimestamp(), h.getAuthor(),
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) {
super(messageId, parentId, text, timestamp, author, status, true);
}

View File

@@ -10,9 +10,9 @@ import org.briarproject.R;
import org.briarproject.android.threaded.ThreadItemAdapter;
@UiThread
public class NestedForumAdapter extends ThreadItemAdapter<ForumItem> {
class NestedForumAdapter extends ThreadItemAdapter<ForumItem> {
public NestedForumAdapter(ThreadItemListener<ForumItem> listener,
NestedForumAdapter(ThreadItemListener<ForumItem> listener,
LinearLayoutManager layoutManager) {
super(listener, layoutManager);
}

View File

@@ -8,13 +8,13 @@ import org.briarproject.api.sync.MessageId;
class GroupMessageItem extends ThreadItem {
public GroupMessageItem(MessageId messageId, MessageId parentId,
GroupMessageItem(MessageId messageId, MessageId parentId,
String text, long timestamp, Author author, Status status,
boolean 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(),
h.getAuthorStatus(), h.isRead());
}

View File

@@ -22,14 +22,12 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
static final int UNDEFINED = -1;
private final NestedTreeList<I> items =
new NestedTreeList<>();
private final Map<I, ValueAnimator> animatingItems =
new HashMap<>();
private final NestedTreeList<I> items = new NestedTreeList<>();
private final Map<I, ValueAnimator> animatingItems = new HashMap<>();
// highlight not dependant on time
private I replyItem;
// temporary highlight
private I addedEntry;
private I addedItem;
private final ThreadItemListener<I> listener;
private final LinearLayoutManager layoutManager;
@@ -53,7 +51,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
return getVisiblePos(null);
}
public I getReplyItem() {
I getReplyItem() {
return replyItem;
}
@@ -65,7 +63,7 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
public void add(I item) {
items.add(item);
addedEntry = item;
addedItem = item;
if (item.getParentId() == null) {
notifyItemInserted(getVisiblePos(item));
} 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);
if (visiblePos == NO_POSITION && item.getParentId() != null) {
// 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);
int parentPos = getVisiblePos(higherItem);
if (parentPos != NO_POSITION) {
// parent or ancestor is visible, entry's visibility
// parent or ancestor is visible, item's visibility
// is ensured
notifyItemChanged(parentPos);
visiblePos = parentPos;
@@ -142,17 +140,17 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
return counter;
}
public void setReplyItem(@Nullable I entry) {
void setReplyItem(@Nullable I item) {
if (replyItem != null) {
notifyItemChanged(getVisiblePos(replyItem));
}
replyItem = entry;
replyItem = item;
if (replyItem != null) {
notifyItemChanged(getVisiblePos(replyItem));
}
}
public void setReplyItemById(MessageId id) {
void setReplyItemById(MessageId id) {
for (I item : items) {
if (item.getId().equals(id)) {
setReplyItem(item);
@@ -215,17 +213,18 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
/**
* 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
* visible entries, or null if position is larger than
* the number of visible entries.
*
* @param position is visible item index
* @return the visible item at index 'position' from an ordered list of
* visible items, or null if 'position' is larger than the number of
* visible items.
*/
@Nullable
public I getVisibleItem(int position) {
int levelLimit = UNDEFINED;
for (I item : items) {
if (levelLimit >= 0) {
// skip hidden entries that their parent is hiding
// skip hidden items that their parent is hiding
if (item.getLevel() > levelLimit) {
continue;
}
@@ -241,33 +240,34 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
return null;
}
public boolean isVisible(I item) {
boolean isVisible(I item) {
return getVisiblePos(item) != NO_POSITION;
}
/**
* Returns the visible position of the given ThreadItem
* @param item the ThreadItem to find the visible position of, or null to
* return the total count of visible elements
* @return the visible position of item, or the total number of visible
* elements if sEntry is null. If item is not visible NO_POSITION is
* Returns the visible position of the given item.
*
* @param item the item to find the visible position of, or null to
* return the total count of visible items.
* @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.
*/
private int getVisiblePos(@Nullable I item) {
int visibleCounter = 0;
int levelLimit = UNDEFINED;
for (I iItem : items) {
for (I i : items) {
if (levelLimit >= 0) {
if (iItem.getLevel() > levelLimit) {
// skip all the entries below a non visible branch
if (i.getLevel() > levelLimit) {
// skip all the items below a non visible branch
continue;
}
levelLimit = UNDEFINED;
}
if (item != null && item.equals(iItem)) {
if (item != null && item.equals(i)) {
return visibleCounter;
} else if (!iItem.isShowingDescendants()) {
levelLimit = iItem.getLevel();
} else if (!i.isShowingDescendants()) {
levelLimit = i.getLevel();
}
visibleCounter++;
}
@@ -275,11 +275,11 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
}
I getAddedItem() {
return addedEntry;
return addedItem;
}
void clearAddedItem() {
addedEntry = null;
addedItem = null;
}
void addAnimatingItem(I item, ValueAnimator anim) {
@@ -290,7 +290,8 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
animatingItems.remove(item);
}
public interface ThreadItemListener<I> {
protected interface ThreadItemListener<I> {
void onItemVisible(I item);
void onReplyClick(I item);

View File

@@ -339,11 +339,11 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
protected abstract void deleteNamedGroup(G groupItem) throws DbException;
private List<I> buildItems(Collection<H> headers) {
List<I> entries = new ArrayList<>();
List<I> items = new ArrayList<>();
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);

View File

@@ -93,18 +93,16 @@ public class ForumActivityTest {
}
private List<ForumItem> getDummyData() {
ForumItem[] forumEntries = new ForumItem[6];
for (int i = 0; i < forumEntries.length; i++) {
ForumItem[] forumItems = new ForumItem[6];
for (int i = 0; i < forumItems.length; i++) {
AuthorId authorId = new AuthorId(TestUtils.getRandomId());
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
Author author = new Author(authorId, AUTHORS[i], publicKey);
forumEntries[i] =
new ForumItem(AUTHOR_IDS[i], PARENT_AUTHOR_IDS[i],
AUTHORS[i], System.currentTimeMillis(), author,
UNKNOWN);
forumEntries[i].setLevel(LEVELS[i]);
forumItems[i] = new ForumItem(AUTHOR_IDS[i], PARENT_AUTHOR_IDS[i],
AUTHORS[i], System.currentTimeMillis(), author, UNKNOWN);
forumItems[i].setLevel(LEVELS[i]);
}
return new ArrayList<>(Arrays.asList(forumEntries));
return new ArrayList<>(Arrays.asList(forumItems));
}
@Test