Added a method for getting one contact's private messages from the DB.

This commit is contained in:
akwizgran
2013-03-02 03:31:39 +00:00
parent a5da3694f9
commit 882420ebc2
8 changed files with 83 additions and 11 deletions

View File

@@ -47,8 +47,8 @@ implements OnClickListener, DatabaseListener {
@Inject private DatabaseComponent db;
@Inject @DatabaseExecutor private Executor dbExecutor;
private ContactId contactId = null;
private ConversationAdapter adapter = null;
private volatile ContactId contactId = null;
@Override
public void onCreate(Bundle state) {
@@ -125,7 +125,7 @@ implements OnClickListener, DatabaseListener {
serviceConnection.waitForStartup();
// Load the message headers from the database
Collection<PrivateMessageHeader> headers =
db.getPrivateMessageHeaders();
db.getPrivateMessageHeaders(contactId);
if(LOG.isLoggable(INFO))
LOG.info("Loaded " + headers.size() + " headers");
// Update the conversation
@@ -147,8 +147,7 @@ implements OnClickListener, DatabaseListener {
runOnUiThread(new Runnable() {
public void run() {
adapter.clear();
for(PrivateMessageHeader h : headers)
if(h.getContactId().equals(contactId)) adapter.add(h);
for(PrivateMessageHeader h : headers) adapter.add(h);
adapter.sort(AscendingHeaderComparator.INSTANCE);
}
});

View File

@@ -56,7 +56,7 @@ implements OnItemClickListener {
TextView date = new TextView(ctx);
date.setTextSize(14);
date.setPadding(5, 0, 10, 0);
date.setPadding(10, 0, 10, 0);
long then = item.getTimestamp(), now = System.currentTimeMillis();
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
layout.addView(date);

View File

@@ -112,20 +112,20 @@ implements OnClickListener, DatabaseListener {
ContactId contactId = db.addContact("Carol");
// Insert some fake messages to and from the contact
Message m = messageFactory.createPrivateMessage(null,
"First message's subject is quite long to test"
+ " line wrapping and stuff like that",
"First message's subject is short",
"First message's body".getBytes("UTF-8"));
db.addLocalPrivateMessage(m, contactId);
db.setReadFlag(m.getId(), true);
db.setStarredFlag(m.getId(), true);
Thread.sleep(1000);
m = messageFactory.createPrivateMessage(m.getId(),
"Second message's subject is short",
"Second message's subject is also short",
"Second message's body".getBytes("UTF-8"));
db.receiveMessage(contactId, m);
Thread.sleep(1000);
m = messageFactory.createPrivateMessage(m.getId(),
"Third message's subject is also short",
"Third message's subject is quite long to test"
+ " line wrapping and exciting stuff like that",
"Third message's body".getBytes("UTF-8"));
db.addLocalPrivateMessage(m, contactId);
db.setReadFlag(m.getId(), true);

View File

@@ -53,7 +53,6 @@ implements OnItemClickListener {
WRAP_CONTENT, 1));
innerLayout.setOrientation(VERTICAL);
innerLayout.setGravity(LEFT);
innerLayout.setPadding(0, 5, 0, 5);
TextView name = new TextView(ctx);
name.setTextSize(18);
@@ -69,7 +68,7 @@ implements OnItemClickListener {
TextView date = new TextView(ctx);
date.setTextSize(14);
date.setPadding(5, 0, 10, 0);
date.setPadding(10, 0, 10, 0);
long then = item.getTimestamp(), now = System.currentTimeMillis();
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
layout.addView(date);