mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
address issues found in final review
(except refactoring of conversation item classes)
This commit is contained in:
@@ -303,6 +303,7 @@ public class ContactListFragment extends BaseEventFragment {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading message headers took " + duration + " ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
Collection<IntroductionMessage> introductions =
|
||||
introductionManager
|
||||
.getIntroductionMessages(id);
|
||||
|
||||
@@ -90,7 +90,6 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ConversationActivity.class.getName());
|
||||
private static final int INTRODUCTION_REQUEST_CODE = 0;
|
||||
|
||||
@Inject protected AndroidNotificationManager notificationManager;
|
||||
@Inject protected ConnectionRegistry connectionRegistry;
|
||||
@@ -128,12 +127,12 @@ public class ConversationActivity extends BriarActivity
|
||||
setContentView(R.layout.activity_conversation);
|
||||
|
||||
// Custom Toolbar
|
||||
final Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbarAvatar = (CircleImageView) tb.findViewById(R.id.contactAvatar);
|
||||
toolbarStatus = (ImageView) tb.findViewById(R.id.contactStatus);
|
||||
toolbarTitle = (TextView) tb.findViewById(R.id.contactName);
|
||||
setSupportActionBar(tb);
|
||||
final ActionBar ab = getSupportActionBar();
|
||||
ActionBar ab = getSupportActionBar();
|
||||
if (ab != null) {
|
||||
ab.setDisplayShowHomeEnabled(true);
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
@@ -202,8 +201,7 @@ public class ConversationActivity extends BriarActivity
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeCustomAnimation(this, android.R.anim.slide_in_left,
|
||||
android.R.anim.slide_out_right);
|
||||
ActivityCompat.startActivityForResult(this, intent,
|
||||
INTRODUCTION_REQUEST_CODE, options.toBundle());
|
||||
ActivityCompat.startActivity(this, intent, options.toBundle());
|
||||
return true;
|
||||
case R.id.action_social_remove_person:
|
||||
askToRemoveContact();
|
||||
@@ -213,17 +211,6 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
|
||||
if (requestCode == INTRODUCTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -274,7 +261,7 @@ public class ConversationActivity extends BriarActivity
|
||||
toolbarStatus
|
||||
.setContentDescription(getString(R.string.offline));
|
||||
}
|
||||
adapter.setIdenticonKey(contactIdenticonKey, contactName);
|
||||
adapter.setContactInformation(contactIdenticonKey, contactName);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -284,6 +271,8 @@ public class ConversationActivity extends BriarActivity
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
if (contactId == null)
|
||||
contactId = messagingManager.getContactId(groupId);
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(contactId);
|
||||
Collection<IntroductionMessage> introductions =
|
||||
@@ -372,11 +361,10 @@ public class ConversationActivity extends BriarActivity
|
||||
if (item.getId().equals(m)) {
|
||||
item.setBody(body);
|
||||
adapter.notifyItemChanged(messages.keyAt(i));
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Scroll to the bottom
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -385,11 +373,9 @@ public class ConversationActivity extends BriarActivity
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (adapter != null) {
|
||||
adapter.add(item);
|
||||
// Scroll to the bottom
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
adapter.add(item);
|
||||
// Scroll to the bottom
|
||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -609,6 +595,10 @@ public class ConversationActivity extends BriarActivity
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
// make sure contactId is initialised
|
||||
if (contactId == null)
|
||||
contactId = messagingManager.getContactId(groupId);
|
||||
// remove contact with that ID
|
||||
contactManager.removeContact(contactId);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
@@ -657,7 +647,8 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respondToIntroduction(final SessionId sessionId, final boolean accept) {
|
||||
public void respondToIntroduction(final SessionId sessionId,
|
||||
final boolean accept) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -665,9 +656,13 @@ public class ConversationActivity extends BriarActivity
|
||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||
try {
|
||||
if (accept) {
|
||||
introductionManager.acceptIntroduction(contactId, sessionId, timestamp);
|
||||
introductionManager
|
||||
.acceptIntroduction(contactId, sessionId,
|
||||
timestamp);
|
||||
} else {
|
||||
introductionManager.declineIntroduction(contactId, sessionId, timestamp);
|
||||
introductionManager
|
||||
.declineIntroduction(contactId, sessionId,
|
||||
timestamp);
|
||||
}
|
||||
loadMessages();
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -88,21 +88,14 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
IntroductionHandler introductionHandler) {
|
||||
ctx = context;
|
||||
intro = introductionHandler;
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public void setIdenticonKey(byte[] key, String contactName) {
|
||||
this.identiconKey = key;
|
||||
public void setContactInformation(byte[] identiconKey, String contactName) {
|
||||
this.identiconKey = identiconKey;
|
||||
this.contactName = contactName;
|
||||
// FIXME this breaks the progress animation because it is called early before data is loaded
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return getItem(position).getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position).getType();
|
||||
@@ -147,11 +140,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder ui, final int position) {
|
||||
public void onBindViewHolder(ViewHolder ui, int position) {
|
||||
ConversationItem item = getItem(position);
|
||||
if (item instanceof ConversationMessageItem) {
|
||||
bindMessage((MessageHolder) ui, (ConversationMessageItem) item,
|
||||
position);
|
||||
bindMessage((MessageHolder) ui, (ConversationMessageItem) item);
|
||||
} else if (item instanceof ConversationIntroductionOutItem) {
|
||||
bindIntroduction((IntroductionHolder) ui,
|
||||
(ConversationIntroductionOutItem) item, position);
|
||||
@@ -159,18 +151,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
bindIntroduction((IntroductionHolder) ui,
|
||||
(ConversationIntroductionInItem) item, position);
|
||||
} else if (item instanceof ConversationNoticeOutItem) {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeOutItem) item,
|
||||
position);
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeOutItem) item);
|
||||
} else if (item instanceof ConversationNoticeInItem) {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item,
|
||||
position);
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled Conversation Item");
|
||||
}
|
||||
}
|
||||
|
||||
private void bindMessage(final MessageHolder ui,
|
||||
ConversationMessageItem item, final int position) {
|
||||
private void bindMessage(MessageHolder ui, ConversationMessageItem item) {
|
||||
|
||||
PrivateMessageHeader header = item.getHeader();
|
||||
|
||||
if (item.getType() == MSG_OUT) {
|
||||
@@ -213,7 +203,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
ui.date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
}
|
||||
|
||||
private void bindIntroduction(final IntroductionHolder ui,
|
||||
private void bindIntroduction(IntroductionHolder ui,
|
||||
final ConversationIntroductionInItem item, final int position) {
|
||||
|
||||
final IntroductionRequest ir = item.getIntroductionRequest();
|
||||
@@ -259,7 +249,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
// Incoming Introduction Request (Not Answered)
|
||||
else {
|
||||
if (item.getIntroductionRequest().doesExist()) {
|
||||
if (item.getIntroductionRequest().contactExists()) {
|
||||
ui.text.setText(ctx.getString(
|
||||
R.string.introduction_request_exists_received,
|
||||
contactName, ir.getName()));
|
||||
@@ -292,8 +282,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
DateUtils.getRelativeTimeSpanString(ctx, item.getTime()));
|
||||
}
|
||||
|
||||
private void bindNotice(final NoticeHolder ui,
|
||||
final ConversationNoticeItem item, final int position) {
|
||||
private void bindNotice(NoticeHolder ui, ConversationNoticeItem item) {
|
||||
|
||||
ui.text.setText(item.getText());
|
||||
ui.date.setText(
|
||||
@@ -375,16 +364,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.items.beginBatchedUpdates();
|
||||
|
||||
while(items.size() != 0) {
|
||||
items.removeItemAt(0);
|
||||
}
|
||||
|
||||
this.items.endBatchedUpdates();
|
||||
items.clear();
|
||||
}
|
||||
|
||||
protected class MessageHolder extends RecyclerView.ViewHolder {
|
||||
private static class MessageHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ViewGroup layout;
|
||||
public TextView body;
|
||||
@@ -408,7 +391,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
protected class IntroductionHolder extends RecyclerView.ViewHolder {
|
||||
private static class IntroductionHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ViewGroup layout;
|
||||
public View messageLayout;
|
||||
@@ -437,7 +420,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
protected class NoticeHolder extends RecyclerView.ViewHolder {
|
||||
private static class NoticeHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ViewGroup layout;
|
||||
public TextView text;
|
||||
|
||||
Reference in New Issue
Block a user