Skip to content
Snippets Groups Projects
Commit bab9a419 authored by akwizgran's avatar akwizgran
Browse files

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
parents 2621ab01 327073f5
No related branches found
No related tags found
No related merge requests found
Pipeline #
<?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>
\ No newline at end of file
......@@ -111,6 +111,9 @@
<string name="notify_sound_setting_disabled">None</string>
<string name="choose_ringtone_title">Choose ringtone</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 -->
<string name="dialog_title_lost_password">Lost password</string>
......
package org.briarproject.android.contact;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
......@@ -48,6 +31,8 @@ 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;
......@@ -61,22 +46,29 @@ 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 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;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.view.View.GONE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class ConversationActivity extends BriarActivity
implements EventListener, OnClickListener, OnItemClickListener {
......@@ -86,12 +78,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
Logger.getLogger(ConversationActivity.class.getName());
@Inject private AndroidNotificationManager notificationManager;
@Inject private ConnectionRegistry connectionRegistry;
@Inject @CryptoExecutor private Executor cryptoExecutor;
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
private TextView empty = null;
private ConversationAdapter adapter = null;
private ListView list = null;
private ListLoadingProgressBar loading = null;
private ProgressBar loading = null;
private EditText content = null;
private ImageButton sendButton = null;
......@@ -104,6 +97,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
private volatile GroupId groupId = null;
private volatile Group group = null;
private volatile AuthorId localAuthorId = null;
private volatile boolean connected;
@Override
public void onCreate(Bundle state) {
......@@ -118,17 +112,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
data.putExtra("briar.CONTACT_ID", id);
setResult(RESULT_OK, data);
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(MATCH_MATCH);
layout.setOrientation(VERTICAL);
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);
setContentView(R.layout.activity_conversation);
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
empty = (TextView) findViewById(R.id.emptyView);
adapter = new ConversationAdapter(this);
list = new ListView(this) {
......@@ -145,46 +131,21 @@ implements EventListener, OnClickListener, OnItemClickListener {
list.setClipToPadding(false);
// Make the dividers the same colour as the background
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.setDividerHeight(pad);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setVisibility(GONE);
layout.addView(list);
list.setEmptyView(empty);
layout.addView(list, 0);
// Show a progress bar while the list is loading
loading = new ListLoadingProgressBar(this);
layout.addView(loading);
layout.addView(new HorizontalBorder(this));
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);
loading = (ProgressBar) findViewById(R.id.listLoadingProgressBar);
content = (EditText) findViewById(R.id.contentView);
sendButton = (ImageButton) findViewById(R.id.sendButton);
sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setOnClickListener(this);
footer.addView(sendButton);
layout.addView(footer);
setContentView(layout);
}
@Override
......@@ -205,12 +166,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
localAuthorId = contact.getLocalAuthorId();
groupId = db.getInboxGroupId(contactId);
group = db.getGroup(groupId);
connected = connectionRegistry.isConnected(contactId);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) {
LOG.info("Loading contact and group took "
+ duration + " ms");
}
displayContactName();
displayContactDetails();
} catch (NoSuchContactException e) {
finishOnUiThread();
} catch (NoSuchSubscriptionException e) {
......@@ -223,10 +185,18 @@ implements EventListener, OnClickListener, OnItemClickListener {
});
}
private void displayContactName() {
private void displayContactDetails() {
runOnUiThread(new Runnable() {
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() {
public void run() {
loading.setVisibility(GONE);
setTitle(contactName);
displayContactDetails();
sendButton.setEnabled(true);
adapter.clear();
if (headers.isEmpty()) {
empty.setVisibility(VISIBLE);
list.setVisibility(GONE);
} else {
empty.setVisibility(GONE);
list.setVisibility(VISIBLE);
if (!headers.isEmpty()) {
for (MessageHeader h : headers) {
ConversationItem item = new ConversationItem(h);
byte[] body = bodyCache.get(h.getId());
......@@ -396,6 +361,20 @@ implements EventListener, OnClickListener, OnItemClickListener {
LOG.info("Messages acked");
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();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment