Removed last connection time from Contact class, tightened up layouts.

This commit is contained in:
akwizgran
2013-04-15 14:44:42 +01:00
parent 2ef06f8564
commit c5fa3d1841
25 changed files with 115 additions and 125 deletions

View File

@@ -12,7 +12,7 @@
<string name="new_identity_item">New identity\u2026</string> <string name="new_identity_item">New identity\u2026</string>
<string name="contact_list_title">Contacts</string> <string name="contact_list_title">Contacts</string>
<string name="contact_connected">Connected</string> <string name="contact_connected">Connected</string>
<string name="format_contact_last_connected">Last connected &lt;br /&gt; %1$s</string> <string name="format_last_connected">Last connected &lt;br /&gt; %1$s</string>
<string name="add_contact_title">Add a Contact</string> <string name="add_contact_title">Add a Contact</string>
<string name="your_nickname">Your nickname: </string> <string name="your_nickname">Your nickname: </string>
<string name="wifi_not_available">Wi-Fi is NOT AVAILABLE</string> <string name="wifi_not_available">Wi-Fi is NOT AVAILABLE</string>

View File

@@ -54,7 +54,6 @@ class BlogAdapter extends ArrayAdapter<GroupMessageHeader> {
authorLayout.setGravity(CENTER_VERTICAL); authorLayout.setGravity(CENTER_VERTICAL);
ImageView thumb = new ImageView(ctx); ImageView thumb = new ImageView(ctx);
thumb.setPadding(10, 10, 10, 10);
Rating rating = item.getRating(); Rating rating = item.getRating();
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
@@ -66,7 +65,7 @@ class BlogAdapter extends ArrayAdapter<GroupMessageHeader> {
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
Author author = item.getAuthor(); Author author = item.getAuthor();
if(author == null) { if(author == null) {
name.setTextColor(res.getColor(R.color.anonymous_author)); name.setTextColor(res.getColor(R.color.anonymous_author));
@@ -90,7 +89,6 @@ class BlogAdapter extends ArrayAdapter<GroupMessageHeader> {
LinearLayout attachmentLayout = new LinearLayout(ctx); LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL); attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx); ImageView attachment = new ImageView(ctx);
attachment.setPadding(10, 0, 10, 10);
attachment.setImageResource(R.drawable.content_attachment); attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment); attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx)); attachmentLayout.addView(new HorizontalSpace(ctx));

View File

@@ -78,7 +78,6 @@ implements OnItemClickListener {
LinearLayout attachmentLayout = new LinearLayout(ctx); LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL); attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx); ImageView attachment = new ImageView(ctx);
attachment.setPadding(10, 0, 10, 10);
attachment.setImageResource(R.drawable.content_attachment); attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment); attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx)); attachmentLayout.addView(new HorizontalSpace(ctx));

View File

@@ -123,25 +123,24 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL); header.setGravity(CENTER_VERTICAL);
thumb = new ImageView(this); thumb = new ImageView(this);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated); else thumb.setImageResource(R.drawable.rating_unrated);
header.addView(thumb); header.addView(thumb);
TextView author = new TextView(this); TextView name = new TextView(this);
// Give me all the unused width // Give me all the unused width
author.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18); name.setTextSize(18);
author.setMaxLines(1); name.setMaxLines(1);
author.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
if(authorName == null) { if(authorName == null) {
author.setTextColor(res.getColor(R.color.anonymous_author)); name.setTextColor(res.getColor(R.color.anonymous_author));
author.setText(R.string.anonymous); name.setText(R.string.anonymous);
} else { } else {
author.setText(authorName); name.setText(authorName);
} }
header.addView(author); header.addView(name);
TextView date = new TextView(this); TextView date = new TextView(this);
date.setTextSize(14); date.setTextSize(14);

View File

@@ -12,6 +12,7 @@ import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_WRAP_1;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -114,10 +115,11 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
serviceConnection.waitForStartup(); serviceConnection.waitForStartup();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Collection<Contact> contacts = db.getContacts(); Collection<Contact> contacts = db.getContacts();
Map<ContactId, Long> times = db.getLastConnected();
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO)) if(LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms"); LOG.info("Load took " + duration + " ms");
displayContacts(contacts); displayContacts(contacts, times);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(WARNING)) if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -130,13 +132,16 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
}); });
} }
private void displayContacts(final Collection<Contact> contacts) { private void displayContacts(final Collection<Contact> contacts,
final Map<ContactId, Long> times) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
adapter.clear(); adapter.clear();
for(Contact c : contacts) { for(Contact c : contacts) {
boolean conn = connectionRegistry.isConnected(c.getId()); boolean now = connectionRegistry.isConnected(c.getId());
adapter.add(new ContactListItem(c, conn)); Long last = times.get(c.getId());
if(last != null)
adapter.add(new ContactListItem(c, now, last));
} }
adapter.sort(ContactComparator.INSTANCE); adapter.sort(ContactComparator.INSTANCE);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@@ -181,8 +186,10 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
ContactListItem item = adapter.getItem(i); ContactListItem item = adapter.getItem(i);
if(item.getContactId().equals(c)) { if(item.getContactId().equals(c)) {
if(LOG.isLoggable(INFO))
LOG.info("Updating connection time");
item.setConnected(connected); item.setConnected(connected);
// FIXME: Item is not redrawn item.setLastConnected(System.currentTimeMillis());
list.invalidate(); list.invalidate();
return; return;
} }

View File

@@ -8,6 +8,7 @@ import java.util.ArrayList;
import net.sf.briar.R; import net.sf.briar.R;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.text.Html; import android.text.Html;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View; import android.view.View;
@@ -36,7 +37,6 @@ implements OnItemClickListener {
layout.setGravity(CENTER_VERTICAL); layout.setGravity(CENTER_VERTICAL);
ImageView bulb = new ImageView(ctx); ImageView bulb = new ImageView(ctx);
bulb.setPadding(10, 10, 10, 10);
if(item.isConnected()) if(item.isConnected())
bulb.setImageResource(R.drawable.contact_connected); bulb.setImageResource(R.drawable.contact_connected);
else bulb.setImageResource(R.drawable.contact_disconnected); else bulb.setImageResource(R.drawable.contact_disconnected);
@@ -47,7 +47,7 @@ implements OnItemClickListener {
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
name.setText(item.getContactName()); name.setText(item.getContactName());
layout.addView(name); layout.addView(name);
@@ -57,8 +57,8 @@ implements OnItemClickListener {
if(item.isConnected()) { if(item.isConnected()) {
connected.setText(R.string.contact_connected); connected.setText(R.string.contact_connected);
} else { } else {
String format = ctx.getResources().getString( Resources res = ctx.getResources();
R.string.format_contact_last_connected); String format = res.getString(R.string.format_last_connected);
long then = item.getLastConnected(); long then = item.getLastConnected();
CharSequence ago = DateUtils.getRelativeTimeSpanString(then); CharSequence ago = DateUtils.getRelativeTimeSpanString(then);
connected.setText(Html.fromHtml(String.format(format, ago))); connected.setText(Html.fromHtml(String.format(format, ago)));

View File

@@ -8,10 +8,12 @@ class ContactListItem {
private final Contact contact; private final Contact contact;
private boolean connected; private boolean connected;
private long lastConnected;
ContactListItem(Contact contact, boolean connected) { ContactListItem(Contact contact, boolean connected, long lastConnected) {
this.contact = contact; this.contact = contact;
this.connected = connected; this.connected = connected;
this.lastConnected = lastConnected;
} }
ContactId getContactId() { ContactId getContactId() {
@@ -23,7 +25,11 @@ class ContactListItem {
} }
long getLastConnected() { long getLastConnected() {
return contact.getLastConnected(); return lastConnected;
}
void setLastConnected(long lastConnected) {
this.lastConnected = lastConnected;
} }
boolean isConnected() { boolean isConnected() {

View File

@@ -54,7 +54,6 @@ class GroupAdapter extends ArrayAdapter<GroupMessageHeader> {
authorLayout.setGravity(CENTER_VERTICAL); authorLayout.setGravity(CENTER_VERTICAL);
ImageView thumb = new ImageView(ctx); ImageView thumb = new ImageView(ctx);
thumb.setPadding(10, 10, 10, 10);
Rating rating = item.getRating(); Rating rating = item.getRating();
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
@@ -66,7 +65,7 @@ class GroupAdapter extends ArrayAdapter<GroupMessageHeader> {
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
Author author = item.getAuthor(); Author author = item.getAuthor();
if(author == null) { if(author == null) {
name.setTextColor(res.getColor(R.color.anonymous_author)); name.setTextColor(res.getColor(R.color.anonymous_author));
@@ -90,7 +89,6 @@ class GroupAdapter extends ArrayAdapter<GroupMessageHeader> {
LinearLayout attachmentLayout = new LinearLayout(ctx); LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL); attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx); ImageView attachment = new ImageView(ctx);
attachment.setPadding(10, 0, 10, 10);
attachment.setImageResource(R.drawable.content_attachment); attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment); attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx)); attachmentLayout.addView(new HorizontalSpace(ctx));

View File

@@ -78,7 +78,6 @@ implements OnItemClickListener {
LinearLayout attachmentLayout = new LinearLayout(ctx); LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL); attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx); ImageView attachment = new ImageView(ctx);
attachment.setPadding(10, 0, 10, 10);
attachment.setImageResource(R.drawable.content_attachment); attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment); attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx)); attachmentLayout.addView(new HorizontalSpace(ctx));

View File

@@ -130,25 +130,24 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL); header.setGravity(CENTER_VERTICAL);
thumb = new ImageView(this); thumb = new ImageView(this);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated); else thumb.setImageResource(R.drawable.rating_unrated);
header.addView(thumb); header.addView(thumb);
TextView author = new TextView(this); TextView name = new TextView(this);
// Give me all the unused width // Give me all the unused width
author.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18); name.setTextSize(18);
author.setMaxLines(1); name.setMaxLines(1);
author.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
if(authorName == null) { if(authorName == null) {
author.setTextColor(res.getColor(R.color.anonymous_author)); name.setTextColor(res.getColor(R.color.anonymous_author));
author.setText(R.string.anonymous); name.setText(R.string.anonymous);
} else { } else {
author.setText(authorName); name.setText(authorName);
} }
header.addView(author); header.addView(name);
TextView date = new TextView(this); TextView date = new TextView(this);
date.setTextSize(14); date.setTextSize(14);

View File

@@ -42,7 +42,6 @@ public class BluetoothWidget extends LinearLayout implements OnClickListener {
listener.bluetoothStateChanged(false); listener.bluetoothStateChanged(false);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.bluetooth_not_available); status.setText(R.string.bluetooth_not_available);
addView(status); addView(status);
@@ -50,7 +49,6 @@ public class BluetoothWidget extends LinearLayout implements OnClickListener {
listener.bluetoothStateChanged(true); listener.bluetoothStateChanged(true);
ImageView ok = new ImageView(ctx); ImageView ok = new ImageView(ctx);
ok.setImageResource(R.drawable.navigation_accept); ok.setImageResource(R.drawable.navigation_accept);
ok.setPadding(10, 10, 10, 10);
addView(ok); addView(ok);
status.setText(R.string.bluetooth_enabled); status.setText(R.string.bluetooth_enabled);
addView(status); addView(status);
@@ -62,7 +60,6 @@ public class BluetoothWidget extends LinearLayout implements OnClickListener {
listener.bluetoothStateChanged(true); listener.bluetoothStateChanged(true);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.bluetooth_not_discoverable); status.setText(R.string.bluetooth_not_discoverable);
addView(status); addView(status);
@@ -74,7 +71,6 @@ public class BluetoothWidget extends LinearLayout implements OnClickListener {
listener.bluetoothStateChanged(false); listener.bluetoothStateChanged(false);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.bluetooth_disabled); status.setText(R.string.bluetooth_disabled);
addView(status); addView(status);

View File

@@ -26,13 +26,12 @@ implements OnClickListener {
innerLayout.setGravity(CENTER); innerLayout.setGravity(CENTER);
ImageView icon = new ImageView(ctx); ImageView icon = new ImageView(ctx);
icon.setPadding(10, 10, 10, 10);
icon.setImageResource(R.drawable.alerts_and_states_error); icon.setImageResource(R.drawable.alerts_and_states_error);
innerLayout.addView(icon); innerLayout.addView(icon);
TextView failed = new TextView(ctx); TextView failed = new TextView(ctx);
failed.setTextSize(22); failed.setTextSize(22);
failed.setPadding(0, 10, 10, 10); failed.setPadding(10, 10, 10, 10);
failed.setText(R.string.codes_do_not_match); failed.setText(R.string.codes_do_not_match);
innerLayout.addView(failed); innerLayout.addView(failed);
addView(innerLayout); addView(innerLayout);

View File

@@ -24,13 +24,12 @@ implements CodeEntryListener {
innerLayout.setGravity(CENTER); innerLayout.setGravity(CENTER);
ImageView icon = new ImageView(ctx); ImageView icon = new ImageView(ctx);
icon.setPadding(10, 10, 10, 10);
icon.setImageResource(R.drawable.navigation_accept); icon.setImageResource(R.drawable.navigation_accept);
innerLayout.addView(icon); innerLayout.addView(icon);
TextView connected = new TextView(ctx); TextView connected = new TextView(ctx);
connected.setTextSize(22); connected.setTextSize(22);
connected.setPadding(0, 10, 10, 10); connected.setPadding(10, 10, 10, 10);
connected.setText(R.string.connected_to_contact); connected.setText(R.string.connected_to_contact);
innerLayout.addView(connected); innerLayout.addView(connected);
addView(innerLayout); addView(innerLayout);

View File

@@ -28,13 +28,12 @@ implements WifiStateListener, BluetoothStateListener, OnClickListener {
innerLayout.setGravity(CENTER); innerLayout.setGravity(CENTER);
ImageView icon = new ImageView(ctx); ImageView icon = new ImageView(ctx);
icon.setPadding(10, 10, 10, 10);
icon.setImageResource(R.drawable.alerts_and_states_error); icon.setImageResource(R.drawable.alerts_and_states_error);
innerLayout.addView(icon); innerLayout.addView(icon);
TextView failed = new TextView(ctx); TextView failed = new TextView(ctx);
failed.setTextSize(22); failed.setTextSize(22);
failed.setPadding(0, 10, 10, 10); failed.setPadding(10, 10, 10, 10);
failed.setText(R.string.connection_failed); failed.setText(R.string.connection_failed);
innerLayout.addView(failed); innerLayout.addView(failed);
addView(innerLayout); addView(innerLayout);

View File

@@ -26,13 +26,12 @@ implements OnClickListener {
innerLayout.setGravity(CENTER); innerLayout.setGravity(CENTER);
ImageView icon = new ImageView(ctx); ImageView icon = new ImageView(ctx);
icon.setPadding(10, 10, 10, 10);
icon.setImageResource(R.drawable.navigation_accept); icon.setImageResource(R.drawable.navigation_accept);
innerLayout.addView(icon); innerLayout.addView(icon);
TextView added = new TextView(ctx); TextView added = new TextView(ctx);
added.setTextSize(22); added.setTextSize(22);
added.setPadding(0, 10, 10, 10); added.setPadding(10, 10, 10, 10);
added.setText(R.string.contact_added); added.setText(R.string.contact_added);
innerLayout.addView(added); innerLayout.addView(added);
addView(innerLayout); addView(innerLayout);

View File

@@ -23,15 +23,14 @@ public class WaitForContactView extends AddContactView {
innerLayout.setGravity(CENTER); innerLayout.setGravity(CENTER);
ImageView icon = new ImageView(ctx); ImageView icon = new ImageView(ctx);
icon.setPadding(10, 10, 10, 10);
icon.setImageResource(R.drawable.navigation_accept); icon.setImageResource(R.drawable.navigation_accept);
innerLayout.addView(icon); innerLayout.addView(icon);
TextView failed = new TextView(ctx); TextView connected = new TextView(ctx);
failed.setTextSize(22); connected.setTextSize(22);
failed.setPadding(0, 10, 10, 10); connected.setPadding(10, 10, 10, 10);
failed.setText(R.string.connected_to_contact); connected.setText(R.string.connected_to_contact);
innerLayout.addView(failed); innerLayout.addView(connected);
addView(innerLayout); addView(innerLayout);
TextView yourCode = new TextView(ctx); TextView yourCode = new TextView(ctx);

View File

@@ -43,7 +43,6 @@ public class WifiWidget extends LinearLayout implements OnClickListener {
wifiStateChanged(null); wifiStateChanged(null);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.wifi_not_available); status.setText(R.string.wifi_not_available);
addView(status); addView(status);
@@ -55,7 +54,6 @@ public class WifiWidget extends LinearLayout implements OnClickListener {
wifiStateChanged(null); wifiStateChanged(null);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.wifi_disconnected); status.setText(R.string.wifi_disconnected);
addView(status); addView(status);
@@ -67,7 +65,6 @@ public class WifiWidget extends LinearLayout implements OnClickListener {
wifiStateChanged(networkName); wifiStateChanged(networkName);
ImageView ok = new ImageView(ctx); ImageView ok = new ImageView(ctx);
ok.setImageResource(R.drawable.navigation_accept); ok.setImageResource(R.drawable.navigation_accept);
ok.setPadding(10, 10, 10, 10);
addView(ok); addView(ok);
String format = getResources().getString( String format = getResources().getString(
R.string.format_wifi_connected); R.string.format_wifi_connected);
@@ -82,7 +79,6 @@ public class WifiWidget extends LinearLayout implements OnClickListener {
wifiStateChanged(null); wifiStateChanged(null);
ImageView warning = new ImageView(ctx); ImageView warning = new ImageView(ctx);
warning.setImageResource(R.drawable.alerts_and_states_warning); warning.setImageResource(R.drawable.alerts_and_states_warning);
warning.setPadding(10, 10, 10, 10);
addView(warning); addView(warning);
status.setText(R.string.wifi_disabled); status.setText(R.string.wifi_disabled);
addView(status); addView(status);

View File

@@ -54,7 +54,6 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
authorLayout.setGravity(CENTER_VERTICAL); authorLayout.setGravity(CENTER_VERTICAL);
ImageView thumb = new ImageView(ctx); ImageView thumb = new ImageView(ctx);
thumb.setPadding(10, 10, 10, 10);
Rating rating = item.getRating(); Rating rating = item.getRating();
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
@@ -66,7 +65,7 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
name.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18); name.setTextSize(18);
name.setMaxLines(1); name.setMaxLines(1);
name.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
name.setText(item.getAuthor().getName()); name.setText(item.getAuthor().getName());
authorLayout.addView(name); authorLayout.addView(name);
innerLayout.addView(authorLayout); innerLayout.addView(authorLayout);
@@ -84,7 +83,6 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
LinearLayout attachmentLayout = new LinearLayout(ctx); LinearLayout attachmentLayout = new LinearLayout(ctx);
attachmentLayout.setOrientation(HORIZONTAL); attachmentLayout.setOrientation(HORIZONTAL);
ImageView attachment = new ImageView(ctx); ImageView attachment = new ImageView(ctx);
attachment.setPadding(10, 0, 10, 10);
attachment.setImageResource(R.drawable.content_attachment); attachment.setImageResource(R.drawable.content_attachment);
attachmentLayout.addView(attachment); attachmentLayout.addView(attachment);
attachmentLayout.addView(new HorizontalSpace(ctx)); attachmentLayout.addView(new HorizontalSpace(ctx));

View File

@@ -122,20 +122,19 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL); header.setGravity(CENTER_VERTICAL);
ImageView thumb = new ImageView(this); ImageView thumb = new ImageView(this);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good); if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad); else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated); else thumb.setImageResource(R.drawable.rating_unrated);
header.addView(thumb); header.addView(thumb);
TextView author = new TextView(this); TextView name = new TextView(this);
// Give me all the unused width // Give me all the unused width
author.setLayoutParams(WRAP_WRAP_1); name.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18); name.setTextSize(18);
author.setMaxLines(1); name.setMaxLines(1);
author.setPadding(0, 10, 10, 10); name.setPadding(10, 10, 10, 10);
author.setText(authorName); name.setText(authorName);
header.addView(author); header.addView(name);
TextView date = new TextView(this); TextView date = new TextView(this);
date.setTextSize(14); date.setTextSize(14);

View File

@@ -5,14 +5,11 @@ public class Contact {
private final ContactId id; private final ContactId id;
private final Author author; private final Author author;
private final AuthorId localAuthorId; private final AuthorId localAuthorId;
private final long lastConnected;
public Contact(ContactId id, Author author, AuthorId localAuthorId, public Contact(ContactId id, Author author, AuthorId localAuthorId) {
long lastConnected) {
this.id = id; this.id = id;
this.author = author; this.author = author;
this.localAuthorId = localAuthorId; this.localAuthorId = localAuthorId;
this.lastConnected = lastConnected;
} }
public ContactId getId() { public ContactId getId() {
@@ -27,10 +24,6 @@ public class Contact {
return localAuthorId; return localAuthorId;
} }
public long getLastConnected() {
return lastConnected;
}
@Override @Override
public int hashCode() { public int hashCode() {
return id.hashCode(); return id.hashCode();

View File

@@ -184,6 +184,12 @@ public interface DatabaseComponent {
Collection<GroupMessageHeader> getGroupMessageHeaders(GroupId g) Collection<GroupMessageHeader> getGroupMessageHeaders(GroupId g)
throws DbException; throws DbException;
/**
* Returns the time at which a connection to each contact was last opened
* or closed.
*/
Map<ContactId, Long> getLastConnected() throws DbException;
/** Returns the pseudonym with the given ID. */ /** Returns the pseudonym with the given ID. */
LocalAuthor getLocalAuthor(AuthorId a) throws DbException; LocalAuthor getLocalAuthor(AuthorId a) throws DbException;

View File

@@ -237,7 +237,7 @@ interface Database<T> {
/** /**
* Returns the contact with the given ID. * Returns the contact with the given ID.
* <p> * <p>
* Locking: contact read, window read. * Locking: contact read.
*/ */
Contact getContact(T txn, ContactId c) throws DbException; Contact getContact(T txn, ContactId c) throws DbException;
@@ -292,12 +292,12 @@ interface Database<T> {
MessageId getGroupMessageParent(T txn, MessageId m) throws DbException; MessageId getGroupMessageParent(T txn, MessageId m) throws DbException;
/** /**
* Returns the time at which a connection to the given contact was last * Returns the time at which a connection to each contact was last opened
* made. * or closed.
* <p> * <p>
* Locking: window read. * Locking: window read.
*/ */
long getLastConnected(T txn, ContactId c) throws DbException; Map<ContactId, Long> getLastConnected(T txn) throws DbException;
/** /**
* Returns the pseudonym with the given ID. * Returns the pseudonym with the given ID.

View File

@@ -926,21 +926,16 @@ DatabaseCleaner.Callback {
public Contact getContact(ContactId c) throws DbException { public Contact getContact(ContactId c) throws DbException {
contactLock.readLock().lock(); contactLock.readLock().lock();
try { try {
windowLock.readLock().lock(); T txn = db.startTransaction();
try { try {
T txn = db.startTransaction(); if(!db.containsContact(txn, c))
try { throw new NoSuchContactException();
if(!db.containsContact(txn, c)) Contact contact = db.getContact(txn, c);
throw new NoSuchContactException(); db.commitTransaction(txn);
Contact contact = db.getContact(txn, c); return contact;
db.commitTransaction(txn); } catch(DbException e) {
return contact; db.abortTransaction(txn);
} catch(DbException e) { throw e;
db.abortTransaction(txn);
throw e;
}
} finally {
windowLock.readLock().unlock();
} }
} finally { } finally {
contactLock.readLock().unlock(); contactLock.readLock().unlock();
@@ -1019,6 +1014,23 @@ DatabaseCleaner.Callback {
} }
} }
public Map<ContactId, Long> getLastConnected() throws DbException {
windowLock.readLock().lock();
try {
T txn = db.startTransaction();
try {
Map<ContactId, Long> times = db.getLastConnected(txn);
db.commitTransaction(txn);
return times;
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
windowLock.readLock().unlock();
}
}
public LocalAuthor getLocalAuthor(AuthorId a) throws DbException { public LocalAuthor getLocalAuthor(AuthorId a) throws DbException {
identityLock.readLock().lock(); identityLock.readLock().lock();
try { try {

View File

@@ -1200,12 +1200,9 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT authorId, name, publicKey, localAuthorId," String sql = "SELECT authorId, name, publicKey, localAuthorId"
+ " lastConnected" + " FROM contacts"
+ " FROM contacts AS c" + " WHERE contactId = ?";
+ " JOIN connectionTimes AS ct"
+ " ON c.contactId = ct.contactId"
+ " WHERE c.contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
rs = ps.executeQuery(); rs = ps.executeQuery();
@@ -1214,11 +1211,10 @@ abstract class JdbcDatabase implements Database<Connection> {
String name = rs.getString(2); String name = rs.getString(2);
byte[] publicKey = rs.getBytes(3); byte[] publicKey = rs.getBytes(3);
AuthorId localAuthorId = new AuthorId(rs.getBytes(4)); AuthorId localAuthorId = new AuthorId(rs.getBytes(4));
long lastConnected = rs.getLong(5);
rs.close(); rs.close();
ps.close(); ps.close();
Author author = new Author(authorId, name, publicKey); Author author = new Author(authorId, name, publicKey);
return new Contact(c, author, localAuthorId, lastConnected); return new Contact(c, author, localAuthorId);
} catch(SQLException e) { } catch(SQLException e) {
tryToClose(rs); tryToClose(rs);
tryToClose(ps); tryToClose(ps);
@@ -1251,11 +1247,9 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT c.contactId, authorId, name, publicKey," String sql = "SELECT contactId, authorId, name, publicKey,"
+ " localAuthorId, lastConnected" + " localAuthorId"
+ " FROM contacts AS c" + " FROM contacts";
+ " JOIN connectionTimes AS ct"
+ " ON c.contactId = ct.contactId";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Contact> contacts = new ArrayList<Contact>(); List<Contact> contacts = new ArrayList<Contact>();
@@ -1264,11 +1258,9 @@ abstract class JdbcDatabase implements Database<Connection> {
AuthorId authorId = new AuthorId(rs.getBytes(2)); AuthorId authorId = new AuthorId(rs.getBytes(2));
String name = rs.getString(3); String name = rs.getString(3);
byte[] publicKey = rs.getBytes(4); byte[] publicKey = rs.getBytes(4);
AuthorId localAuthorId = new AuthorId(rs.getBytes(5));
long lastConnected = rs.getLong(6);
Author author = new Author(authorId, name, publicKey); Author author = new Author(authorId, name, publicKey);
contacts.add(new Contact(contactId, author, localAuthorId, AuthorId localAuthorId = new AuthorId(rs.getBytes(5));
lastConnected)); contacts.add(new Contact(contactId, author, localAuthorId));
} }
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1409,22 +1401,20 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
public long getLastConnected(Connection txn, ContactId c) public Map<ContactId, Long> getLastConnected(Connection txn)
throws DbException { throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT lastConnected FROM connectionTimes" String sql = "SELECT contactId, lastConnected FROM connectionTimes";
+ " WHERE contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
rs = ps.executeQuery(); rs = ps.executeQuery();
if(!rs.next()) throw new DbStateException(); Map<ContactId, Long> times = new HashMap<ContactId, Long>();
long lastConnected = rs.getLong(1); while(rs.next())
if(rs.next()) throw new DbStateException(); times.put(new ContactId(rs.getInt(1)), rs.getLong(2));
rs.close(); rs.close();
ps.close(); ps.close();
return lastConnected; return Collections.unmodifiableMap(times);
} catch(SQLException e) { } catch(SQLException e) {
tryToClose(rs); tryToClose(rs);
tryToClose(ps); tryToClose(ps);

View File

@@ -106,7 +106,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
transportProperties = new TransportProperties(Collections.singletonMap( transportProperties = new TransportProperties(Collections.singletonMap(
"foo", "bar")); "foo", "bar"));
contactId = new ContactId(234); contactId = new ContactId(234);
contact = new Contact(contactId, author, localAuthorId, timestamp); contact = new Contact(contactId, author, localAuthorId);
endpoint = new Endpoint(contactId, transportId, 123, true); endpoint = new Endpoint(contactId, transportId, 123, true);
temporarySecret = new TemporarySecret(contactId, transportId, 123, temporarySecret = new TemporarySecret(contactId, transportId, 123,
false, 234, new byte[32], 345, 456, new byte[4]); false, 234, new byte[32], 345, 456, new byte[4]);