mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Replaced last connection time with time of last private message.
This commit is contained in:
@@ -12,7 +12,6 @@ import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -127,15 +126,12 @@ ConnectionListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
Map<ContactId, Long> times = db.getLastConnected();
|
||||
for(Contact c : db.getContacts()) {
|
||||
Long lastConnected = times.get(c.getId());
|
||||
if(lastConnected == null) continue;
|
||||
try {
|
||||
GroupId inbox = db.getInboxGroupId(c.getId());
|
||||
Collection<MessageHeader> headers =
|
||||
db.getInboxMessageHeaders(c.getId());
|
||||
displayContact(c, lastConnected, inbox, headers);
|
||||
displayContact(c, inbox, headers);
|
||||
} catch(NoSuchContactException e) {
|
||||
// Continue
|
||||
}
|
||||
@@ -164,7 +160,7 @@ ConnectionListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayContact(final Contact c, final long lastConnected,
|
||||
private void displayContact(final Contact c,
|
||||
final GroupId inbox, final Collection<MessageHeader> headers) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -175,8 +171,7 @@ ConnectionListener {
|
||||
ContactListItem item = findItem(c.getId());
|
||||
if(item != null) adapter.remove(item);
|
||||
// Add a new item
|
||||
adapter.add(new ContactListItem(c, connected, lastConnected,
|
||||
inbox, headers));
|
||||
adapter.add(new ContactListItem(c, connected, inbox, headers));
|
||||
adapter.sort(ContactListItemComparator.INSTANCE);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
@@ -308,12 +303,10 @@ ConnectionListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = findItem(c);
|
||||
if(item == null) return;
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Setting connection status " + connected);
|
||||
item.setConnected(connected);
|
||||
item.setLastConnected(System.currentTimeMillis());
|
||||
adapter.notifyDataSetChanged();
|
||||
if(item != null) {
|
||||
item.setConnected(connected);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.android.util.LayoutUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.text.Html;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -62,17 +61,19 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
|
||||
else name.setText(contactName);
|
||||
layout.addView(name);
|
||||
|
||||
TextView connected = new TextView(ctx);
|
||||
connected.setPadding(0, pad, pad, pad);
|
||||
if(item.isConnected()) {
|
||||
connected.setText(R.string.contact_connected);
|
||||
if(item.isEmpty()) {
|
||||
TextView noMessages = new TextView(ctx);
|
||||
noMessages.setPadding(pad, pad, pad, pad);
|
||||
noMessages.setTextColor(res.getColor(R.color.no_private_messages));
|
||||
noMessages.setText(R.string.no_private_messages);
|
||||
layout.addView(noMessages);
|
||||
} else {
|
||||
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)));
|
||||
TextView date = new TextView(ctx);
|
||||
date.setPadding(pad, pad, pad, pad);
|
||||
long timestamp = item.getTimestamp();
|
||||
date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
layout.addView(date);
|
||||
}
|
||||
layout.addView(connected);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -11,18 +11,15 @@ class ContactListItem {
|
||||
|
||||
private final Contact contact;
|
||||
private final GroupId inbox;
|
||||
private boolean connected;
|
||||
private long lastConnected;
|
||||
private boolean empty;
|
||||
private boolean connected, empty;
|
||||
private long timestamp;
|
||||
private int unread;
|
||||
|
||||
ContactListItem(Contact contact, boolean connected, long lastConnected,
|
||||
GroupId inbox, Collection<MessageHeader> headers) {
|
||||
ContactListItem(Contact contact, boolean connected, GroupId inbox,
|
||||
Collection<MessageHeader> headers) {
|
||||
this.contact = contact;
|
||||
this.inbox = inbox;
|
||||
this.connected = connected;
|
||||
this.lastConnected = lastConnected;
|
||||
setHeaders(headers);
|
||||
}
|
||||
|
||||
@@ -46,14 +43,6 @@ class ContactListItem {
|
||||
return inbox;
|
||||
}
|
||||
|
||||
long getLastConnected() {
|
||||
return lastConnected;
|
||||
}
|
||||
|
||||
void setLastConnected(long lastConnected) {
|
||||
this.lastConnected = lastConnected;
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user