mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Android UI for reading a message (text/plain only for now).
This commit is contained in:
@@ -48,5 +48,9 @@
|
|||||||
android:name=".android.messages.ConversationListActivity"
|
android:name=".android.messages.ConversationListActivity"
|
||||||
android:label="@string/messages_title" >
|
android:label="@string/messages_title" >
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".android.messages.ReadMessageActivity"
|
||||||
|
android:label="@string/messages_title" >
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
BIN
briar-android/res/drawable-hdpi/social_reply.png
Normal file
BIN
briar-android/res/drawable-hdpi/social_reply.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
briar-android/res/drawable-mdpi/social_reply.png
Normal file
BIN
briar-android/res/drawable-mdpi/social_reply.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
BIN
briar-android/res/drawable-xhdpi/social_reply.png
Normal file
BIN
briar-android/res/drawable-xhdpi/social_reply.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -88,8 +88,6 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
|
|||||||
// Bind to the service so we can wait for the DB to be opened
|
// Bind to the service so we can wait for the DB to be opened
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
bindService(new Intent(BriarService.class.getName()),
|
||||||
serviceConnection, 0);
|
serviceConnection, 0);
|
||||||
// Load the contact list from the DB
|
|
||||||
reloadContactList();
|
|
||||||
|
|
||||||
// Add some fake contacts to the database in a background thread
|
// Add some fake contacts to the database in a background thread
|
||||||
// FIXME: Remove this
|
// FIXME: Remove this
|
||||||
@@ -118,6 +116,12 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
reloadContactList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.sf.briar.android.contact;
|
package net.sf.briar.android.contact;
|
||||||
|
|
||||||
import static android.view.Gravity.CENTER;
|
import static android.view.Gravity.CENTER_VERTICAL;
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ implements OnItemClickListener {
|
|||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
LinearLayout layout = new LinearLayout(ctx);
|
LinearLayout layout = new LinearLayout(ctx);
|
||||||
layout.setOrientation(HORIZONTAL);
|
layout.setOrientation(HORIZONTAL);
|
||||||
layout.setGravity(CENTER);
|
layout.setGravity(CENTER_VERTICAL);
|
||||||
|
|
||||||
ImageView bulb = new ImageView(ctx);
|
ImageView bulb = new ImageView(ctx);
|
||||||
bulb.setPadding(5, 5, 5, 5);
|
bulb.setPadding(5, 5, 5, 5);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
@@ -36,7 +38,7 @@ import android.widget.ListView;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
public class ConversationActivity extends BriarActivity
|
public class ConversationActivity extends BriarActivity
|
||||||
implements OnClickListener, DatabaseListener {
|
implements DatabaseListener, OnClickListener, OnItemClickListener {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConversationActivity.class.getName());
|
Logger.getLogger(ConversationActivity.class.getName());
|
||||||
@@ -48,6 +50,7 @@ implements OnClickListener, DatabaseListener {
|
|||||||
@Inject @DatabaseExecutor private Executor dbExecutor;
|
@Inject @DatabaseExecutor private Executor dbExecutor;
|
||||||
|
|
||||||
private ConversationAdapter adapter = null;
|
private ConversationAdapter adapter = null;
|
||||||
|
private String contactName = null;
|
||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,12 +58,12 @@ implements OnClickListener, DatabaseListener {
|
|||||||
super.onCreate(null);
|
super.onCreate(null);
|
||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
|
contactName = i.getStringExtra("net.sf.briar.CONTACT_NAME");
|
||||||
|
if(contactName == null) throw new IllegalStateException();
|
||||||
|
setTitle(contactName);
|
||||||
int id = i.getIntExtra("net.sf.briar.CONTACT_ID", -1);
|
int id = i.getIntExtra("net.sf.briar.CONTACT_ID", -1);
|
||||||
if(id == -1) throw new IllegalStateException();
|
if(id == -1) throw new IllegalStateException();
|
||||||
contactId = new ContactId(id);
|
contactId = new ContactId(id);
|
||||||
String contactName = i.getStringExtra("net.sf.briar.CONTACT_NAME");
|
|
||||||
if(contactName == null) throw new IllegalStateException();
|
|
||||||
setTitle(contactName);
|
|
||||||
|
|
||||||
LinearLayout layout = new LinearLayout(this);
|
LinearLayout layout = new LinearLayout(this);
|
||||||
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
||||||
@@ -72,7 +75,7 @@ implements OnClickListener, DatabaseListener {
|
|||||||
// Give me all the width and all the unused height
|
// Give me all the width and all the unused height
|
||||||
list.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, 1f));
|
list.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, 1f));
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setOnItemClickListener(adapter);
|
list.setOnItemClickListener(this);
|
||||||
layout.addView(list);
|
layout.addView(list);
|
||||||
|
|
||||||
Button composeButton = new Button(this);
|
Button composeButton = new Button(this);
|
||||||
@@ -92,7 +95,11 @@ implements OnClickListener, DatabaseListener {
|
|||||||
// Bind to the service so we can wait for the DB to be opened
|
// Bind to the service so we can wait for the DB to be opened
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
bindService(new Intent(BriarService.class.getName()),
|
||||||
serviceConnection, 0);
|
serviceConnection, 0);
|
||||||
// Load the message headers from the DB
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
reloadMessageHeaders();
|
reloadMessageHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,10 +110,6 @@ implements OnClickListener, DatabaseListener {
|
|||||||
unbindService(serviceConnection);
|
unbindService(serviceConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
|
||||||
// FIXME: Hook this button up to an activity
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof MessageAddedEvent) {
|
if(e instanceof MessageAddedEvent) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
|
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
|
||||||
@@ -152,4 +155,20 @@ implements OnClickListener, DatabaseListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onClick(View view) {
|
||||||
|
// FIXME: Hook this button up to an activity
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||||
|
long id) {
|
||||||
|
PrivateMessageHeader item = adapter.getItem(position);
|
||||||
|
Intent i = new Intent(this, ReadMessageActivity.class);
|
||||||
|
i.putExtra("net.sf.briar.CONTACT_NAME", contactName);
|
||||||
|
i.putExtra("net.sf.briar.MESSAGE_ID", item.getId().getBytes());
|
||||||
|
i.putExtra("net.sf.briar.CONTENT_TYPE", item.getContentType());
|
||||||
|
i.putExtra("net.sf.briar.TIMESTAMP", item.getTimestamp());
|
||||||
|
i.putExtra("net.sf.briar.STARRED", item.isStarred());
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.sf.briar.android.messages;
|
package net.sf.briar.android.messages;
|
||||||
|
|
||||||
import static android.graphics.Typeface.BOLD;
|
import static android.graphics.Typeface.BOLD;
|
||||||
import static android.view.Gravity.CENTER;
|
import static android.view.Gravity.CENTER_VERTICAL;
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
import static java.text.DateFormat.SHORT;
|
import static java.text.DateFormat.SHORT;
|
||||||
@@ -14,16 +14,13 @@ import android.content.Context;
|
|||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader>
|
class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
|
||||||
implements OnItemClickListener {
|
|
||||||
|
|
||||||
ConversationAdapter(Context ctx) {
|
ConversationAdapter(Context ctx) {
|
||||||
super(ctx, android.R.layout.simple_expandable_list_item_1,
|
super(ctx, android.R.layout.simple_expandable_list_item_1,
|
||||||
@@ -36,12 +33,11 @@ implements OnItemClickListener {
|
|||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
LinearLayout layout = new LinearLayout(ctx);
|
LinearLayout layout = new LinearLayout(ctx);
|
||||||
layout.setOrientation(HORIZONTAL);
|
layout.setOrientation(HORIZONTAL);
|
||||||
layout.setGravity(CENTER);
|
layout.setGravity(CENTER_VERTICAL);
|
||||||
|
|
||||||
ImageView star = new ImageView(ctx);
|
ImageView star = new ImageView(ctx);
|
||||||
star.setPadding(5, 5, 5, 5);
|
star.setPadding(5, 5, 5, 5);
|
||||||
if(item.getStarred())
|
if(item.isStarred()) star.setImageResource(R.drawable.rating_important);
|
||||||
star.setImageResource(R.drawable.rating_important);
|
|
||||||
else star.setImageResource(R.drawable.rating_not_important);
|
else star.setImageResource(R.drawable.rating_not_important);
|
||||||
layout.addView(star);
|
layout.addView(star);
|
||||||
|
|
||||||
@@ -57,7 +53,8 @@ implements OnItemClickListener {
|
|||||||
subject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT,
|
subject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT,
|
||||||
1));
|
1));
|
||||||
subject.setTextSize(14);
|
subject.setTextSize(14);
|
||||||
if(!item.getRead()) subject.setTypeface(null, BOLD);
|
subject.setMaxLines(2);
|
||||||
|
if(!item.isRead()) subject.setTypeface(null, BOLD);
|
||||||
subject.setText(item.getSubject());
|
subject.setText(item.getSubject());
|
||||||
layout.addView(subject);
|
layout.addView(subject);
|
||||||
|
|
||||||
@@ -70,9 +67,4 @@ implements OnItemClickListener {
|
|||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
|
||||||
long id) {
|
|
||||||
// FIXME
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package net.sf.briar.android.messages;
|
||||||
|
|
||||||
|
import net.sf.briar.api.db.PrivateMessageHeader;
|
||||||
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
|
|
||||||
|
class ConversationItem {
|
||||||
|
|
||||||
|
private final PrivateMessageHeader header;
|
||||||
|
private final byte[] body;
|
||||||
|
private final boolean expanded;
|
||||||
|
|
||||||
|
ConversationItem(PrivateMessageHeader header) {
|
||||||
|
this.header = header;
|
||||||
|
body = null;
|
||||||
|
expanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collapse an existing item
|
||||||
|
ConversationItem(ConversationItem item) {
|
||||||
|
this.header = item.header;
|
||||||
|
body = null;
|
||||||
|
expanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand an existing item
|
||||||
|
ConversationItem(ConversationItem item, byte[] body) {
|
||||||
|
this.header = item.header;
|
||||||
|
this.body = body;
|
||||||
|
expanded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageId getId() {
|
||||||
|
return header.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
String getContentType() {
|
||||||
|
return header.getContentType();
|
||||||
|
}
|
||||||
|
|
||||||
|
String getSubject() {
|
||||||
|
return header.getSubject();
|
||||||
|
}
|
||||||
|
|
||||||
|
long getTimestamp() {
|
||||||
|
return header.getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isRead() {
|
||||||
|
return header.isRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isStarred() {
|
||||||
|
return header.isStarred();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isIncoming() {
|
||||||
|
return header.isIncoming();
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] getBody() {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isExpanded() {
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,8 +92,6 @@ implements OnClickListener, DatabaseListener {
|
|||||||
// Bind to the service so we can wait for the DB to be opened
|
// Bind to the service so we can wait for the DB to be opened
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
bindService(new Intent(BriarService.class.getName()),
|
||||||
serviceConnection, 0);
|
serviceConnection, 0);
|
||||||
// Load the message headers from the DB
|
|
||||||
reloadMessageHeaders();
|
|
||||||
|
|
||||||
// Add some fake messages to the database in a background thread
|
// Add some fake messages to the database in a background thread
|
||||||
// FIXME: Remove this
|
// FIXME: Remove this
|
||||||
@@ -115,13 +113,10 @@ implements OnClickListener, DatabaseListener {
|
|||||||
"text/plain",
|
"text/plain",
|
||||||
"First message is short".getBytes("UTF-8"));
|
"First message is short".getBytes("UTF-8"));
|
||||||
db.addLocalPrivateMessage(m, contactId);
|
db.addLocalPrivateMessage(m, contactId);
|
||||||
db.setReadFlag(m.getId(), true);
|
|
||||||
db.setStarredFlag(m.getId(), true);
|
|
||||||
Thread.sleep(1000);
|
|
||||||
m = messageFactory.createPrivateMessage(m.getId(),
|
m = messageFactory.createPrivateMessage(m.getId(),
|
||||||
"image/jpeg", new byte[1000]);
|
"image/jpeg", new byte[1000]);
|
||||||
db.receiveMessage(contactId, m);
|
db.receiveMessage(contactId, m);
|
||||||
Thread.sleep(1000);
|
db.setReadFlag(m.getId(), true);
|
||||||
m = messageFactory.createPrivateMessage(m.getId(),
|
m = messageFactory.createPrivateMessage(m.getId(),
|
||||||
"text/plain",
|
"text/plain",
|
||||||
("Third message is quite long to test line"
|
("Third message is quite long to test line"
|
||||||
@@ -129,6 +124,7 @@ implements OnClickListener, DatabaseListener {
|
|||||||
+ " all that fun stuff").getBytes("UTF-8"));
|
+ " all that fun stuff").getBytes("UTF-8"));
|
||||||
db.addLocalPrivateMessage(m, contactId);
|
db.addLocalPrivateMessage(m, contactId);
|
||||||
db.setReadFlag(m.getId(), true);
|
db.setReadFlag(m.getId(), true);
|
||||||
|
db.setStarredFlag(m.getId(), true);
|
||||||
}
|
}
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
@@ -148,6 +144,12 @@ implements OnClickListener, DatabaseListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
reloadMessageHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.sf.briar.android.messages;
|
package net.sf.briar.android.messages;
|
||||||
|
|
||||||
import static android.graphics.Typeface.BOLD;
|
import static android.graphics.Typeface.BOLD;
|
||||||
import static android.view.Gravity.CENTER;
|
import static android.view.Gravity.CENTER_VERTICAL;
|
||||||
import static android.view.Gravity.LEFT;
|
import static android.view.Gravity.LEFT;
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
@@ -38,12 +38,11 @@ implements OnItemClickListener {
|
|||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
LinearLayout layout = new LinearLayout(ctx);
|
LinearLayout layout = new LinearLayout(ctx);
|
||||||
layout.setOrientation(HORIZONTAL);
|
layout.setOrientation(HORIZONTAL);
|
||||||
layout.setGravity(CENTER);
|
layout.setGravity(CENTER_VERTICAL);
|
||||||
|
|
||||||
ImageView star = new ImageView(ctx);
|
ImageView star = new ImageView(ctx);
|
||||||
star.setPadding(5, 5, 5, 5);
|
star.setPadding(5, 5, 5, 5);
|
||||||
if(item.getStarred())
|
if(item.isStarred()) star.setImageResource(R.drawable.rating_important);
|
||||||
star.setImageResource(R.drawable.rating_important);
|
|
||||||
else star.setImageResource(R.drawable.rating_not_important);
|
else star.setImageResource(R.drawable.rating_not_important);
|
||||||
layout.addView(star);
|
layout.addView(star);
|
||||||
|
|
||||||
@@ -61,7 +60,8 @@ implements OnItemClickListener {
|
|||||||
|
|
||||||
TextView subject = new TextView(ctx);
|
TextView subject = new TextView(ctx);
|
||||||
subject.setTextSize(14);
|
subject.setTextSize(14);
|
||||||
if(!item.getRead()) subject.setTypeface(null, BOLD);
|
subject.setMaxLines(2);
|
||||||
|
if(!item.isRead()) subject.setTypeface(null, BOLD);
|
||||||
subject.setText(item.getSubject());
|
subject.setText(item.getSubject());
|
||||||
innerLayout.addView(subject);
|
innerLayout.addView(subject);
|
||||||
layout.addView(innerLayout);
|
layout.addView(innerLayout);
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ class ConversationListItem {
|
|||||||
subject = headers.get(0).getSubject();
|
subject = headers.get(0).getSubject();
|
||||||
timestamp = headers.get(0).getTimestamp();
|
timestamp = headers.get(0).getTimestamp();
|
||||||
length = headers.size();
|
length = headers.size();
|
||||||
boolean allRead = false, anyStarred = false;
|
boolean allRead = true, anyStarred = false;
|
||||||
for(PrivateMessageHeader h : headers) {
|
for(PrivateMessageHeader h : headers) {
|
||||||
allRead &= h.getRead();
|
allRead &= h.isRead();
|
||||||
anyStarred |= h.getStarred();
|
anyStarred |= h.isStarred();
|
||||||
}
|
}
|
||||||
read = allRead;
|
read = allRead;
|
||||||
starred = anyStarred;
|
starred = anyStarred;
|
||||||
@@ -48,11 +48,11 @@ class ConversationListItem {
|
|||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getRead() {
|
boolean isRead() {
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getStarred() {
|
boolean isStarred() {
|
||||||
return starred;
|
return starred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package net.sf.briar.android.messages;
|
||||||
|
|
||||||
|
import static android.view.Gravity.CENTER_VERTICAL;
|
||||||
|
import static android.view.Gravity.RIGHT;
|
||||||
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
|
import static java.text.DateFormat.SHORT;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.sf.briar.R;
|
||||||
|
import net.sf.briar.android.BriarActivity;
|
||||||
|
import net.sf.briar.android.BriarService;
|
||||||
|
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
||||||
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class ReadMessageActivity extends BriarActivity
|
||||||
|
implements OnClickListener {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ReadMessageActivity.class.getName());
|
||||||
|
|
||||||
|
private final BriarServiceConnection serviceConnection =
|
||||||
|
new BriarServiceConnection();
|
||||||
|
|
||||||
|
@Inject private DatabaseComponent db;
|
||||||
|
@Inject @DatabaseExecutor private Executor dbExecutor;
|
||||||
|
|
||||||
|
private MessageId messageId = null;
|
||||||
|
private boolean starred = false;
|
||||||
|
private ImageButton starButton = null, replyButton = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle state) {
|
||||||
|
super.onCreate(null);
|
||||||
|
|
||||||
|
Intent i = getIntent();
|
||||||
|
String contactName = i.getStringExtra("net.sf.briar.CONTACT_NAME");
|
||||||
|
if(contactName == null) throw new IllegalStateException();
|
||||||
|
setTitle(contactName);
|
||||||
|
byte[] id = i.getByteArrayExtra("net.sf.briar.MESSAGE_ID");
|
||||||
|
if(id == null) throw new IllegalStateException();
|
||||||
|
messageId = new MessageId(id);
|
||||||
|
String contentType = i.getStringExtra("net.sf.briar.CONTENT_TYPE");
|
||||||
|
if(contentType == null) throw new IllegalStateException();
|
||||||
|
long timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
|
||||||
|
if(timestamp == -1) throw new IllegalStateException();
|
||||||
|
starred = i.getBooleanExtra("net.sf.briar.STARRED", false);
|
||||||
|
|
||||||
|
LinearLayout layout = new LinearLayout(this);
|
||||||
|
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
||||||
|
layout.setOrientation(VERTICAL);
|
||||||
|
|
||||||
|
LinearLayout header = new LinearLayout(this);
|
||||||
|
header.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
||||||
|
header.setOrientation(HORIZONTAL);
|
||||||
|
header.setGravity(CENTER_VERTICAL);
|
||||||
|
|
||||||
|
starButton = new ImageButton(this);
|
||||||
|
starButton.setPadding(5, 5, 5, 5);
|
||||||
|
starButton.setBackgroundResource(0);
|
||||||
|
if(starred) starButton.setImageResource(R.drawable.rating_important);
|
||||||
|
else starButton.setImageResource(R.drawable.rating_not_important);
|
||||||
|
starButton.setOnClickListener(this);
|
||||||
|
header.addView(starButton);
|
||||||
|
|
||||||
|
replyButton = new ImageButton(this);
|
||||||
|
replyButton.setPadding(5, 5, 5, 5);
|
||||||
|
replyButton.setBackgroundResource(0);
|
||||||
|
replyButton.setImageResource(R.drawable.social_reply);
|
||||||
|
replyButton.setOnClickListener(this);
|
||||||
|
header.addView(replyButton);
|
||||||
|
|
||||||
|
TextView date = new TextView(this);
|
||||||
|
// Give me all the unused width
|
||||||
|
date.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1));
|
||||||
|
date.setTextSize(14);
|
||||||
|
date.setPadding(10, 0, 10, 0);
|
||||||
|
date.setGravity(RIGHT);
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
date.setText(DateUtils.formatSameDayTime(timestamp, now, SHORT, SHORT));
|
||||||
|
header.addView(date);
|
||||||
|
layout.addView(header);
|
||||||
|
|
||||||
|
if(contentType.equals("text/plain")) {
|
||||||
|
// Load and display the message body
|
||||||
|
TextView content = new TextView(this);
|
||||||
|
content.setPadding(10, 10, 10, 10);
|
||||||
|
layout.addView(content);
|
||||||
|
loadMessageBody(messageId, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
setContentView(layout);
|
||||||
|
|
||||||
|
// Bind to the service so we can wait for the DB to be opened
|
||||||
|
bindService(new Intent(BriarService.class.getName()),
|
||||||
|
serviceConnection, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMessageBody(final MessageId id, final TextView view) {
|
||||||
|
dbExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
// Wait for the service to be bound and started
|
||||||
|
serviceConnection.waitForStartup();
|
||||||
|
// Load the message body from the database
|
||||||
|
byte[] body = db.getMessageBody(id);
|
||||||
|
final String text = new String(body, "UTF-8");
|
||||||
|
// Display the message body
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
view.setText(text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} 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 service");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} catch(UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
final MessageId id = messageId;
|
||||||
|
dbExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
// Wait for the service to be bound and started
|
||||||
|
serviceConnection.waitForStartup();
|
||||||
|
// Mark the message as read
|
||||||
|
db.setReadFlag(id, true);
|
||||||
|
} 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 service");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
unbindService(serviceConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if(view == starButton) {
|
||||||
|
final MessageId id = messageId;
|
||||||
|
final boolean starredNow = !starred;
|
||||||
|
dbExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
db.setStarredFlag(id, starredNow);
|
||||||
|
} catch(DbException e) {
|
||||||
|
if(LOG.isLoggable(WARNING))
|
||||||
|
LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
starred = starredNow;
|
||||||
|
if(starred)
|
||||||
|
starButton.setImageResource(R.drawable.rating_important);
|
||||||
|
else starButton.setImageResource(R.drawable.rating_not_important);
|
||||||
|
} else if(view == replyButton) {
|
||||||
|
// FIXME: Hook this up to an activity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,12 +49,12 @@ public abstract class MessageHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if the message has been read. */
|
/** Returns true if the message has been read. */
|
||||||
public boolean getRead() {
|
public boolean isRead() {
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if the message has been starred. */
|
/** Returns true if the message has been starred. */
|
||||||
public boolean getStarred() {
|
public boolean isStarred() {
|
||||||
return starred;
|
return starred;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1310,13 +1310,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
GroupMessageHeader header = it.next();
|
GroupMessageHeader header = it.next();
|
||||||
if(messageId.equals(header.getId())) {
|
if(messageId.equals(header.getId())) {
|
||||||
assertHeadersMatch(message, header);
|
assertHeadersMatch(message, header);
|
||||||
assertTrue(header.getRead());
|
assertTrue(header.isRead());
|
||||||
assertFalse(header.getStarred());
|
assertFalse(header.isStarred());
|
||||||
messageFound = true;
|
messageFound = true;
|
||||||
} else if(messageId1.equals(header.getId())) {
|
} else if(messageId1.equals(header.getId())) {
|
||||||
assertHeadersMatch(message1, header);
|
assertHeadersMatch(message1, header);
|
||||||
assertFalse(header.getRead());
|
assertFalse(header.isRead());
|
||||||
assertFalse(header.getStarred());
|
assertFalse(header.isStarred());
|
||||||
message1Found = true;
|
message1Found = true;
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
@@ -1326,13 +1326,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
header = it.next();
|
header = it.next();
|
||||||
if(messageId.equals(header.getId())) {
|
if(messageId.equals(header.getId())) {
|
||||||
assertHeadersMatch(message, header);
|
assertHeadersMatch(message, header);
|
||||||
assertTrue(header.getRead());
|
assertTrue(header.isRead());
|
||||||
assertFalse(header.getStarred());
|
assertFalse(header.isStarred());
|
||||||
messageFound = true;
|
messageFound = true;
|
||||||
} else if(messageId1.equals(header.getId())) {
|
} else if(messageId1.equals(header.getId())) {
|
||||||
assertHeadersMatch(message1, header);
|
assertHeadersMatch(message1, header);
|
||||||
assertFalse(header.getRead());
|
assertFalse(header.isRead());
|
||||||
assertFalse(header.getStarred());
|
assertFalse(header.isStarred());
|
||||||
message1Found = true;
|
message1Found = true;
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
|
|||||||
Reference in New Issue
Block a user