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

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

View File

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

View File

@@ -123,25 +123,24 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL);
thumb = new ImageView(this);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated);
header.addView(thumb);
TextView author = new TextView(this);
TextView name = new TextView(this);
// Give me all the unused width
author.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18);
author.setMaxLines(1);
author.setPadding(0, 10, 10, 10);
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setMaxLines(1);
name.setPadding(10, 10, 10, 10);
if(authorName == null) {
author.setTextColor(res.getColor(R.color.anonymous_author));
author.setText(R.string.anonymous);
name.setTextColor(res.getColor(R.color.anonymous_author));
name.setText(R.string.anonymous);
} else {
author.setText(authorName);
name.setText(authorName);
}
header.addView(author);
header.addView(name);
TextView date = new TextView(this);
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.Comparator;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
@@ -114,10 +115,11 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
serviceConnection.waitForStartup();
long now = System.currentTimeMillis();
Collection<Contact> contacts = db.getContacts();
Map<ContactId, Long> times = db.getLastConnected();
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms");
displayContacts(contacts);
displayContacts(contacts, times);
} catch(DbException e) {
if(LOG.isLoggable(WARNING))
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() {
public void run() {
adapter.clear();
for(Contact c : contacts) {
boolean conn = connectionRegistry.isConnected(c.getId());
adapter.add(new ContactListItem(c, conn));
boolean now = connectionRegistry.isConnected(c.getId());
Long last = times.get(c.getId());
if(last != null)
adapter.add(new ContactListItem(c, now, last));
}
adapter.sort(ContactComparator.INSTANCE);
adapter.notifyDataSetChanged();
@@ -181,8 +186,10 @@ implements OnClickListener, DatabaseListener, ConnectionListener {
for(int i = 0; i < count; i++) {
ContactListItem item = adapter.getItem(i);
if(item.getContactId().equals(c)) {
if(LOG.isLoggable(INFO))
LOG.info("Updating connection time");
item.setConnected(connected);
// FIXME: Item is not redrawn
item.setLastConnected(System.currentTimeMillis());
list.invalidate();
return;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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