mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
address issues found in final review
(except refactoring of conversation item classes)
This commit is contained in:
@@ -153,15 +153,15 @@
|
|||||||
<string name="introduction_warn_different_identities_title">Warning: Different Identities</string>
|
<string name="introduction_warn_different_identities_title">Warning: Different Identities</string>
|
||||||
<string name="introduction_warn_different_identities_text">You are trying to introduce two contacts that you have added with different identities. This might reveal that both identities are yours.</string>
|
<string name="introduction_warn_different_identities_text">You are trying to introduce two contacts that you have added with different identities. This might reveal that both identities are yours.</string>
|
||||||
<string name="introduction_request_sent">You have asked to introduce %1$s to %2$s.</string>
|
<string name="introduction_request_sent">You have asked to introduce %1$s to %2$s.</string>
|
||||||
<string name="introduction_request_received">%1$s introduced you to %2$s. Do you want to add %2$s to your contact list?</string>
|
<string name="introduction_request_received">%1$s has asked to introduce you to %2$s. Do you want to add %2$s to your contact list?</string>
|
||||||
<string name="introduction_request_exists_received">%1$s introduced you to %2$s, but %2$s is already in your contact list. Since %1$s might not know that, you can still respond:</string>
|
<string name="introduction_request_exists_received">%1$s has asked to introduce you to %2$s, but %2$s is already in your contact list. Since %1$s might not know that, you can still respond:</string>
|
||||||
<string name="introduction_request_answered_received">%1$s has asked to introduce you to %2$s.</string>
|
<string name="introduction_request_answered_received">%1$s has asked to introduce you to %2$s.</string>
|
||||||
<string name="introduction_response_accepted_sent">You accepted the introduction to %1$s.</string>
|
<string name="introduction_response_accepted_sent">You accepted the introduction to %1$s.</string>
|
||||||
<string name="introduction_response_declined_sent">You declined the introduction to %1$s.</string>
|
<string name="introduction_response_declined_sent">You declined the introduction to %1$s.</string>
|
||||||
<string name="introduction_response_accepted_received">%1$s accepted to be introduced to %2$s.</string>
|
<string name="introduction_response_accepted_received">%1$s accepted to be introduced to %2$s.</string>
|
||||||
<string name="introduction_response_declined_received">%1$s declined to be introduced to %2$s.</string>
|
<string name="introduction_response_declined_received">%1$s declined to be introduced to %2$s.</string>
|
||||||
<string name="introduction_success_title">Introduced contact was added</string>
|
<string name="introduction_success_title">Introduced contact was added</string>
|
||||||
<string name="introduction_success_text">You have been successfully introduced to %1$s who was now added to your contact list.</string>
|
<string name="introduction_success_text">You have been introduced to %1$s.</string>
|
||||||
|
|
||||||
<!-- Dialogs -->
|
<!-- Dialogs -->
|
||||||
<string name="dialog_title_lost_password">Lost Password</string>
|
<string name="dialog_title_lost_password">Lost Password</string>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.briarproject.android.api.AndroidNotificationManager;
|
|||||||
import org.briarproject.android.contact.ConversationActivity;
|
import org.briarproject.android.contact.ConversationActivity;
|
||||||
import org.briarproject.android.forum.ForumActivity;
|
import org.briarproject.android.forum.ForumActivity;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DatabaseExecutor;
|
import org.briarproject.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
@@ -161,21 +162,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
showForumPostNotification(m.getMessage().getGroupId());
|
showForumPostNotification(m.getMessage().getGroupId());
|
||||||
}
|
}
|
||||||
} else if (e instanceof IntroductionRequestReceivedEvent) {
|
} else if (e instanceof IntroductionRequestReceivedEvent) {
|
||||||
try {
|
ContactId c = ((IntroductionRequestReceivedEvent) e).getContactId();
|
||||||
GroupId group = messagingManager.getConversationId(
|
showIntroductionNotifications(c);
|
||||||
((IntroductionRequestReceivedEvent) e).getContactId());
|
|
||||||
showPrivateMessageNotification(group);
|
|
||||||
} catch (DbException ex) {
|
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, ex.toString(), ex);
|
|
||||||
}
|
|
||||||
} else if (e instanceof IntroductionResponseReceivedEvent) {
|
} else if (e instanceof IntroductionResponseReceivedEvent) {
|
||||||
try {
|
ContactId c = ((IntroductionResponseReceivedEvent) e).getContactId();
|
||||||
GroupId group = messagingManager.getConversationId(
|
showIntroductionNotifications(c);
|
||||||
((IntroductionResponseReceivedEvent) e).getContactId());
|
|
||||||
showPrivateMessageNotification(group);
|
|
||||||
} catch (DbException ex) {
|
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, ex.toString(), ex);
|
|
||||||
}
|
|
||||||
} else if (e instanceof IntroductionSucceededEvent) {
|
} else if (e instanceof IntroductionSucceededEvent) {
|
||||||
Contact c = ((IntroductionSucceededEvent) e).getContact();
|
Contact c = ((IntroductionSucceededEvent) e).getContact();
|
||||||
showIntroductionSucceededNotification(c);
|
showIntroductionSucceededNotification(c);
|
||||||
@@ -367,6 +358,20 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showIntroductionNotifications(final ContactId c) {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
GroupId group = messagingManager.getConversationId(c);
|
||||||
|
showPrivateMessageNotification(group);
|
||||||
|
} catch (DbException e) {
|
||||||
|
if (LOG.isLoggable(WARNING))
|
||||||
|
LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void showIntroductionSucceededNotification(final Contact c) {
|
private void showIntroductionSucceededNotification(final Contact c) {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -303,6 +303,7 @@ public class ContactListFragment extends BaseEventFragment {
|
|||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading message headers took " + duration + " ms");
|
LOG.info("Loading message headers took " + duration + " ms");
|
||||||
|
|
||||||
|
now = System.currentTimeMillis();
|
||||||
Collection<IntroductionMessage> introductions =
|
Collection<IntroductionMessage> introductions =
|
||||||
introductionManager
|
introductionManager
|
||||||
.getIntroductionMessages(id);
|
.getIntroductionMessages(id);
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConversationActivity.class.getName());
|
Logger.getLogger(ConversationActivity.class.getName());
|
||||||
private static final int INTRODUCTION_REQUEST_CODE = 0;
|
|
||||||
|
|
||||||
@Inject protected AndroidNotificationManager notificationManager;
|
@Inject protected AndroidNotificationManager notificationManager;
|
||||||
@Inject protected ConnectionRegistry connectionRegistry;
|
@Inject protected ConnectionRegistry connectionRegistry;
|
||||||
@@ -128,12 +127,12 @@ public class ConversationActivity extends BriarActivity
|
|||||||
setContentView(R.layout.activity_conversation);
|
setContentView(R.layout.activity_conversation);
|
||||||
|
|
||||||
// Custom Toolbar
|
// Custom Toolbar
|
||||||
final Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
|
||||||
toolbarAvatar = (CircleImageView) tb.findViewById(R.id.contactAvatar);
|
toolbarAvatar = (CircleImageView) tb.findViewById(R.id.contactAvatar);
|
||||||
toolbarStatus = (ImageView) tb.findViewById(R.id.contactStatus);
|
toolbarStatus = (ImageView) tb.findViewById(R.id.contactStatus);
|
||||||
toolbarTitle = (TextView) tb.findViewById(R.id.contactName);
|
toolbarTitle = (TextView) tb.findViewById(R.id.contactName);
|
||||||
setSupportActionBar(tb);
|
setSupportActionBar(tb);
|
||||||
final ActionBar ab = getSupportActionBar();
|
ActionBar ab = getSupportActionBar();
|
||||||
if (ab != null) {
|
if (ab != null) {
|
||||||
ab.setDisplayShowHomeEnabled(true);
|
ab.setDisplayShowHomeEnabled(true);
|
||||||
ab.setDisplayHomeAsUpEnabled(true);
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
@@ -202,8 +201,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||||
.makeCustomAnimation(this, android.R.anim.slide_in_left,
|
.makeCustomAnimation(this, android.R.anim.slide_in_left,
|
||||||
android.R.anim.slide_out_right);
|
android.R.anim.slide_out_right);
|
||||||
ActivityCompat.startActivityForResult(this, intent,
|
ActivityCompat.startActivity(this, intent, options.toBundle());
|
||||||
INTRODUCTION_REQUEST_CODE, options.toBundle());
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_social_remove_person:
|
case R.id.action_social_remove_person:
|
||||||
askToRemoveContact();
|
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() {
|
private void loadData() {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -274,7 +261,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
toolbarStatus
|
toolbarStatus
|
||||||
.setContentDescription(getString(R.string.offline));
|
.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() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
if (contactId == null)
|
||||||
|
contactId = messagingManager.getContactId(groupId);
|
||||||
Collection<PrivateMessageHeader> headers =
|
Collection<PrivateMessageHeader> headers =
|
||||||
messagingManager.getMessageHeaders(contactId);
|
messagingManager.getMessageHeaders(contactId);
|
||||||
Collection<IntroductionMessage> introductions =
|
Collection<IntroductionMessage> introductions =
|
||||||
@@ -372,11 +361,10 @@ public class ConversationActivity extends BriarActivity
|
|||||||
if (item.getId().equals(m)) {
|
if (item.getId().equals(m)) {
|
||||||
item.setBody(body);
|
item.setBody(body);
|
||||||
adapter.notifyItemChanged(messages.keyAt(i));
|
adapter.notifyItemChanged(messages.keyAt(i));
|
||||||
|
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Scroll to the bottom
|
|
||||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -385,11 +373,9 @@ public class ConversationActivity extends BriarActivity
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (adapter != null) {
|
adapter.add(item);
|
||||||
adapter.add(item);
|
// Scroll to the bottom
|
||||||
// Scroll to the bottom
|
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -609,6 +595,10 @@ public class ConversationActivity extends BriarActivity
|
|||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
// make sure contactId is initialised
|
||||||
|
if (contactId == null)
|
||||||
|
contactId = messagingManager.getContactId(groupId);
|
||||||
|
// remove contact with that ID
|
||||||
contactManager.removeContact(contactId);
|
contactManager.removeContact(contactId);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
@@ -657,7 +647,8 @@ public class ConversationActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void respondToIntroduction(final SessionId sessionId, final boolean accept) {
|
public void respondToIntroduction(final SessionId sessionId,
|
||||||
|
final boolean accept) {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -665,9 +656,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||||
try {
|
try {
|
||||||
if (accept) {
|
if (accept) {
|
||||||
introductionManager.acceptIntroduction(contactId, sessionId, timestamp);
|
introductionManager
|
||||||
|
.acceptIntroduction(contactId, sessionId,
|
||||||
|
timestamp);
|
||||||
} else {
|
} else {
|
||||||
introductionManager.declineIntroduction(contactId, sessionId, timestamp);
|
introductionManager
|
||||||
|
.declineIntroduction(contactId, sessionId,
|
||||||
|
timestamp);
|
||||||
}
|
}
|
||||||
loadMessages();
|
loadMessages();
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
|
|||||||
@@ -88,21 +88,14 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
IntroductionHandler introductionHandler) {
|
IntroductionHandler introductionHandler) {
|
||||||
ctx = context;
|
ctx = context;
|
||||||
intro = introductionHandler;
|
intro = introductionHandler;
|
||||||
setHasStableIds(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdenticonKey(byte[] key, String contactName) {
|
public void setContactInformation(byte[] identiconKey, String contactName) {
|
||||||
this.identiconKey = key;
|
this.identiconKey = identiconKey;
|
||||||
this.contactName = contactName;
|
this.contactName = contactName;
|
||||||
// FIXME this breaks the progress animation because it is called early before data is loaded
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return getItem(position).getId().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
return getItem(position).getType();
|
return getItem(position).getType();
|
||||||
@@ -147,11 +140,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder ui, final int position) {
|
public void onBindViewHolder(ViewHolder ui, int position) {
|
||||||
ConversationItem item = getItem(position);
|
ConversationItem item = getItem(position);
|
||||||
if (item instanceof ConversationMessageItem) {
|
if (item instanceof ConversationMessageItem) {
|
||||||
bindMessage((MessageHolder) ui, (ConversationMessageItem) item,
|
bindMessage((MessageHolder) ui, (ConversationMessageItem) item);
|
||||||
position);
|
|
||||||
} else if (item instanceof ConversationIntroductionOutItem) {
|
} else if (item instanceof ConversationIntroductionOutItem) {
|
||||||
bindIntroduction((IntroductionHolder) ui,
|
bindIntroduction((IntroductionHolder) ui,
|
||||||
(ConversationIntroductionOutItem) item, position);
|
(ConversationIntroductionOutItem) item, position);
|
||||||
@@ -159,18 +151,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
bindIntroduction((IntroductionHolder) ui,
|
bindIntroduction((IntroductionHolder) ui,
|
||||||
(ConversationIntroductionInItem) item, position);
|
(ConversationIntroductionInItem) item, position);
|
||||||
} else if (item instanceof ConversationNoticeOutItem) {
|
} else if (item instanceof ConversationNoticeOutItem) {
|
||||||
bindNotice((NoticeHolder) ui, (ConversationNoticeOutItem) item,
|
bindNotice((NoticeHolder) ui, (ConversationNoticeOutItem) item);
|
||||||
position);
|
|
||||||
} else if (item instanceof ConversationNoticeInItem) {
|
} else if (item instanceof ConversationNoticeInItem) {
|
||||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item,
|
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item);
|
||||||
position);
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unhandled Conversation Item");
|
throw new IllegalArgumentException("Unhandled Conversation Item");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindMessage(final MessageHolder ui,
|
private void bindMessage(MessageHolder ui, ConversationMessageItem item) {
|
||||||
ConversationMessageItem item, final int position) {
|
|
||||||
PrivateMessageHeader header = item.getHeader();
|
PrivateMessageHeader header = item.getHeader();
|
||||||
|
|
||||||
if (item.getType() == MSG_OUT) {
|
if (item.getType() == MSG_OUT) {
|
||||||
@@ -213,7 +203,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
ui.date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
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 ConversationIntroductionInItem item, final int position) {
|
||||||
|
|
||||||
final IntroductionRequest ir = item.getIntroductionRequest();
|
final IntroductionRequest ir = item.getIntroductionRequest();
|
||||||
@@ -259,7 +249,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
// Incoming Introduction Request (Not Answered)
|
// Incoming Introduction Request (Not Answered)
|
||||||
else {
|
else {
|
||||||
if (item.getIntroductionRequest().doesExist()) {
|
if (item.getIntroductionRequest().contactExists()) {
|
||||||
ui.text.setText(ctx.getString(
|
ui.text.setText(ctx.getString(
|
||||||
R.string.introduction_request_exists_received,
|
R.string.introduction_request_exists_received,
|
||||||
contactName, ir.getName()));
|
contactName, ir.getName()));
|
||||||
@@ -292,8 +282,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
DateUtils.getRelativeTimeSpanString(ctx, item.getTime()));
|
DateUtils.getRelativeTimeSpanString(ctx, item.getTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindNotice(final NoticeHolder ui,
|
private void bindNotice(NoticeHolder ui, ConversationNoticeItem item) {
|
||||||
final ConversationNoticeItem item, final int position) {
|
|
||||||
|
|
||||||
ui.text.setText(item.getText());
|
ui.text.setText(item.getText());
|
||||||
ui.date.setText(
|
ui.date.setText(
|
||||||
@@ -375,16 +364,10 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
this.items.beginBatchedUpdates();
|
items.clear();
|
||||||
|
|
||||||
while(items.size() != 0) {
|
|
||||||
items.removeItemAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.items.endBatchedUpdates();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class MessageHolder extends RecyclerView.ViewHolder {
|
private static class MessageHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public ViewGroup layout;
|
public ViewGroup layout;
|
||||||
public TextView body;
|
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 ViewGroup layout;
|
||||||
public View messageLayout;
|
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 ViewGroup layout;
|
||||||
public TextView text;
|
public TextView text;
|
||||||
|
|||||||
@@ -103,10 +103,7 @@ public class ContactChooserFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onItemClick(View view, ContactListItem item) {
|
public void onItemClick(View view, ContactListItem item) {
|
||||||
if (c1 == null) {
|
if (c1 == null) {
|
||||||
Toast.makeText(getActivity(),
|
throw new RuntimeException("c1 not initialized");
|
||||||
R.string.introduction_error,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Contact c2 = item.getContact();
|
Contact c2 = item.getContact();
|
||||||
if (!c1.getLocalAuthorId()
|
if (!c1.getLocalAuthorId()
|
||||||
@@ -227,6 +224,7 @@ public class ContactChooserFragment extends BaseFragment {
|
|||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading message headers took " + duration + " ms");
|
LOG.info("Loading message headers took " + duration + " ms");
|
||||||
|
|
||||||
|
now = System.currentTimeMillis();
|
||||||
Collection<IntroductionMessage> introductions =
|
Collection<IntroductionMessage> introductions =
|
||||||
introductionManager
|
introductionManager
|
||||||
.getIntroductionMessages(id);
|
.getIntroductionMessages(id);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public class IntroductionActivity extends BriarActivity implements
|
|||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
contactId = intent.getIntExtra(CONTACT_ID, -1);
|
contactId = intent.getIntExtra(CONTACT_ID, -1);
|
||||||
|
if (contactId == -1)
|
||||||
|
throw new IllegalArgumentException("Wrong ContactId");
|
||||||
|
|
||||||
setContentView(R.layout.activity_introduction);
|
setContentView(R.layout.activity_introduction);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.android.introduction;
|
package org.briarproject.android.introduction;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
@@ -37,7 +36,7 @@ public class IntroductionMessageFragment extends BaseFragment {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
Logger.getLogger(IntroductionMessageFragment.class.getName());
|
||||||
|
|
||||||
public final static String TAG = "ContactChooserFragment";
|
public final static String TAG = "IntroductionMessageFragment";
|
||||||
private IntroductionActivity introductionActivity;
|
private IntroductionActivity introductionActivity;
|
||||||
private ViewHolder ui;
|
private ViewHolder ui;
|
||||||
|
|
||||||
@@ -45,7 +44,6 @@ public class IntroductionMessageFragment extends BaseFragment {
|
|||||||
private final static String CONTACT_ID_2 = "contact2";
|
private final static String CONTACT_ID_2 = "contact2";
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
private volatile boolean introductionWasMade = false;
|
|
||||||
@Inject
|
@Inject
|
||||||
protected volatile ContactManager contactManager;
|
protected volatile ContactManager contactManager;
|
||||||
@Inject
|
@Inject
|
||||||
@@ -129,8 +127,8 @@ public class IntroductionMessageFragment extends BaseFragment {
|
|||||||
.getContact(new ContactId(contactId2));
|
.getContact(new ContactId(contactId2));
|
||||||
setUpViews(c1, c2);
|
setUpViews(c1, c2);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
// TODO
|
if (LOG.isLoggable(WARNING))
|
||||||
e.printStackTrace();
|
LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -167,54 +165,49 @@ public class IntroductionMessageFragment extends BaseFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonClick(final Contact c1, final Contact c2) {
|
public void onButtonClick(final Contact c1, final Contact c2) {
|
||||||
|
// disable button to prevent accidental double invitations
|
||||||
|
ui.button.setEnabled(false);
|
||||||
|
|
||||||
String msg = ui.message.getText().toString();
|
String msg = ui.message.getText().toString();
|
||||||
makeIntroduction(c1, c2, msg);
|
makeIntroduction(c1, c2, msg);
|
||||||
|
|
||||||
|
// don't wait for the introduction to be made before finishing activity
|
||||||
|
introductionActivity.hideSoftKeyboard(ui.message);
|
||||||
|
introductionActivity.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeIntroduction(final Contact c1, final Contact c2,
|
private void makeIntroduction(final Contact c1, final Contact c2,
|
||||||
final String msg) {
|
final String msg) {
|
||||||
introductionActivity.runOnDbThread(new Runnable() {
|
introductionActivity.runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// prevent double introductions
|
|
||||||
if (introductionWasMade) return;
|
|
||||||
|
|
||||||
// actually make the introduction
|
// actually make the introduction
|
||||||
try {
|
try {
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
introductionManager.makeIntroduction(c1, c2, msg, timestamp);
|
introductionManager.makeIntroduction(c1, c2, msg, timestamp);
|
||||||
introductionWasMade = true;
|
|
||||||
postIntroduction(false);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
LOG.log(WARNING, e.toString(), e);
|
LOG.log(WARNING, e.toString(), e);
|
||||||
postIntroduction(true);
|
introductionError();
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
LOG.log(WARNING, e.toString(), e);
|
LOG.log(WARNING, e.toString(), e);
|
||||||
postIntroduction(true);
|
introductionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postIntroduction(final boolean error) {
|
private void introductionError() {
|
||||||
introductionActivity.runOnUiThread(new Runnable() {
|
introductionActivity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
introductionActivity.hideSoftKeyboard(ui.message);
|
Toast.makeText(introductionActivity,
|
||||||
if (error) {
|
R.string.introduction_error, Toast.LENGTH_SHORT)
|
||||||
Toast.makeText(introductionActivity,
|
.show();
|
||||||
R.string.introduction_error, Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
introductionActivity.setResult(Activity.RESULT_CANCELED);
|
|
||||||
} else {
|
|
||||||
introductionActivity.setResult(Activity.RESULT_OK);
|
|
||||||
}
|
|
||||||
introductionActivity.finish();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder {
|
private static class ViewHolder {
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
ViewGroup header;
|
ViewGroup header;
|
||||||
CircleImageView avatar1;
|
CircleImageView avatar1;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class IntroductionRequest extends IntroductionResponse {
|
|||||||
return answered;
|
return answered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesExist() {
|
public boolean contactExists() {
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
|
|||||||
BdfDictionary state;
|
BdfDictionary state;
|
||||||
try {
|
try {
|
||||||
state = getSessionState(txn, groupId,
|
state = getSessionState(txn, groupId,
|
||||||
message.getRaw(SESSION_ID, new byte[0]));
|
message.getRaw(SESSION_ID));
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
LOG.warning("Could not find state for message, deleting...");
|
LOG.warning("Could not find state for message, deleting...");
|
||||||
deleteMessage(txn, m.getId());
|
deleteMessage(txn, m.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user