Permalink
Browse files

Add empty messages, fix updating of conversation.

  • Loading branch information...
1 parent 8aef9c0 commit 9f6710f5d51f84f6105246b73c5c95f5a52aeba9 @Stebalien committed May 9, 2012
View
7 res/layout/contact_picker.xml
@@ -11,4 +11,11 @@
android:layout_height="wrap_content" >
</ListView>
+ <TextView
+ android:id="@+id/contactListEmpty"
+ android:gravity="center"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="@string/contact_picker_empty" />
+
</LinearLayout>
View
7 res/layout/contacts.xml
@@ -10,5 +10,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
+
+ <TextView
+ android:id="@+id/contactListEmpty"
+ android:layout_gravity="center"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="@string/contacts_empty" />
</LinearLayout>
View
8 res/layout/conversation_activity.xml
@@ -12,6 +12,14 @@
android:layout_height="0dip" >
</ListView>
+ <TextView
+ android:id="@+id/conversationEmpty"
+ android:gravity="center"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"
+ android:text="@string/conversation_empty" />
+
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="0"
View
6 res/layout/inbox.xml
@@ -10,5 +10,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
+ <TextView
+ android:id="@+id/inboxEmpty"
+ android:gravity="center"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:text="@string/inbox_empty" />
</LinearLayout>
View
18 res/values/strings.xml
@@ -20,7 +20,7 @@
<string name="contact_picker_title">Pick A Contact</string>
<string name="new_conversation">New</string>
<string name="conversations_title">Inbox</string>
- <string name="add_contact_title">Add Contact</string>
+ <string name="dialog_add_contact_title">Add Contact</string>
<string name="verified_checkbox">I know this user</string>
<string name="name_hint">Full Name</string>
<string name="username_hint">Username</string>
@@ -30,4 +30,20 @@
<color name="error_foreground">#ff0000</color>
<string name="invalid_name">* Invalid Name</string>
<string name="conflict_name">* You already have a contact by this name.</string>
+ <string-array name="dialog_add_contact_menu">
+ <item >Add By Barcode</item>
+ <item >Add Manually</item>
+ </string-array>
+ <string name="dialog_modify_contact_title">Modify %s</string>
+ <string-array name="dialog_modify_contact_menu">
+ <item >Edit Contact</item>
+ <item >Delete Contact</item>
+ </string-array>
+ <string name="add_contact_title">Add Contact</string>
+ <string name="dialog_delete_contact_message">Are you sure you want to delete &quot;%s&quot;?</string>
+ <string name="dialog_delete_contact_title">Delete Contact</string>
+ <string name="contact_picker_empty">Nobody To Add</string>
+ <string name="contacts_empty">No Contacts</string>
+ <string name="conversation_empty">No Messages</string>
+ <string name="inbox_empty">No Conversations</string>
</resources>
View
3 src/edu/mit/securemessaging/Backend.java
@@ -45,6 +45,9 @@
return memberships;
}
+ public DatabaseHelper getHelper() {
+ return db;
+ }
@Override
public void onCreate() {
View
31 src/edu/mit/securemessaging/Conversation.java
@@ -25,27 +25,31 @@
@DatabaseTable(tableName = "conversation")
public class Conversation {
- public static final String ID_FIELD = "_id";
private static final Random RAND = new Random();
-
private static Backend BACKEND;
+ public static final String ID_FIELD = "_id";
+ public static final String TIMESTAMP_FIELD = "timestamp";
+ public static final String STATUS_FIELD = "status";
+
+
+
// Stores the conversation's ID
@DatabaseField(columnName = ID_FIELD, id = true)
private final String id;
// Caches the timestamp of the last received message.
- @DatabaseField
+ @DatabaseField(columnName = TIMESTAMP_FIELD)
private Date timestamp;
// Caches the read status of the conversation
- @DatabaseField
+ @DatabaseField(columnName = STATUS_FIELD)
private Status status = Status.READ;
@ForeignCollectionField(eager = false, orderColumnName = "timestamp")
private ForeignCollection<Message> messages;
- @ForeignCollectionField(eager = false)
+ @ForeignCollectionField(eager = true)
private ForeignCollection<Membership> memberships;
private final Set<ConversationListener> conversationListeners = new CopyOnWriteArraySet<ConversationListener>();
@@ -59,21 +63,14 @@
public Conversation() {
id = UUID.randomUUID().toString();
this.timestamp = new Date();
- if (BACKEND == null) {
- BACKEND = Backend.getInstance();
- }
- }
-
- public Conversation(String id, List<Message> messages, List<Person> members, Date timestamp) {
- this.id = id;
- this.timestamp = timestamp;
+ if (BACKEND == null) BACKEND = Backend.getInstance();
}
public Collection<Message> getMessages() {
return Collections.unmodifiableCollection(messages);
}
- private PreparedQuery<Message> getLastMessageQuery() throws SQLException {
+ public PreparedQuery<Message> getLastMessageQuery() throws SQLException {
if (lastMessageQuery == null) {
QueryBuilder<Message, String> qBuilder = BACKEND.getMessageDao().queryBuilder();
qBuilder.where().eq(Message.CONVERSATION_FIELD, this);
@@ -84,7 +81,7 @@ public Conversation(String id, List<Message> messages, List<Person> members, Dat
}
- private PreparedQuery<Person> getPersonQuery() throws SQLException {
+ public PreparedQuery<Person> getPersonQuery() throws SQLException {
if (personQuery == null) {
QueryBuilder<Membership, String> subQuery = BACKEND.getMembershipDao().queryBuilder();
subQuery.selectColumns(Membership.PERSON_FIELD);
@@ -98,7 +95,7 @@ public Conversation(String id, List<Message> messages, List<Person> members, Dat
return personQuery;
}
- private PreparedQuery<Person> getTrustLevelQuery() throws SQLException {
+ public PreparedQuery<Person> getTrustLevelQuery() throws SQLException {
if (trustLevelQuery == null) {
QueryBuilder<Membership, String> subQuery = BACKEND.getMembershipDao().queryBuilder();
@@ -114,7 +111,7 @@ public Conversation(String id, List<Message> messages, List<Person> members, Dat
return trustLevelQuery;
}
- private PreparedQuery<Membership> getMembershipQuery(Person person) throws SQLException {
+ public PreparedQuery<Membership> getMembershipQuery(Person person) throws SQLException {
if (membershipQuery == null) {
membershipQuery = BACKEND.getMembershipDao().queryBuilder().where().eq(Membership.CONVERSATION_FIELD, this).eq(Membership.PERSON_FIELD, new SelectArg(person)).prepare();
return membershipQuery;
View
2 src/edu/mit/securemessaging/Message.java
@@ -13,7 +13,6 @@
public static final String SENDER_FIELD = "sender_id";
public static final String TIMESTAMP_FIELD = "timestamp";
public static final String CONTENTS_FIELD = "contents";
- private static Backend BACKEND;
@DatabaseField(columnName = ID_FIELD, id = true)
private final String id;
@@ -62,7 +61,6 @@ public Message(String id, Conversation conversation, Person sender, Date timesta
this.sender = sender;
this.contents = contents;
this.timestamp = timestamp;
- if (BACKEND == null) BACKEND = Backend.getInstance();
}
/**
View
13 src/edu/mit/securemessaging/Person.java
@@ -133,11 +133,12 @@ public Bitmap getPhoto() {
private PreparedQuery<Conversation> getConversationQuery() throws SQLException {
if (conversationQuery == null) {
QueryBuilder<Membership, String> subQuery = BACKEND.getMembershipDao().queryBuilder();
- subQuery.selectColumns(Membership.PERSON_FIELD);
- subQuery.where().eq(Membership.CONVERSATION_FIELD, this);
+ subQuery.selectColumns(Membership.CONVERSATION_FIELD);
+ subQuery.where().eq(Membership.PERSON_FIELD, this);
QueryBuilder<Conversation, String> outerQuery = BACKEND.getConversationDao().queryBuilder();
outerQuery.where().in(Conversation.ID_FIELD, subQuery);
+ outerQuery.orderBy(Conversation.TIMESTAMP_FIELD, false);
conversationQuery = outerQuery.prepare();
}
@@ -156,6 +157,14 @@ public Bitmap getPhoto() {
}
}
+ public Conversation getLastConversation() {
+ try {
+ return BACKEND.getConversationDao().queryForFirst(getConversationQuery());
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Set this person's encryption key.
* @param key
View
25 src/edu/mit/securemessaging/activities/ContactPickerActivity.java
@@ -2,9 +2,10 @@
import java.sql.SQLException;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+import com.j256.ormlite.stmt.QueryBuilder;
-import edu.mit.securemessaging.DatabaseHelper;
+import edu.mit.securemessaging.Backend;
+import edu.mit.securemessaging.Membership;
import edu.mit.securemessaging.Person;
import edu.mit.securemessaging.R;
import edu.mit.securemessaging.TrustLevel;
@@ -18,20 +19,34 @@
import android.widget.ListView;
import android.widget.TextView;
-public class ContactPickerActivity extends OrmLiteBaseActivity<DatabaseHelper> {
+public class ContactPickerActivity extends Activity {
+ private static Backend BACKEND = null;
/** Called when the activity is first created. */
private ListView contactList;
@Override
public void onCreate(Bundle savedInstanceState) {
+ if (BACKEND == null) BACKEND = Backend.getInstance();
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_picker);
contactList = (ListView)findViewById(R.id.contactList);
+ contactList.setEmptyView((TextView)findViewById(R.id.contactListEmpty));
+ String id = getIntent().getStringExtra("conversation_id");
try {
+ QueryBuilder<Person, String> b = BACKEND.getPersonDao().queryBuilder();
+ b.orderBy(Person.NAME_FIELD, false);
+ if (id != null) {
+ QueryBuilder<Membership, String> subQuery = BACKEND.getMembershipDao().queryBuilder();
+ subQuery.selectColumns(Membership.PERSON_FIELD);
+ subQuery.where().eq(Membership.CONVERSATION_FIELD, id);
+ b.where().notIn(Person.TRUST_FIELD, TrustLevel.UNKNOWN, TrustLevel.ME).and().notIn(Person.ID_FIELD, subQuery);
+ } else {
+ b.where().notIn(Person.TRUST_FIELD, TrustLevel.UNKNOWN, TrustLevel.ME);
+ }
contactList.setAdapter(
new ContactAdapter(this,
R.layout.contact,
- getHelper().getPersonDao().queryBuilder().orderBy("name", false).where().notIn(Person.TRUST_FIELD, TrustLevel.UNKNOWN, TrustLevel.ME).prepare(),
- getHelper())
+ b.prepare(),
+ BACKEND.getHelper())
);
} catch (SQLException e) {
throw new RuntimeException(e);
View
160 src/edu/mit/securemessaging/activities/ContactsActivity.java
@@ -2,11 +2,9 @@
import java.sql.SQLException;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
-
import edu.mit.securemessaging.Backend;
import edu.mit.securemessaging.Backend.ContactsListener;
-import edu.mit.securemessaging.DatabaseHelper;
+import edu.mit.securemessaging.Conversation;
import edu.mit.securemessaging.Person;
import edu.mit.securemessaging.R;
import edu.mit.securemessaging.TrustLevel;
@@ -21,44 +19,78 @@
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
-public class ContactsActivity extends OrmLiteBaseActivity<DatabaseHelper> {
- protected static enum ContactDialog {
- ADD_CONTACT, DELETE_CONTACT, DELETE_CONTACT_CONFIRM, DELETE_CONTACT_CONFIRM_WIPE;
- public static ContactDialog valueOf(int ordinal) {
- return values()[ordinal];
- }
- }
+public class ContactsActivity extends Activity {
+ private static Backend BACKEND = null;
+
+ // Use ints for speed as recommended by android. (Really? speed+java?)
+ protected static final int DIALOG_ADD = 1;
+ protected static final int DIALOG_MODIFY = 2;
+ protected static final int DIALOG_DELETE = 3;
+ protected static final int DIALOG_DELETE_CONFIRM = 4;
+ protected static final int DIALOG_DELETE_CONFIRM_WIPE = 5;
+
+ // Add dialog indices
+ protected static final int DIALOG_ADD_BARCODE = 0;
+ protected static final int DIALOG_ADD_MANUAL = 1;
+
+ // Modify dialog indices
+ protected static final int DIALOG_MODIFY_EDIT = 0;
+ protected static final int DIALOG_MODIFY_DELETE = 1;
+
/** Called when the activity is first created. */
private ListView contactList;
private Button btnAddContact;
@Override
public void onCreate(Bundle savedInstanceState) {
+ if (BACKEND == null) BACKEND = Backend.getInstance();
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts);
Backend backend = Backend.getInstance();
contactList = (ListView)findViewById(R.id.contactList);
+ contactList.setEmptyView(findViewById(R.id.contactListEmpty));
try {
contactList.setAdapter(
new ContactAdapter(this,
R.layout.contact,
- getHelper().getPersonDao().queryBuilder().orderBy("name", false).where().notIn(Person.TRUST_FIELD, TrustLevel.UNKNOWN, TrustLevel.ME).prepare(),
- getHelper())
+ BACKEND.getPersonDao().queryBuilder().orderBy("name", false).where().notIn(Person.TRUST_FIELD, TrustLevel.UNKNOWN, TrustLevel.ME).prepare(),
+ BACKEND.getHelper())
);
} catch (SQLException e) {
throw new RuntimeException(e);
}
contactList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- editContact((Person)parent.getItemAtPosition(position));
+ // TODO: Does this make sense? We can also filter or find last updated.
+ Person person = ((Person)parent.getItemAtPosition(position));
+ Conversation conversation = person.getLastConversation();
+ if (conversation == null) {
+ conversation = BACKEND.newConversation();
+ conversation.addMember(person);
+ }
+
+ Intent intent = new Intent(view.getContext(), ConversationActivity.class);
+ intent.putExtra("id", conversation.getID());
+ startActivity(intent);
+ }
+ });
+
+ contactList.setOnItemLongClickListener(new OnItemLongClickListener() {
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ final Bundle args = new Bundle();
+ args.putString("id", ((Person)parent.getItemAtPosition(position)).getID());
+ showDialog(DIALOG_MODIFY, args);
+ return true;
}
+
});
// Show right button.
@@ -67,7 +99,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
btnAddContact.setVisibility(View.VISIBLE);
btnAddContact.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- showDialog(ContactDialog.ADD_CONTACT.ordinal());
+ showDialog(DIALOG_ADD);
}
});
@@ -86,43 +118,87 @@ public void run() {
});
}
- protected Dialog onCreateDialog(int id) {
- Dialog dialog;
- switch(ContactDialog.valueOf(id)) {
- case ADD_CONTACT:
- return createAddDialog();
+ @Override
+ protected Dialog onCreateDialog(int id, final Bundle bundle) {
+ final Dialog dialog;
+ final String personId;
+ switch(id) {
+ case DIALOG_ADD:
+ dialog = new AlertDialog.Builder(this)
+ .setTitle(R.string.dialog_add_contact_title)
+ .setItems(R.array.dialog_add_contact_menu, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ switch(item) {
+ case DIALOG_ADD_BARCODE:
+ Toast.makeText(getApplicationContext(), "You have scanned someone's barcode.", Toast.LENGTH_LONG).show();
+ break;
+ case DIALOG_ADD_MANUAL:
+ addContact();
+ break;
+ }
+ }
+ }).create();
+ dialog.setCancelable(true);
+ break;
+ case DIALOG_MODIFY:
+ personId = bundle.getString("id");
+ try {
+ dialog = new AlertDialog.Builder(this)
+ .setTitle(getResources().getString(
+ R.string.dialog_modify_contact_title,
+ BACKEND.getPersonDao().queryForId(personId).getName()))
+ .setItems( R.array.dialog_modify_contact_menu, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ switch(item) {
+ case DIALOG_MODIFY_EDIT:
+ editContact(personId);
+ break;
+ case DIALOG_MODIFY_DELETE:
+ showDialog(DIALOG_DELETE, bundle);
+ break;
+ }
+ }
+ }).create();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ dialog.setCancelable(true);
+ break;
+ case DIALOG_DELETE:
+ personId = bundle.getString("id");
+ try {
+ dialog = new AlertDialog.Builder(this)
+ .setTitle(R.string.dialog_delete_contact_title)
+ .setMessage(getResources().getString(
+ R.string.dialog_delete_contact_message,
+ BACKEND.getPersonDao().queryForId(personId).getName()))
+ .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ showDialog(DIALOG_DELETE_CONFIRM, bundle);
+ }})
+ .setNegativeButton(android.R.string.no, null).create();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ dialog.setCancelable(true);
+ break;
+ case DIALOG_DELETE_CONFIRM:
+ Toast.makeText(getApplicationContext(), "Deleted", Toast.LENGTH_SHORT).show();
default:
dialog = null;
}
return dialog;
}
- protected AlertDialog createAddDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- final CharSequence[] items = {
- "Add By Barcode",
- "Add Manually",
- };
- builder.setTitle(R.string.add_contact_title);
- builder.setItems(items, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- switch(item) {
- case 0:
- Toast.makeText(getApplicationContext(), "You have scanned someone's barcode.", Toast.LENGTH_LONG).show();
- break;
- case 1:
- addContact();
- break;
- }
- }
- });
- return builder.create();
+ public void editContact(String contactID) {
+ Intent intent = new Intent(this, EditContactActivity.class);
+ intent.putExtra("id", contactID);
+ startActivityForResult(intent, 0); // Should be const later TODO
}
+
public void editContact(Person contact) {
- Intent intent = new Intent(this, EditContactActivity.class);
- intent.putExtra("id", contact.getID());
- startActivityForResult(intent, 0); // Should be const later TODO
+ editContact(contact.getID());
}
public void addContact() {
View
56 src/edu/mit/securemessaging/activities/ConversationActivity.java
@@ -2,36 +2,28 @@
import java.sql.SQLException;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import edu.mit.securemessaging.Backend;
import edu.mit.securemessaging.Common;
import edu.mit.securemessaging.Conversation;
+import edu.mit.securemessaging.Message;
import edu.mit.securemessaging.Conversation.ConversationListener;
-import edu.mit.securemessaging.DatabaseHelper;
import edu.mit.securemessaging.R;
import edu.mit.securemessaging.widgets.MessageAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
-import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
-public class ConversationActivity extends OrmLiteBaseActivity<DatabaseHelper> {
- private final Backend backend = Backend.getInstance();
- private static enum Request {
- ADD_CONTACT;
-
- public static Request valueOf(int ordinal) {
- return values()[ordinal];
- }
- }
+public class ConversationActivity extends Activity {
+ private static Backend BACKEND = null;
+ private static final int ADD_CONTACT = 1;
/** Called when the activity is first created. */
private ListView listMessages;
@@ -40,21 +32,28 @@ public static Request valueOf(int ordinal) {
private ImageView icon;
@Override
public void onCreate(Bundle savedInstanceState) {
+ if (BACKEND == null) BACKEND = Backend.getInstance();
super.onCreate(savedInstanceState);
+
+ final MessageAdapter adapter;
+
setContentView(R.layout.conversation_activity);
- conversation = backend.getConversation(getIntent().getStringExtra("id"));
+ conversation = BACKEND.getConversation(getIntent().getStringExtra("id"));
listMessages = (ListView)findViewById(R.id.messageList);
+ listMessages.setEmptyView(findViewById(R.id.conversationEmpty));
try {
- listMessages.setAdapter(
- new MessageAdapter(this,
- R.layout.message,
- getHelper().getMessageDao().queryBuilder().orderBy("timestamp", true).where().eq("conversation_id", conversation).prepare(),
- getHelper())
- );
+ adapter = new MessageAdapter(this,
+ R.layout.message,
+ BACKEND.getMessageDao().queryBuilder().orderBy(Message.TIMESTAMP_FIELD, true)
+ .where().eq(Message.CONVERSATION_FIELD, conversation).prepare(),
+ BACKEND.getHelper());
} catch (SQLException e) {
throw new RuntimeException(e);
}
+ listMessages.setAdapter(adapter);
listMessages.setItemsCanFocus(false);
+ int position = adapter.getCount() - 1;
+ listMessages.smoothScrollToPosition(position > 0 ? position : 0);
((TextView)findViewById(R.id.labelHeader)).setText("Placeholder conversation text");
// Show right button.
@@ -64,7 +63,8 @@ public void onCreate(Bundle savedInstanceState) {
btnAddUser.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), ContactPickerActivity.class);
- startActivityForResult(intent, Request.ADD_CONTACT.ordinal());
+ intent.putExtra("conversation_id", conversation.getID());
+ startActivityForResult(intent, ADD_CONTACT);
}
});
@@ -94,12 +94,12 @@ public void onClick(View v) {
public void onConversationUpdated() {
runOnUiThread(new Runnable() {
public void run() {
- title.setText(Common.formatConversationTitle(conversation));
- icon.setImageResource(Common.getConversationIcon(conversation));
- BaseAdapter adapter = ((BaseAdapter)listMessages.getAdapter());
- adapter.notifyDataSetChanged();
- int position = adapter.getCount() - 1;
- listMessages.smoothScrollToPosition(position > 0 ? position : 0);
+ title.setText(Common.formatConversationTitle(conversation));
+ icon.setImageResource(Common.getConversationIcon(conversation));
+ adapter.update();
+ adapter.notifyDataSetChanged();
+ int position = adapter.getCount() - 1;
+ listMessages.smoothScrollToPosition(position > 0 ? position : 0);
}
});
}
@@ -111,10 +111,10 @@ public void onActivityResult(int request, int result, Intent data) {
if (result != Activity.RESULT_OK) {
return;
}
- switch (Request.valueOf(request)) {
+ switch (request) {
case ADD_CONTACT:
try {
- conversation.addMember(backend.getPerson(data.getStringExtra("id")));
+ conversation.addMember(BACKEND.getPerson(data.getStringExtra("id")));
} catch (SQLException e) {
new RuntimeException(e);
}
View
4 src/edu/mit/securemessaging/activities/EditContactActivity.java
@@ -2,10 +2,8 @@
import java.sql.SQLException;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import edu.mit.securemessaging.Backend;
-import edu.mit.securemessaging.DatabaseHelper;
import edu.mit.securemessaging.Person;
import edu.mit.securemessaging.R;
import edu.mit.securemessaging.TrustLevel;
@@ -18,7 +16,7 @@
import android.widget.EditText;
import android.widget.TextView;
-public class EditContactActivity extends OrmLiteBaseActivity<DatabaseHelper> {
+public class EditContactActivity extends Activity {
/** Called when the activity is first created. */
private Backend backend = Backend.getInstance();
private EditText name;
View
20 src/edu/mit/securemessaging/activities/InboxActivity.java
@@ -2,14 +2,13 @@
import java.sql.SQLException;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import edu.mit.securemessaging.Backend;
import edu.mit.securemessaging.Backend.InboxListener;
import edu.mit.securemessaging.Conversation;
-import edu.mit.securemessaging.DatabaseHelper;
import edu.mit.securemessaging.R;
import edu.mit.securemessaging.widgets.ConversationAdapter;
+import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -21,21 +20,24 @@
import android.widget.ListView;
import android.widget.TextView;
-public class InboxActivity extends OrmLiteBaseActivity<DatabaseHelper> {
+public class InboxActivity extends Activity {
/** Called when the activity is first created. */
- private final static Backend backend = Backend.getInstance();
+ private static Backend BACKEND = null;
private ListView conversationList;
@Override
public void onCreate(Bundle savedInstanceState) {
+ if (BACKEND == null) BACKEND = Backend.getInstance();
super.onCreate(savedInstanceState);
+
setContentView(R.layout.inbox);
conversationList = (ListView)findViewById(R.id.conversationList);
+ conversationList.setEmptyView(findViewById(R.id.inboxEmpty));
try {
conversationList.setAdapter(
new ConversationAdapter(this,
R.layout.conversation,
- getHelper().getConversationDao().queryBuilder().orderBy("timestamp", false).prepare(),
- getHelper())
+ BACKEND.getConversationDao().queryBuilder().orderBy("timestamp", false).prepare(),
+ BACKEND.getHelper())
);
} catch (SQLException e) {
throw new RuntimeException(e);
@@ -44,7 +46,7 @@ public void onCreate(Bundle savedInstanceState) {
conversationList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(view.getContext(), ConversationActivity.class);
- intent.putExtra("id", ((Conversation)parent.getItemAtPosition(position)).getID()); // XXX: Temp var
+ intent.putExtra("id", ((Conversation)parent.getItemAtPosition(position)).getID());
startActivity(intent);
}
});
@@ -56,13 +58,13 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
btnNewConversation.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), ConversationActivity.class);
- intent.putExtra("id", backend.newConversation().getID());
+ intent.putExtra("id", BACKEND.newConversation().getID());
startActivity(intent);
}
});
- backend.addInboxListener(new InboxListener() {
+ BACKEND.addInboxListener(new InboxListener() {
public void InboxUpdated() {
runOnUiThread(new Runnable() {
public void run() {
View
2 src/edu/mit/securemessaging/activities/MainActivity.java
@@ -47,6 +47,6 @@ public void onCreate(Bundle savedInstanceState) {
) .setContent(intent);
tabHost.addTab(spec);
- tabHost.setCurrentTab(1);
+ tabHost.setCurrentTab(0);
}
}
View
22 src/edu/mit/securemessaging/widgets/ConversationAdapter.java
@@ -1,8 +1,6 @@
package edu.mit.securemessaging.widgets;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.stmt.PreparedQuery;
@@ -46,21 +44,21 @@ public void setView(View row) {
@Override
public void update(Conversation convo) {
- List<Message> messageList = new ArrayList<Message>(convo.getMessages());
-
memberText.setText(Common.formatConversationTitle(convo));
//set timestamp Textfield
timeDisplay.setText(Common.formatDate(convo.getTimestamp()));
- if(messageList.isEmpty())
- this.messagePreview.setText("No messages");
- else
- try {
- this.messagePreview.setText(convo.getLatestMessage().getContents());
- } catch (SQLException e) {
- this.messagePreview.setText("");
- }
+ try {
+ Message m = convo.getLatestMessage();
+ if (m == null) {
+ this.messagePreview.setText("No messages");
+ } else {
+ this.messagePreview.setText(m.getContents());
+ }
+ } catch (SQLException e) {
+ this.messagePreview.setText("");
+ }
icon.setImageResource(Common.getConversationIcon(convo));
View
6 src/edu/mit/securemessaging/widgets/SimpleQueryAdapter.java
@@ -102,4 +102,10 @@ public Context getContext() {
public abstract void setView(View row);
public abstract void update(T obj);
}
+
+ public void update() {
+ // Deprecated and slow but compatible and easy.
+ // TODO Maybe fix?
+ getCursor().requery();
+ }
}

0 comments on commit 9f6710f

Please sign in to comment.