mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Compose messages directly from ConversationActivity. Bug #32.
This commit is contained in:
@@ -69,6 +69,7 @@
|
|||||||
android:name=".android.contact.ConversationActivity"
|
android:name=".android.contact.ConversationActivity"
|
||||||
android:logo="@drawable/logo"
|
android:logo="@drawable/logo"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:windowSoftInputMode="stateHidden"
|
||||||
android:parentActivityName=".android.contact.ContactListActivity" >
|
android:parentActivityName=".android.contact.ContactListActivity" >
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
|||||||
@@ -126,8 +126,7 @@ ConnectionListener {
|
|||||||
db.getInboxMessageHeaders(c.getId());
|
db.getInboxMessageHeaders(c.getId());
|
||||||
displayContact(c, lastConnected, inbox, headers);
|
displayContact(c, lastConnected, inbox, headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
if(LOG.isLoggable(INFO))
|
// Continue
|
||||||
LOG.info("Contact removed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -251,7 +250,6 @@ ConnectionListener {
|
|||||||
LOG.info("Partial load took " + duration + " ms");
|
LOG.info("Partial load took " + duration + " ms");
|
||||||
updateItem(c, headers);
|
updateItem(c, headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Contact removed");
|
|
||||||
removeItem(c);
|
removeItem(c);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package org.briarproject.android.contact;
|
package org.briarproject.android.contact;
|
||||||
|
|
||||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
import static android.text.InputType.TYPE_CLASS_TEXT;
|
||||||
|
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
||||||
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
|
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_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.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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -29,31 +37,41 @@ import org.briarproject.android.util.ListLoadingProgressBar;
|
|||||||
import org.briarproject.api.AuthorId;
|
import org.briarproject.api.AuthorId;
|
||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||||
|
import org.briarproject.api.crypto.CryptoExecutor;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.db.MessageHeader;
|
import org.briarproject.api.db.MessageHeader;
|
||||||
import org.briarproject.api.db.NoSuchContactException;
|
import org.briarproject.api.db.NoSuchContactException;
|
||||||
import org.briarproject.api.db.NoSuchMessageException;
|
import org.briarproject.api.db.NoSuchMessageException;
|
||||||
|
import org.briarproject.api.db.NoSuchSubscriptionException;
|
||||||
import org.briarproject.api.event.ContactRemovedEvent;
|
import org.briarproject.api.event.ContactRemovedEvent;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.api.event.EventListener;
|
||||||
import org.briarproject.api.event.MessageAddedEvent;
|
import org.briarproject.api.event.MessageAddedEvent;
|
||||||
import org.briarproject.api.event.MessageExpiredEvent;
|
import org.briarproject.api.event.MessageExpiredEvent;
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.api.messaging.Group;
|
||||||
import org.briarproject.api.messaging.GroupId;
|
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.messaging.MessageId;
|
||||||
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.InputType;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class ConversationActivity extends BriarActivity
|
public class ConversationActivity extends BriarActivity
|
||||||
implements EventListener, OnClickListener, OnItemClickListener {
|
implements EventListener, OnClickListener, OnItemClickListener {
|
||||||
@@ -62,18 +80,23 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConversationActivity.class.getName());
|
Logger.getLogger(ConversationActivity.class.getName());
|
||||||
|
|
||||||
|
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||||
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
|
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
|
||||||
private String contactName = null;
|
private String contactName = null;
|
||||||
private ConversationAdapter adapter = null;
|
private ConversationAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
|
private EditText content = null;
|
||||||
|
private ImageButton sendButton = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
@Inject private volatile LifecycleManager lifecycleManager;
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
@Inject private volatile MessageFactory messageFactory;
|
||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
private volatile GroupId groupId = null;
|
private volatile GroupId groupId = null;
|
||||||
|
private volatile Group group = null;
|
||||||
private volatile AuthorId localAuthorId = null;
|
private volatile AuthorId localAuthorId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -97,7 +120,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
LinearLayout layout = new LinearLayout(this);
|
LinearLayout layout = new LinearLayout(this);
|
||||||
layout.setLayoutParams(MATCH_MATCH);
|
layout.setLayoutParams(MATCH_MATCH);
|
||||||
layout.setOrientation(VERTICAL);
|
layout.setOrientation(VERTICAL);
|
||||||
layout.setGravity(CENTER_HORIZONTAL);
|
|
||||||
|
|
||||||
adapter = new ConversationAdapter(this);
|
adapter = new ConversationAdapter(this);
|
||||||
list = new ListView(this);
|
list = new ListView(this);
|
||||||
@@ -111,20 +133,35 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
list.setDividerHeight(LayoutUtils.getSeparatorWidth(this));
|
list.setDividerHeight(LayoutUtils.getSeparatorWidth(this));
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setOnItemClickListener(this);
|
list.setOnItemClickListener(this);
|
||||||
|
list.setVisibility(GONE);
|
||||||
layout.addView(list);
|
layout.addView(list);
|
||||||
|
|
||||||
// Show a progress bar while the list is loading
|
// Show a progress bar while the list is loading
|
||||||
list.setVisibility(GONE);
|
|
||||||
loading = new ListLoadingProgressBar(this);
|
loading = new ListLoadingProgressBar(this);
|
||||||
layout.addView(loading);
|
layout.addView(loading);
|
||||||
|
|
||||||
layout.addView(new HorizontalBorder(this));
|
layout.addView(new HorizontalBorder(this));
|
||||||
|
|
||||||
ImageButton composeButton = new ImageButton(this);
|
LinearLayout footer = new LinearLayout(this);
|
||||||
composeButton.setBackgroundResource(0);
|
footer.setLayoutParams(MATCH_WRAP);
|
||||||
composeButton.setImageResource(R.drawable.content_new_email);
|
footer.setOrientation(HORIZONTAL);
|
||||||
composeButton.setOnClickListener(this);
|
|
||||||
layout.addView(composeButton);
|
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);
|
||||||
|
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.setOnClickListener(this);
|
||||||
|
footer.addView(sendButton);
|
||||||
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
}
|
}
|
||||||
@@ -133,10 +170,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
db.addListener(this);
|
db.addListener(this);
|
||||||
loadHeaders();
|
loadHeadersAndGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadHeaders() {
|
private void loadHeadersAndGroup() {
|
||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -144,12 +181,14 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<MessageHeader> headers =
|
Collection<MessageHeader> headers =
|
||||||
db.getInboxMessageHeaders(contactId);
|
db.getInboxMessageHeaders(contactId);
|
||||||
|
group = db.getGroup(groupId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading headers took " + duration + " ms");
|
LOG.info("Load took " + duration + " ms");
|
||||||
displayHeaders(headers);
|
displayHeaders(headers);
|
||||||
} catch(NoSuchContactException e) {
|
} catch(NoSuchContactException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Contact removed");
|
finishOnUiThread();
|
||||||
|
} catch(NoSuchSubscriptionException e) {
|
||||||
finishOnUiThread();
|
finishOnUiThread();
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
@@ -168,6 +207,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
list.setVisibility(VISIBLE);
|
list.setVisibility(VISIBLE);
|
||||||
loading.setVisibility(GONE);
|
loading.setVisibility(GONE);
|
||||||
|
sendButton.setEnabled(true);
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
for(MessageHeader h : headers) {
|
for(MessageHeader h : headers) {
|
||||||
ConversationItem item = new ConversationItem(h);
|
ConversationItem item = new ConversationItem(h);
|
||||||
@@ -196,7 +236,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
LOG.info("Loading message took " + duration + " ms");
|
LOG.info("Loading message took " + duration + " ms");
|
||||||
displayMessageBody(h.getId(), body);
|
displayMessageBody(h.getId(), body);
|
||||||
} catch(NoSuchMessageException e) {
|
} catch(NoSuchMessageException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message expired");
|
|
||||||
// The item will be removed when we get the event
|
// The item will be removed when we get the event
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
@@ -297,20 +336,67 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
GroupId g = ((MessageAddedEvent) e).getGroup().getId();
|
GroupId g = ((MessageAddedEvent) e).getGroup().getId();
|
||||||
if(g.equals(groupId)) {
|
if(g.equals(groupId)) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
|
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
|
||||||
loadHeaders();
|
loadHeadersAndGroup();
|
||||||
}
|
}
|
||||||
} else if(e instanceof MessageExpiredEvent) {
|
} else if(e instanceof MessageExpiredEvent) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
|
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
|
||||||
loadHeaders();
|
loadHeadersAndGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent i = new Intent(this, WritePrivateMessageActivity.class);
|
// Don't use an earlier timestamp than the newest message
|
||||||
i.putExtra("briar.CONTACT_NAME", contactName);
|
long timestamp = System.currentTimeMillis();
|
||||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
int count = adapter.getCount();
|
||||||
i.putExtra("briar.LOCAL_AUTHOR_ID", localAuthorId.getBytes());
|
for(int i = 0; i < count; i++) {
|
||||||
startActivity(i);
|
long time = adapter.getItem(i).getHeader().getTimestamp() + 1;
|
||||||
|
if(time > timestamp) timestamp = time;
|
||||||
|
}
|
||||||
|
byte[] body = StringUtils.toUtf8(content.getText().toString());
|
||||||
|
createMessage(body, timestamp);
|
||||||
|
Toast.makeText(this, R.string.message_sent_toast, LENGTH_SHORT).show();
|
||||||
|
content.setText("");
|
||||||
|
// Hide the soft keyboard
|
||||||
|
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMessage(final byte[] body, final long timestamp) {
|
||||||
|
cryptoExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Message m = messageFactory.createAnonymousMessage(null,
|
||||||
|
group, "text/plain", timestamp, body);
|
||||||
|
storeMessage(m);
|
||||||
|
} catch(GeneralSecurityException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeMessage(final Message m) {
|
||||||
|
dbUiExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
lifecycleManager.waitForDatabase();
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
db.addLocalMessage(m);
|
||||||
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Storing message took " + duration + " ms");
|
||||||
|
} catch(DbException e) {
|
||||||
|
if(LOG.isLoggable(WARNING))
|
||||||
|
LOG.log(WARNING, e.toString(), e);
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Interrupted while waiting for database");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
|||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
Resources res = ctx.getResources();
|
Resources res = ctx.getResources();
|
||||||
|
|
||||||
RelativeLayout layout = new RelativeLayout(ctx);
|
|
||||||
|
|
||||||
int background;
|
int background;
|
||||||
if(header.isRead()) background = res.getColor(R.color.read_background);
|
if(header.isRead()) background = res.getColor(R.color.read_background);
|
||||||
else background = res.getColor(R.color.unread_background);
|
else background = res.getColor(R.color.unread_background);
|
||||||
@@ -82,6 +80,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
|||||||
ImageView bubble = new ImageView(ctx);
|
ImageView bubble = new ImageView(ctx);
|
||||||
bubble.setId(3);
|
bubble.setId(3);
|
||||||
|
|
||||||
|
RelativeLayout layout = new RelativeLayout(ctx);
|
||||||
if(header.isLocal()) {
|
if(header.isLocal()) {
|
||||||
Drawable d;
|
Drawable d;
|
||||||
if(header.isRead())
|
if(header.isRead())
|
||||||
@@ -89,19 +88,19 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
|||||||
else d = res.getDrawable(R.drawable.bubble_unread_right);
|
else d = res.getDrawable(R.drawable.bubble_unread_right);
|
||||||
bubble.setImageDrawable(d);
|
bubble.setImageDrawable(d);
|
||||||
layout.setPadding(d.getIntrinsicWidth(), 0, 0, 0);
|
layout.setPadding(d.getIntrinsicWidth(), 0, 0, 0);
|
||||||
|
// Bubble tip and date at the top right, content below
|
||||||
date.setGravity(RIGHT);
|
date.setGravity(RIGHT);
|
||||||
// Bubble point at the top right, date on top, content below
|
|
||||||
RelativeLayout.LayoutParams topRight =
|
RelativeLayout.LayoutParams topRight =
|
||||||
CommonLayoutParams.wrapWrap();
|
CommonLayoutParams.relative();
|
||||||
topRight.addRule(ALIGN_PARENT_TOP);
|
topRight.addRule(ALIGN_PARENT_TOP);
|
||||||
topRight.addRule(ALIGN_PARENT_RIGHT);
|
topRight.addRule(ALIGN_PARENT_RIGHT);
|
||||||
layout.addView(bubble, topRight);
|
layout.addView(bubble, topRight);
|
||||||
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.relative();
|
||||||
leftOf.addRule(ALIGN_PARENT_TOP);
|
leftOf.addRule(ALIGN_PARENT_TOP);
|
||||||
leftOf.addRule(ALIGN_PARENT_LEFT);
|
leftOf.addRule(ALIGN_PARENT_LEFT);
|
||||||
leftOf.addRule(LEFT_OF, 3);
|
leftOf.addRule(LEFT_OF, 3);
|
||||||
layout.addView(date, leftOf);
|
layout.addView(date, leftOf);
|
||||||
RelativeLayout.LayoutParams below = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams below = CommonLayoutParams.relative();
|
||||||
below.addRule(ALIGN_PARENT_LEFT);
|
below.addRule(ALIGN_PARENT_LEFT);
|
||||||
below.addRule(LEFT_OF, 3);
|
below.addRule(LEFT_OF, 3);
|
||||||
below.addRule(BELOW, 1);
|
below.addRule(BELOW, 1);
|
||||||
@@ -113,24 +112,23 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
|||||||
else d = res.getDrawable(R.drawable.bubble_unread_left);
|
else d = res.getDrawable(R.drawable.bubble_unread_left);
|
||||||
bubble.setImageDrawable(d);
|
bubble.setImageDrawable(d);
|
||||||
layout.setPadding(0, 0, d.getIntrinsicWidth(), 0);
|
layout.setPadding(0, 0, d.getIntrinsicWidth(), 0);
|
||||||
|
// Bubble tip and date at the top left, content below
|
||||||
date.setGravity(LEFT);
|
date.setGravity(LEFT);
|
||||||
// Bubble point at the top left, date on top, content below
|
RelativeLayout.LayoutParams topLeft = CommonLayoutParams.relative();
|
||||||
RelativeLayout.LayoutParams topLeft = CommonLayoutParams.wrapWrap();
|
|
||||||
topLeft.addRule(ALIGN_PARENT_TOP);
|
topLeft.addRule(ALIGN_PARENT_TOP);
|
||||||
topLeft.addRule(ALIGN_PARENT_LEFT);
|
topLeft.addRule(ALIGN_PARENT_LEFT);
|
||||||
layout.addView(bubble, topLeft);
|
layout.addView(bubble, topLeft);
|
||||||
RelativeLayout.LayoutParams rightOf = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams rightOf = CommonLayoutParams.relative();
|
||||||
rightOf.addRule(ALIGN_PARENT_TOP);
|
rightOf.addRule(ALIGN_PARENT_TOP);
|
||||||
rightOf.addRule(ALIGN_PARENT_RIGHT);
|
rightOf.addRule(ALIGN_PARENT_RIGHT);
|
||||||
rightOf.addRule(RIGHT_OF, 3);
|
rightOf.addRule(RIGHT_OF, 3);
|
||||||
layout.addView(date, rightOf);
|
layout.addView(date, rightOf);
|
||||||
RelativeLayout.LayoutParams below = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams below = CommonLayoutParams.relative();
|
||||||
below.addRule(ALIGN_PARENT_RIGHT);
|
below.addRule(ALIGN_PARENT_RIGHT);
|
||||||
below.addRule(RIGHT_OF, 3);
|
below.addRule(RIGHT_OF, 3);
|
||||||
below.addRule(BELOW, 1);
|
below.addRule(BELOW, 1);
|
||||||
layout.addView(content, below);
|
layout.addView(content, below);
|
||||||
}
|
}
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,6 @@ implements OnClickListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(NoSuchMessageException e) {
|
} catch(NoSuchMessageException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message removed");
|
|
||||||
finishOnUiThread();
|
finishOnUiThread();
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ implements OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(WritePrivateMessageActivity.class.getName());
|
Logger.getLogger(WritePrivateMessageActivity.class.getName());
|
||||||
|
|
||||||
|
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||||
private TextView from = null, to = null;
|
private TextView from = null, to = null;
|
||||||
private ImageButton sendButton = null;
|
private ImageButton sendButton = null;
|
||||||
private EditText content = null;
|
private EditText content = null;
|
||||||
@@ -67,7 +68,6 @@ implements OnClickListener {
|
|||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
@Inject private volatile LifecycleManager lifecycleManager;
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
@Inject @CryptoExecutor private volatile Executor cryptoExecutor;
|
|
||||||
@Inject private volatile MessageFactory messageFactory;
|
@Inject private volatile MessageFactory messageFactory;
|
||||||
private volatile String contactName = null;
|
private volatile String contactName = null;
|
||||||
private volatile GroupId groupId = null;
|
private volatile GroupId groupId = null;
|
||||||
@@ -108,7 +108,7 @@ implements OnClickListener {
|
|||||||
from.setEllipsize(END);
|
from.setEllipsize(END);
|
||||||
from.setPadding(pad, pad, pad, pad);
|
from.setPadding(pad, pad, pad, pad);
|
||||||
from.setText(R.string.from);
|
from.setText(R.string.from);
|
||||||
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams leftOf = CommonLayoutParams.relative();
|
||||||
leftOf.addRule(ALIGN_PARENT_LEFT);
|
leftOf.addRule(ALIGN_PARENT_LEFT);
|
||||||
leftOf.addRule(CENTER_VERTICAL);
|
leftOf.addRule(CENTER_VERTICAL);
|
||||||
leftOf.addRule(LEFT_OF, 2);
|
leftOf.addRule(LEFT_OF, 2);
|
||||||
@@ -120,7 +120,7 @@ implements OnClickListener {
|
|||||||
sendButton.setImageResource(R.drawable.social_send_now);
|
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);
|
||||||
RelativeLayout.LayoutParams right = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams right = CommonLayoutParams.relative();
|
||||||
right.addRule(ALIGN_PARENT_RIGHT);
|
right.addRule(ALIGN_PARENT_RIGHT);
|
||||||
right.addRule(CENTER_VERTICAL);
|
right.addRule(CENTER_VERTICAL);
|
||||||
header.addView(sendButton, right);
|
header.addView(sendButton, right);
|
||||||
@@ -148,7 +148,7 @@ implements OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
loadAuthorAndGroup();
|
if(localAuthor == null || group == null) loadAuthorAndGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAuthorAndGroup() {
|
private void loadAuthorAndGroup() {
|
||||||
@@ -191,7 +191,6 @@ implements OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(localAuthor == null) throw new IllegalStateException();
|
|
||||||
createMessage(StringUtils.toUtf8(content.getText().toString()));
|
createMessage(StringUtils.toUtf8(content.getText().toString()));
|
||||||
Toast.makeText(this, R.string.message_sent_toast, LENGTH_LONG).show();
|
Toast.makeText(this, R.string.message_sent_toast, LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
@@ -203,16 +202,15 @@ implements OnClickListener {
|
|||||||
// Don't use an earlier timestamp than the parent
|
// Don't use an earlier timestamp than the parent
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
time = Math.max(time, timestamp + 1);
|
time = Math.max(time, timestamp + 1);
|
||||||
Message m;
|
|
||||||
try {
|
try {
|
||||||
m = messageFactory.createAnonymousMessage(parentId, group,
|
Message m = messageFactory.createAnonymousMessage(parentId,
|
||||||
"text/plain", time, body);
|
group, "text/plain", time, body);
|
||||||
|
storeMessage(m);
|
||||||
} catch(GeneralSecurityException e) {
|
} catch(GeneralSecurityException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
storeMessage(m);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ OnClickListener, OnItemClickListener {
|
|||||||
LOG.info("Load took " + duration + " ms");
|
LOG.info("Load took " + duration + " ms");
|
||||||
displayHeaders(headers);
|
displayHeaders(headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
|
|
||||||
finishOnUiThread();
|
finishOnUiThread();
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
@@ -178,7 +177,6 @@ OnClickListener, OnItemClickListener {
|
|||||||
LOG.info("Loading message took " + duration + " ms");
|
LOG.info("Loading message took " + duration + " ms");
|
||||||
displayMessage(h.getId(), body);
|
displayMessage(h.getId(), body);
|
||||||
} catch(NoSuchMessageException e) {
|
} catch(NoSuchMessageException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message expired");
|
|
||||||
// The item will be removed when we get the event
|
// The item will be removed when we get the event
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
|
|||||||
@@ -143,8 +143,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
db.getMessageHeaders(g.getId());
|
db.getMessageHeaders(g.getId());
|
||||||
displayHeaders(g, headers);
|
displayHeaders(g, headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
if(LOG.isLoggable(INFO))
|
// Continue
|
||||||
LOG.info("Subscription removed");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
available++;
|
available++;
|
||||||
@@ -279,7 +278,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
LOG.info("Partial load took " + duration + " ms");
|
LOG.info("Partial load took " + duration + " ms");
|
||||||
displayHeaders(g, headers);
|
displayHeaders(g, headers);
|
||||||
} catch(NoSuchSubscriptionException e) {
|
} catch(NoSuchSubscriptionException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
|
|
||||||
removeGroup(g.getId());
|
removeGroup(g.getId());
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
|
|||||||
@@ -230,7 +230,6 @@ implements OnClickListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(NoSuchMessageException e) {
|
} catch(NoSuchMessageException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message removed");
|
|
||||||
finishOnUiThread();
|
finishOnUiThread();
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
from.setTextSize(18);
|
from.setTextSize(18);
|
||||||
from.setPadding(pad, pad, 0, pad);
|
from.setPadding(pad, pad, 0, pad);
|
||||||
from.setText(R.string.from);
|
from.setText(R.string.from);
|
||||||
RelativeLayout.LayoutParams left = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams left = CommonLayoutParams.relative();
|
||||||
left.addRule(ALIGN_PARENT_LEFT);
|
left.addRule(ALIGN_PARENT_LEFT);
|
||||||
left.addRule(CENTER_VERTICAL);
|
left.addRule(CENTER_VERTICAL);
|
||||||
header.addView(from, left);
|
header.addView(from, left);
|
||||||
@@ -129,7 +129,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
spinner.setId(2);
|
spinner.setId(2);
|
||||||
spinner.setAdapter(adapter);
|
spinner.setAdapter(adapter);
|
||||||
spinner.setOnItemSelectedListener(this);
|
spinner.setOnItemSelectedListener(this);
|
||||||
RelativeLayout.LayoutParams between = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams between = CommonLayoutParams.relative();
|
||||||
between.addRule(CENTER_VERTICAL);
|
between.addRule(CENTER_VERTICAL);
|
||||||
between.addRule(RIGHT_OF, 1);
|
between.addRule(RIGHT_OF, 1);
|
||||||
between.addRule(LEFT_OF, 3);
|
between.addRule(LEFT_OF, 3);
|
||||||
@@ -141,7 +141,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
sendButton.setImageResource(R.drawable.social_send_now);
|
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);
|
||||||
RelativeLayout.LayoutParams right = CommonLayoutParams.wrapWrap();
|
RelativeLayout.LayoutParams right = CommonLayoutParams.relative();
|
||||||
right.addRule(ALIGN_PARENT_RIGHT);
|
right.addRule(ALIGN_PARENT_RIGHT);
|
||||||
right.addRule(CENTER_VERTICAL);
|
right.addRule(CENTER_VERTICAL);
|
||||||
header.addView(sendButton, right);
|
header.addView(sendButton, right);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class AuthorView extends RelativeLayout {
|
|||||||
nameView.setPadding(pad, pad, pad, pad);
|
nameView.setPadding(pad, pad, pad, pad);
|
||||||
if(name == null) nameView.setText(R.string.anonymous);
|
if(name == null) nameView.setText(R.string.anonymous);
|
||||||
else nameView.setText(name);
|
else nameView.setText(name);
|
||||||
LayoutParams leftOf = CommonLayoutParams.wrapWrap();
|
LayoutParams leftOf = CommonLayoutParams.relative();
|
||||||
leftOf.addRule(ALIGN_PARENT_LEFT);
|
leftOf.addRule(ALIGN_PARENT_LEFT);
|
||||||
leftOf.addRule(CENTER_VERTICAL);
|
leftOf.addRule(CENTER_VERTICAL);
|
||||||
leftOf.addRule(LEFT_OF, 2);
|
leftOf.addRule(LEFT_OF, 2);
|
||||||
@@ -51,7 +51,7 @@ public class AuthorView extends RelativeLayout {
|
|||||||
statusView.setImageResource(R.drawable.identity_verified);
|
statusView.setImageResource(R.drawable.identity_verified);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LayoutParams right = CommonLayoutParams.wrapWrap();
|
LayoutParams right = CommonLayoutParams.relative();
|
||||||
right.addRule(ALIGN_PARENT_RIGHT);
|
right.addRule(ALIGN_PARENT_RIGHT);
|
||||||
right.addRule(CENTER_VERTICAL);
|
right.addRule(CENTER_VERTICAL);
|
||||||
addView(statusView, right);
|
addView(statusView, right);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class CommonLayoutParams {
|
|||||||
public static final LinearLayout.LayoutParams WRAP_WRAP_1 =
|
public static final LinearLayout.LayoutParams WRAP_WRAP_1 =
|
||||||
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1);
|
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1);
|
||||||
|
|
||||||
public static RelativeLayout.LayoutParams wrapWrap() {
|
public static RelativeLayout.LayoutParams relative() {
|
||||||
return new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
|
return new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class LayoutUtils {
|
|||||||
public static int getSeparatorWidth(Context ctx) {
|
public static int getSeparatorWidth(Context ctx) {
|
||||||
DisplayMetrics metrics = getDisplayMetrics(ctx);
|
DisplayMetrics metrics = getDisplayMetrics(ctx);
|
||||||
int percent = Math.max(metrics.widthPixels, metrics.heightPixels) / 100;
|
int percent = Math.max(metrics.widthPixels, metrics.heightPixels) / 100;
|
||||||
return Math.max(2, percent - 6);
|
return Math.max(2, percent - 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPadding(Context ctx) {
|
public static int getPadding(Context ctx) {
|
||||||
|
|||||||
Reference in New Issue
Block a user