mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Show join messages properly in the threaded conversation
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.android.privategroup.conversation;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.threaded.ThreadListControllerImpl;
|
||||
@@ -17,6 +18,7 @@ import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.privategroup.GroupMessage;
|
||||
import org.briarproject.api.privategroup.GroupMessageFactory;
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
import org.briarproject.api.privategroup.JoinMessageHeader;
|
||||
import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -90,8 +92,13 @@ public class GroupControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String loadMessageBody(MessageId id) throws DbException {
|
||||
return privateGroupManager.getMessageBody(id);
|
||||
protected String loadMessageBody(GroupMessageHeader header)
|
||||
throws DbException {
|
||||
if (header instanceof JoinMessageHeader) {
|
||||
return listener.getApplicationContext()
|
||||
.getString(R.string.groups_member_joined);
|
||||
}
|
||||
return privateGroupManager.getMessageBody(header.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,6 +169,9 @@ public class GroupControllerImpl extends
|
||||
@Override
|
||||
protected GroupMessageItem buildItem(GroupMessageHeader header,
|
||||
String body) {
|
||||
if (header instanceof JoinMessageHeader) {
|
||||
return new JoinMessageItem(header, body);
|
||||
}
|
||||
return new GroupMessageItem(header, body);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.threaded.BaseThreadItemViewHolder;
|
||||
import org.briarproject.android.threaded.ThreadItemAdapter;
|
||||
import org.briarproject.android.threaded.ThreadItemViewHolder;
|
||||
|
||||
@UiThread
|
||||
public class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
||||
@@ -18,11 +20,23 @@ public class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupMessageViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
public int getItemViewType(int position) {
|
||||
GroupMessageItem item = getVisibleItem(position);
|
||||
if (item instanceof JoinMessageItem) {
|
||||
return R.layout.list_item_thread_notice;
|
||||
}
|
||||
return R.layout.list_item_thread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseThreadItemViewHolder<GroupMessageItem> onCreateViewHolder(
|
||||
ViewGroup parent, int type) {
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_item_forum_post, parent, false);
|
||||
return new GroupMessageViewHolder(v);
|
||||
.inflate(type, parent, false);
|
||||
if (type == R.layout.list_item_thread_notice) {
|
||||
return new BaseThreadItemViewHolder<>(v);
|
||||
}
|
||||
return new ThreadItemViewHolder<>(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.briarproject.api.sync.MessageId;
|
||||
|
||||
class GroupMessageItem extends ThreadItem {
|
||||
|
||||
GroupMessageItem(MessageId messageId, MessageId parentId,
|
||||
private GroupMessageItem(MessageId messageId, MessageId parentId,
|
||||
String text, long timestamp, Author author, Status status,
|
||||
boolean isRead) {
|
||||
super(messageId, parentId, text, timestamp, author, status, isRead);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.briarproject.android.privategroup.conversation;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import org.briarproject.android.threaded.ThreadItemViewHolder;
|
||||
|
||||
public class GroupMessageViewHolder
|
||||
extends ThreadItemViewHolder<GroupMessageItem> {
|
||||
|
||||
public GroupMessageViewHolder(View v) {
|
||||
super(v);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.android.privategroup.conversation;
|
||||
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
|
||||
class JoinMessageItem extends GroupMessageItem {
|
||||
|
||||
JoinMessageItem(GroupMessageHeader h,
|
||||
String text) {
|
||||
super(h, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDescendants() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user