Merge branch '97-show-connection-status-of-contact-in-conversation-view' into 'master'

Show connection status of contact in conversation view



See merge request !24
This commit is contained in:
akwizgran
2015-12-15 15:59:40 +00:00
3 changed files with 159 additions and 114 deletions

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ListView will get inserted here -->
<ProgressBar
android:id="@+id/listLoadingProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:indeterminate="true"/>
<TextView
android:id="@+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:padding="@dimen/margin_large"
android:textSize="@dimen/text_size_large"
android:text="@string/no_private_messages"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/horizontal_border"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/button_bar_background"
android:paddingLeft="@dimen/margin_medium"
android:paddingStart="@dimen/margin_medium"
android:paddingRight="@dimen/margin_medium"
android:paddingEnd="@dimen/margin_medium">
<EditText
android:id="@+id/contentView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/private_message_hint"
android:layout_weight="1"
android:inputType="text|textMultiLine|textCapSentences"/>
<ImageButton
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/social_send_now"
android:background="@color/button_bar_background"
android:contentDescription="@string/send"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>

View File

@@ -111,6 +111,9 @@
<string name="notify_sound_setting_disabled">None</string> <string name="notify_sound_setting_disabled">None</string>
<string name="choose_ringtone_title">Choose ringtone</string> <string name="choose_ringtone_title">Choose ringtone</string>
<string name="step">Step %1$d/%2$d</string> <string name="step">Step %1$d/%2$d</string>
<string name="online">Online</string>
<string name="offline">Offline</string>
<string name="send">Send</string>
<!-- Dialogs --> <!-- Dialogs -->
<string name="dialog_title_lost_password">Lost password</string> <string name="dialog_title_lost_password">Lost password</string>

View File

@@ -1,20 +1,53 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import static android.text.InputType.TYPE_CLASS_TEXT; import android.content.Intent;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; import android.content.res.Resources;
import static android.view.Gravity.CENTER; import android.graphics.drawable.ColorDrawable;
import static android.view.Gravity.CENTER_VERTICAL; import android.os.Bundle;
import static android.view.View.GONE; import android.support.v7.app.ActionBar;
import static android.view.View.VISIBLE; import android.view.View;
import static android.widget.LinearLayout.HORIZONTAL; import android.view.View.OnClickListener;
import static android.widget.LinearLayout.VERTICAL; import android.view.ViewGroup;
import static java.util.logging.Level.INFO; import android.widget.AdapterView;
import static java.util.logging.Level.WARNING; import android.widget.AdapterView.OnItemClickListener;
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT; import android.widget.EditText;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import android.widget.ImageButton;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import android.widget.ListView;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import android.widget.ProgressBar;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1; import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.MessageHeader.State;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.ContactConnectedEvent;
import org.briarproject.api.event.ContactDisconnectedEvent;
import org.briarproject.api.event.ContactRemovedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.event.MessagesAckedEvent;
import org.briarproject.api.event.MessagesSentEvent;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.util.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@@ -31,52 +64,11 @@ import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import org.briarproject.R; import static android.view.View.GONE;
import org.briarproject.android.BriarActivity; import static java.util.logging.Level.INFO;
import org.briarproject.android.util.HorizontalBorder; import static java.util.logging.Level.WARNING;
import org.briarproject.android.util.LayoutUtils; import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
import org.briarproject.android.util.ListLoadingProgressBar; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.MessageHeader.State;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.ContactRemovedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.event.MessagesAckedEvent;
import org.briarproject.api.event.MessagesSentEvent;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.util.StringUtils;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class ConversationActivity extends BriarActivity public class ConversationActivity extends BriarActivity
implements EventListener, OnClickListener, OnItemClickListener { implements EventListener, OnClickListener, OnItemClickListener {
@@ -86,12 +78,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
Logger.getLogger(ConversationActivity.class.getName()); Logger.getLogger(ConversationActivity.class.getName());
@Inject private AndroidNotificationManager notificationManager; @Inject private AndroidNotificationManager notificationManager;
@Inject private ConnectionRegistry connectionRegistry;
@Inject @CryptoExecutor private Executor cryptoExecutor; @Inject @CryptoExecutor private Executor cryptoExecutor;
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>(); private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
private TextView empty = null; private TextView empty = null;
private ConversationAdapter adapter = null; private ConversationAdapter adapter = null;
private ListView list = null; private ListView list = null;
private ListLoadingProgressBar loading = null; private ProgressBar loading = null;
private EditText content = null; private EditText content = null;
private ImageButton sendButton = null; private ImageButton sendButton = null;
@@ -104,6 +97,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
private volatile Group group = null; private volatile Group group = null;
private volatile AuthorId localAuthorId = null; private volatile AuthorId localAuthorId = null;
private volatile boolean connected;
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
@@ -118,17 +112,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
data.putExtra("briar.CONTACT_ID", id); data.putExtra("briar.CONTACT_ID", id);
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
LinearLayout layout = new LinearLayout(this); setContentView(R.layout.activity_conversation);
layout.setLayoutParams(MATCH_MATCH); ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
layout.setOrientation(VERTICAL); empty = (TextView) findViewById(R.id.emptyView);
empty = new TextView(this);
empty.setLayoutParams(MATCH_WRAP_1);
empty.setGravity(CENTER);
empty.setTextSize(18);
empty.setText(R.string.no_private_messages);
empty.setVisibility(GONE);
layout.addView(empty);
adapter = new ConversationAdapter(this); adapter = new ConversationAdapter(this);
list = new ListView(this) { list = new ListView(this) {
@@ -145,46 +131,21 @@ implements EventListener, OnClickListener, OnItemClickListener {
list.setClipToPadding(false); list.setClipToPadding(false);
// Make the dividers the same colour as the background // Make the dividers the same colour as the background
Resources res = getResources(); Resources res = getResources();
int background = res.getColor(R.color.window_background); int background = res.getColor(android.R.color.transparent);
list.setDivider(new ColorDrawable(background)); list.setDivider(new ColorDrawable(background));
list.setDividerHeight(pad); list.setDividerHeight(pad);
list.setAdapter(adapter); list.setAdapter(adapter);
list.setOnItemClickListener(this); list.setOnItemClickListener(this);
list.setVisibility(GONE); list.setEmptyView(empty);
layout.addView(list); layout.addView(list, 0);
// Show a progress bar while the list is loading // Show a progress bar while the list is loading
loading = new ListLoadingProgressBar(this); loading = (ProgressBar) findViewById(R.id.listLoadingProgressBar);
layout.addView(loading);
layout.addView(new HorizontalBorder(this)); content = (EditText) findViewById(R.id.contentView);
sendButton = (ImageButton) findViewById(R.id.sendButton);
LinearLayout footer = new LinearLayout(this);
footer.setLayoutParams(MATCH_WRAP);
footer.setOrientation(HORIZONTAL);
footer.setGravity(CENTER_VERTICAL);
footer.setPadding(pad, 0, 0, 0);
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
content = new EditText(this);
content.setId(1);
content.setLayoutParams(WRAP_WRAP_1);
int inputType = TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
| TYPE_TEXT_FLAG_CAP_SENTENCES;
content.setInputType(inputType);
content.setHint(R.string.private_message_hint);
footer.addView(content);
sendButton = new ImageButton(this);
sendButton.setId(2);
sendButton.setBackgroundResource(0);
sendButton.setImageResource(R.drawable.social_send_now);
sendButton.setEnabled(false); // Enabled after loading the group sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setOnClickListener(this); sendButton.setOnClickListener(this);
footer.addView(sendButton);
layout.addView(footer);
setContentView(layout);
} }
@Override @Override
@@ -205,12 +166,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
localAuthorId = contact.getLocalAuthorId(); localAuthorId = contact.getLocalAuthorId();
groupId = db.getInboxGroupId(contactId); groupId = db.getInboxGroupId(contactId);
group = db.getGroup(groupId); group = db.getGroup(groupId);
connected = connectionRegistry.isConnected(contactId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) { if (LOG.isLoggable(INFO)) {
LOG.info("Loading contact and group took " LOG.info("Loading contact and group took "
+ duration + " ms"); + duration + " ms");
} }
displayContactName(); displayContactDetails();
} catch (NoSuchContactException e) { } catch (NoSuchContactException e) {
finishOnUiThread(); finishOnUiThread();
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
@@ -223,10 +185,18 @@ implements EventListener, OnClickListener, OnItemClickListener {
}); });
} }
private void displayContactName() { private void displayContactDetails() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
setTitle(contactName); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(contactName);
if (connected) {
actionBar.setSubtitle(getString(R.string.online));
} else {
actionBar.setSubtitle(getString(R.string.offline));
}
}
} }
}); });
} }
@@ -256,15 +226,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
loading.setVisibility(GONE); loading.setVisibility(GONE);
setTitle(contactName); displayContactDetails();
sendButton.setEnabled(true); sendButton.setEnabled(true);
adapter.clear(); adapter.clear();
if (headers.isEmpty()) { if (!headers.isEmpty()) {
empty.setVisibility(VISIBLE);
list.setVisibility(GONE);
} else {
empty.setVisibility(GONE);
list.setVisibility(VISIBLE);
for (MessageHeader h : headers) { for (MessageHeader h : headers) {
ConversationItem item = new ConversationItem(h); ConversationItem item = new ConversationItem(h);
byte[] body = bodyCache.get(h.getId()); byte[] body = bodyCache.get(h.getId());
@@ -396,6 +361,20 @@ implements EventListener, OnClickListener, OnItemClickListener {
LOG.info("Messages acked"); LOG.info("Messages acked");
markMessages(m.getMessageIds(), State.DELIVERED); markMessages(m.getMessageIds(), State.DELIVERED);
} }
} else if (e instanceof ContactConnectedEvent) {
ContactConnectedEvent c = (ContactConnectedEvent) e;
if (c.getContactId().equals(contactId)) {
LOG.info("Contact connected");
connected = true;
displayContactDetails();
}
} else if (e instanceof ContactDisconnectedEvent) {
ContactDisconnectedEvent c = (ContactDisconnectedEvent) e;
if (c.getContactId().equals(contactId)) {
LOG.info("Contact disconnected");
connected = false;
displayContactDetails();
}
} }
} }