mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
UI code cleanup.
This commit is contained in:
@@ -25,15 +25,15 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
protected final OnItemClickListener listener;
|
||||
protected Context ctx;
|
||||
|
||||
public BaseContactListAdapter(Context context, OnItemClickListener listener) {
|
||||
this.ctx = context;
|
||||
public BaseContactListAdapter(Context ctx, OnItemClickListener listener) {
|
||||
this.ctx = ctx;
|
||||
this.listener = listener;
|
||||
this.contacts = new SortedList<>(ContactListItem.class,
|
||||
new SortedListCallBacks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final VH ui, final int position) {
|
||||
public void onBindViewHolder(final VH ui, int position) {
|
||||
final ContactListItem item = getItem(position);
|
||||
|
||||
Author author = item.getContact().getAuthor();
|
||||
@@ -96,6 +96,7 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
}
|
||||
|
||||
public static class BaseContactHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public final ViewGroup layout;
|
||||
public final ImageView avatar;
|
||||
public final TextView name;
|
||||
@@ -132,7 +133,8 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected class SortedListCallBacks extends SortedList.Callback<ContactListItem> {
|
||||
protected class SortedListCallBacks
|
||||
extends SortedList.Callback<ContactListItem> {
|
||||
|
||||
@Override
|
||||
public void onInserted(int position, int count) {
|
||||
@@ -185,5 +187,4 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(View view, ContactListItem item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,17 +20,17 @@ public class ContactListAdapter
|
||||
|
||||
@Override
|
||||
public ContactHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_contact, viewGroup, false);
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_contact, viewGroup, false);
|
||||
|
||||
return new ContactHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ContactHolder ui, final int position) {
|
||||
public void onBindViewHolder(ContactHolder ui, int position) {
|
||||
super.onBindViewHolder(ui, position);
|
||||
|
||||
final ContactListItem item = getItem(position);
|
||||
ContactListItem item = getItem(position);
|
||||
|
||||
// name and unread count
|
||||
String contactName = item.getContact().getAuthor().getName();
|
||||
@@ -84,5 +84,4 @@ public class ContactListAdapter
|
||||
public int compareContactListItems(ContactListItem c1, ContactListItem c2) {
|
||||
return compareByTime(c1, c2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,18 +54,16 @@ import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||
|
||||
public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
public final static String TAG = "ContactListFragment";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactListFragment.class.getName());
|
||||
|
||||
public final static String TAG = "ContactListFragment";
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Inject
|
||||
protected ConnectionRegistry connectionRegistry;
|
||||
@Inject
|
||||
protected EventBus eventBus;
|
||||
|
||||
private ContactListAdapter adapter = null;
|
||||
private BriarRecyclerView list = null;
|
||||
|
||||
@@ -80,15 +78,17 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
|
||||
|
||||
@Inject
|
||||
public ContactListFragment() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -160,11 +160,11 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void loadContacts() {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<ContactListItem>();
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
try {
|
||||
ContactId id = c.getId();
|
||||
@@ -196,6 +196,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void displayContacts(final List<ContactListItem> contacts) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (contacts.size() == 0) list.showData();
|
||||
else adapter.addAll(contacts);
|
||||
@@ -203,9 +204,10 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactAddedEvent) {
|
||||
if(((ContactAddedEvent) e).isActive()) {
|
||||
if (((ContactAddedEvent) e).isActive()) {
|
||||
LOG.info("Contact added as active, reloading");
|
||||
loadContacts();
|
||||
}
|
||||
@@ -233,6 +235,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void reloadConversation(final GroupId g) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ContactId c = messagingManager.getContactId(g);
|
||||
@@ -252,6 +255,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
private void updateItem(final ContactId c,
|
||||
final Collection<ConversationItem> messages) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -265,6 +269,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void removeItem(final ContactId c) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -275,6 +280,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
|
||||
private void setConnected(final ContactId c, final boolean connected) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int position = adapter.findItemPosition(c);
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -286,14 +292,13 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
});
|
||||
}
|
||||
|
||||
/** This needs to be called from the DbThread */
|
||||
// This needs to be called from the DB thread
|
||||
private Collection<ConversationItem> getMessages(ContactId id)
|
||||
throws DbException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Collection<ConversationItem> messages =
|
||||
new ArrayList<ConversationItem>();
|
||||
Collection<ConversationItem> messages = new ArrayList<>();
|
||||
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(id);
|
||||
|
||||
@@ -24,12 +24,12 @@ import android.widget.Toast;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.introduction.IntroductionActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
@@ -55,7 +55,6 @@ import org.briarproject.api.introduction.IntroductionManager;
|
||||
import org.briarproject.api.introduction.IntroductionMessage;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.messaging.MessagingManager;
|
||||
import org.briarproject.api.messaging.PrivateMessage;
|
||||
import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||
@@ -95,25 +94,37 @@ public class ConversationActivity extends BriarActivity
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ConversationActivity.class.getName());
|
||||
|
||||
@Inject protected AndroidNotificationManager notificationManager;
|
||||
@Inject protected ConnectionRegistry connectionRegistry;
|
||||
@Inject @CryptoExecutor protected Executor cryptoExecutor;
|
||||
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
|
||||
private ConversationAdapter adapter = null;
|
||||
@Inject
|
||||
protected AndroidNotificationManager notificationManager;
|
||||
@Inject
|
||||
protected ConnectionRegistry connectionRegistry;
|
||||
@Inject
|
||||
@CryptoExecutor
|
||||
protected Executor cryptoExecutor;
|
||||
|
||||
private Map<MessageId, byte[]> bodyCache = new HashMap<>();
|
||||
private ConversationAdapter adapter;
|
||||
private CircleImageView toolbarAvatar;
|
||||
private ImageView toolbarStatus;
|
||||
private TextView toolbarTitle;
|
||||
private BriarRecyclerView list = null;
|
||||
private EditText content = null;
|
||||
private ImageButton sendButton = null;
|
||||
private BriarRecyclerView list;
|
||||
private EditText content;
|
||||
private ImageButton sendButton;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile ContactManager contactManager;
|
||||
@Inject protected volatile MessagingManager messagingManager;
|
||||
@Inject protected volatile EventBus eventBus;
|
||||
@Inject protected volatile PrivateMessageFactory privateMessageFactory;
|
||||
@Inject protected volatile IntroductionManager introductionManager;
|
||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile ContactManager contactManager;
|
||||
@Inject
|
||||
protected volatile MessagingManager messagingManager;
|
||||
@Inject
|
||||
protected volatile EventBus eventBus;
|
||||
@Inject
|
||||
protected volatile PrivateMessageFactory privateMessageFactory;
|
||||
@Inject
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
private volatile GroupId groupId = null;
|
||||
private volatile ContactId contactId = null;
|
||||
private volatile String contactName = null;
|
||||
@@ -218,6 +229,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadData() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -248,6 +260,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void displayContactDetails() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toolbarAvatar.setImageDrawable(
|
||||
new IdenticonDrawable(contactIdenticonKey));
|
||||
@@ -273,6 +286,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadMessages() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -304,6 +318,7 @@ public class ConversationActivity extends BriarActivity
|
||||
final Collection<IntroductionMessage> introductions,
|
||||
final Collection<ForumInvitationMessage> invitations) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendButton.setEnabled(true);
|
||||
if (headers.isEmpty() && introductions.isEmpty() &&
|
||||
@@ -312,8 +327,7 @@ public class ConversationActivity extends BriarActivity
|
||||
// so let the list know to hide progress bar
|
||||
list.showData();
|
||||
} else {
|
||||
List<ConversationItem> items =
|
||||
new ArrayList<ConversationItem>();
|
||||
List<ConversationItem> items = new ArrayList<>();
|
||||
for (PrivateMessageHeader h : headers) {
|
||||
ConversationMessageItem item =
|
||||
(ConversationMessageItem) ConversationItem
|
||||
@@ -350,6 +364,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void loadMessageBody(final PrivateMessageHeader h) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -370,6 +385,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void displayMessageBody(final MessageId m, final byte[] body) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bodyCache.put(m, body);
|
||||
SparseArray<ConversationMessageItem> messages =
|
||||
@@ -399,9 +415,8 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void markMessagesRead() {
|
||||
List<MessageId> unread = new ArrayList<MessageId>();
|
||||
SparseArray<IncomingItem> list =
|
||||
adapter.getIncomingMessages();
|
||||
List<MessageId> unread = new ArrayList<>();
|
||||
SparseArray<IncomingItem> list = adapter.getIncomingMessages();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
IncomingItem item = list.valueAt(i);
|
||||
if (!item.isRead()) unread.add(item.getId());
|
||||
@@ -414,6 +429,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markMessagesRead(final Collection<MessageId> unread) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -432,6 +448,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||
@@ -501,6 +518,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markMessageReadIfNew(final Message m) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ConversationItem item = adapter.getLastItem();
|
||||
if (item != null) {
|
||||
@@ -519,6 +537,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void markNewMessageRead(final Message m) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
messagingManager.setReadFlag(m.getId(), true);
|
||||
@@ -534,10 +553,10 @@ public class ConversationActivity extends BriarActivity
|
||||
private void markMessages(final Collection<MessageId> messageIds,
|
||||
final boolean sent, final boolean seen) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set<MessageId> messages = new HashSet<MessageId>(messageIds);
|
||||
SparseArray<OutgoingItem> list =
|
||||
adapter.getOutgoingMessages();
|
||||
Set<MessageId> messages = new HashSet<>(messageIds);
|
||||
SparseArray<OutgoingItem> list = adapter.getOutgoingMessages();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
OutgoingItem item = list.valueAt(i);
|
||||
if (messages.contains(item.getId())) {
|
||||
@@ -550,6 +569,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
markMessagesRead();
|
||||
String message = content.getText().toString();
|
||||
@@ -569,6 +589,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void createMessage(final byte[] body, final long timestamp) {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
storeMessage(privateMessageFactory.createPrivateMessage(
|
||||
@@ -582,6 +603,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void storeMessage(final PrivateMessage m) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -617,6 +639,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void removeContact() {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// make sure contactId is initialised
|
||||
@@ -648,6 +671,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void hideIntroductionActionWhenOneContact(final MenuItem item) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (contactManager.getActiveContacts().size() < 2) {
|
||||
@@ -689,11 +713,7 @@ public class ConversationActivity extends BriarActivity
|
||||
timestamp);
|
||||
}
|
||||
loadMessages();
|
||||
} catch (DbException e) {
|
||||
introductionResponseError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (FormatException e) {
|
||||
} catch (DbException | FormatException e) {
|
||||
introductionResponseError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -41,6 +41,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private final SortedList<ConversationItem> items =
|
||||
new SortedList<>(ConversationItem.class, new ListCallbacks());
|
||||
|
||||
private Context ctx;
|
||||
private IntroductionHandler intro;
|
||||
private String contactName;
|
||||
@@ -67,44 +68,38 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
// outgoing message (local)
|
||||
if (type == MSG_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_msg_out, viewGroup, false);
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_msg_out, viewGroup, false);
|
||||
return new MessageHolder(v, type);
|
||||
}
|
||||
else if (type == INTRODUCTION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_introduction_in, viewGroup, false);
|
||||
} else if (type == INTRODUCTION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_introduction_in, viewGroup, false);
|
||||
return new IntroductionHolder(v, type);
|
||||
}
|
||||
else if (type == INTRODUCTION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_introduction_out, viewGroup, false);
|
||||
} else if (type == INTRODUCTION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_introduction_out, viewGroup, false);
|
||||
return new IntroductionHolder(v, type);
|
||||
}
|
||||
else if (type == NOTICE_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_notice_in, viewGroup, false);
|
||||
} else if (type == NOTICE_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_notice_in, viewGroup, false);
|
||||
return new NoticeHolder(v, type);
|
||||
}
|
||||
else if (type == NOTICE_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_notice_out, viewGroup, false);
|
||||
} else if (type == NOTICE_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_notice_out, viewGroup, false);
|
||||
return new NoticeHolder(v, type);
|
||||
}
|
||||
else if (type == FORUM_INVITATION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_forum_invitation_in, viewGroup, false);
|
||||
} else if (type == FORUM_INVITATION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_in, viewGroup, false);
|
||||
return new InvitationHolder(v, type);
|
||||
}
|
||||
else if (type == FORUM_INVITATION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_forum_invitation_out, viewGroup, false);
|
||||
} else if (type == FORUM_INVITATION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_out, viewGroup, false);
|
||||
return new InvitationHolder(v, type);
|
||||
}
|
||||
// incoming message (non-local)
|
||||
else {
|
||||
v = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.list_item_msg_in, viewGroup, false);
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_msg_in, viewGroup, false);
|
||||
return new MessageHolder(v, type);
|
||||
}
|
||||
}
|
||||
@@ -126,10 +121,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationOutItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationOutItem) item, position);
|
||||
(ConversationForumInvitationOutItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationInItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationInItem) item, position);
|
||||
(ConversationForumInvitationInItem) item);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled Conversation Item");
|
||||
}
|
||||
@@ -200,13 +195,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
(ConversationIntroductionOutItem) item;
|
||||
if (i.isSeen()) {
|
||||
ui.status.setImageResource(R.drawable.message_delivered);
|
||||
ui.message.status.setImageResource(R.drawable.message_delivered_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_delivered_white);
|
||||
} else if (i.isSent()) {
|
||||
ui.status.setImageResource(R.drawable.message_sent);
|
||||
ui.message.status.setImageResource(R.drawable.message_sent_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_sent_white);
|
||||
} else {
|
||||
ui.status.setImageResource(R.drawable.message_stored);
|
||||
ui.message.status.setImageResource(R.drawable.message_stored_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_stored_white);
|
||||
}
|
||||
}
|
||||
// Incoming Introduction Request (Answered)
|
||||
@@ -279,7 +277,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
private void bindInvitation(InvitationHolder ui,
|
||||
final ConversationForumInvitationItem item, final int position) {
|
||||
final ConversationForumInvitationItem item) {
|
||||
|
||||
ForumInvitationMessage fim = item.getForumInvitationMessage();
|
||||
|
||||
@@ -301,13 +299,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
(ConversationForumInvitationOutItem) item;
|
||||
if (i.isSeen()) {
|
||||
ui.status.setImageResource(R.drawable.message_delivered);
|
||||
ui.message.status.setImageResource(R.drawable.message_delivered_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_delivered_white);
|
||||
} else if (i.isSent()) {
|
||||
ui.status.setImageResource(R.drawable.message_sent);
|
||||
ui.message.status.setImageResource(R.drawable.message_sent_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_sent_white);
|
||||
} else {
|
||||
ui.status.setImageResource(R.drawable.message_stored);
|
||||
ui.message.status.setImageResource(R.drawable.message_stored_white);
|
||||
ui.message.status.setImageResource(
|
||||
R.drawable.message_stored_white);
|
||||
}
|
||||
}
|
||||
// Incoming Invitation
|
||||
@@ -321,9 +322,8 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent =
|
||||
new Intent(ctx,
|
||||
AvailableForumsActivity.class);
|
||||
Intent intent = new Intent(ctx,
|
||||
AvailableForumsActivity.class);
|
||||
ctx.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@@ -380,7 +380,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public SparseArray<ConversationMessageItem> getPrivateMessages() {
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ConversationItem item = items.get(i);
|
||||
@@ -426,19 +426,17 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class IntroductionHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private View messageLayout;
|
||||
final private MessageHolder message;
|
||||
final private TextView text;
|
||||
final private Button acceptButton;
|
||||
final private Button declineButton;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final View messageLayout;
|
||||
private final MessageHolder message;
|
||||
private final TextView text;
|
||||
private final Button acceptButton;
|
||||
private final Button declineButton;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public IntroductionHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.introductionLayout);
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
message = new MessageHolder(messageLayout,
|
||||
type == INTRODUCTION_IN ? MSG_IN : MSG_OUT);
|
||||
@@ -457,15 +455,13 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class NoticeHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private TextView text;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final TextView text;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public NoticeHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.noticeLayout);
|
||||
text = (TextView) v.findViewById(R.id.noticeText);
|
||||
date = (TextView) v.findViewById(R.id.noticeTime);
|
||||
|
||||
@@ -479,18 +475,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private static class InvitationHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final private ViewGroup layout;
|
||||
final private View messageLayout;
|
||||
final private MessageHolder message;
|
||||
final private TextView text;
|
||||
final private Button showForumsButton;
|
||||
final private TextView date;
|
||||
final private ImageView status;
|
||||
private final View messageLayout;
|
||||
private final MessageHolder message;
|
||||
private final TextView text;
|
||||
private final Button showForumsButton;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public InvitationHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.introductionLayout);
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
message = new MessageHolder(messageLayout,
|
||||
type == FORUM_INVITATION_IN ? MSG_IN : MSG_OUT);
|
||||
@@ -507,6 +501,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
private class ListCallbacks extends SortedList.Callback<ConversationItem> {
|
||||
|
||||
@Override
|
||||
public void onInserted(int position, int count) {
|
||||
notifyItemRangeInserted(position, count);
|
||||
@@ -551,8 +546,6 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public interface IntroductionHandler {
|
||||
void respondToIntroduction(final SessionId sessionId,
|
||||
final boolean accept);
|
||||
void respondToIntroduction(SessionId sessionId, boolean accept);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,5 +29,4 @@ public class ConversationForumInvitationInItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
|
||||
abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
|
||||
private ForumInvitationMessage fim;
|
||||
private final ForumInvitationMessage fim;
|
||||
|
||||
public ConversationForumInvitationItem(ForumInvitationMessage fim) {
|
||||
super(fim.getId(), fim.getTimestamp());
|
||||
@@ -15,5 +15,4 @@ abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
public ForumInvitationMessage getForumInvitationMessage() {
|
||||
return fim;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
* This class is needed and can not be replaced by an ConversationNoticeOutItem,
|
||||
* because it carries the optional invitation message
|
||||
* to be displayed as a regular private message.
|
||||
*
|
||||
* <p/>
|
||||
* This class is not thread-safe
|
||||
*/
|
||||
public class ConversationForumInvitationOutItem
|
||||
@@ -45,5 +45,4 @@ public class ConversationForumInvitationOutItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationIntroductionInItem extends ConversationIntroductionItem
|
||||
@@ -29,5 +28,4 @@ public class ConversationIntroductionInItem extends ConversationIntroductionItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
|
||||
// This class is not thread-safe
|
||||
abstract class ConversationIntroductionItem extends ConversationItem {
|
||||
|
||||
private IntroductionRequest ir;
|
||||
private final IntroductionRequest ir;
|
||||
private boolean answered;
|
||||
|
||||
public ConversationIntroductionItem(IntroductionRequest ir) {
|
||||
@@ -25,5 +26,4 @@ abstract class ConversationIntroductionItem extends ConversationItem {
|
||||
public void setAnswered(boolean answered) {
|
||||
this.answered = answered;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,5 +45,4 @@ public class ConversationIntroductionOutItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -103,8 +103,9 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
/** This method should not be used to get user-facing objects,
|
||||
* Its purpose is to provider data for the contact list.
|
||||
/**
|
||||
* This method should not be used to get user-facing objects,
|
||||
* Its purpose is to provider data for the contact list.
|
||||
*/
|
||||
public static ConversationItem from(IntroductionMessage im) {
|
||||
if (im.isLocal())
|
||||
@@ -115,17 +116,24 @@ public abstract class ConversationItem {
|
||||
}
|
||||
|
||||
protected interface OutgoingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
boolean isSent();
|
||||
|
||||
void setSent(boolean sent);
|
||||
|
||||
boolean isSeen();
|
||||
|
||||
void setSeen(boolean seen);
|
||||
}
|
||||
|
||||
protected interface IncomingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
boolean isRead();
|
||||
|
||||
void setRead(boolean read);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,5 +28,4 @@ public class ConversationMessageInItem extends ConversationMessageItem
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,5 +26,4 @@ abstract class ConversationMessageItem extends ConversationItem {
|
||||
void setBody(byte[] body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,5 +39,4 @@ public class ConversationMessageOutItem extends ConversationMessageItem
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.briarproject.android.contact;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationNoticeInItem extends ConversationNoticeItem implements
|
||||
ConversationItem.IncomingItem {
|
||||
public class ConversationNoticeInItem extends ConversationNoticeItem
|
||||
implements ConversationItem.IncomingItem {
|
||||
|
||||
private boolean read;
|
||||
|
||||
@@ -29,5 +29,4 @@ public class ConversationNoticeInItem extends ConversationNoticeItem implements
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.briarproject.api.sync.MessageId;
|
||||
|
||||
abstract class ConversationNoticeItem extends ConversationItem {
|
||||
|
||||
private String text;
|
||||
private final String text;
|
||||
|
||||
public ConversationNoticeItem(MessageId id, String text, long time) {
|
||||
super(id, time);
|
||||
@@ -15,5 +15,4 @@ abstract class ConversationNoticeItem extends ConversationItem {
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@ package org.briarproject.android.contact;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationNoticeOutItem extends ConversationNoticeItem implements
|
||||
ConversationItem.OutgoingItem {
|
||||
public class ConversationNoticeOutItem extends ConversationNoticeItem
|
||||
implements ConversationItem.OutgoingItem {
|
||||
|
||||
private boolean sent, seen;
|
||||
|
||||
public ConversationNoticeOutItem(MessageId id, String text, long time,
|
||||
boolean sent, boolean seen) {
|
||||
|
||||
super(id, text, time);
|
||||
|
||||
this.sent = sent;
|
||||
@@ -41,5 +40,4 @@ public class ConversationNoticeOutItem extends ConversationNoticeItem implements
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user