mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Prettier display of available forums, cleaned up list comparators.
This commit is contained in:
@@ -7,5 +7,6 @@
|
|||||||
<color name="private_message_date">#AAAAAA</color>
|
<color name="private_message_date">#AAAAAA</color>
|
||||||
<color name="unread_background">#FFFFFF</color>
|
<color name="unread_background">#FFFFFF</color>
|
||||||
<color name="horizontal_border">#CCCCCC</color>
|
<color name="horizontal_border">#CCCCCC</color>
|
||||||
|
<color name="groups_available_background">#FCCF1C</color>
|
||||||
<color name="no_posts">#AAAAAA</color>
|
<color name="no_posts">#AAAAAA</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.briarproject.android;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
import org.briarproject.api.db.MessageHeader;
|
|
||||||
|
|
||||||
public class AscendingHeaderComparator implements Comparator<MessageHeader> {
|
|
||||||
|
|
||||||
public static final AscendingHeaderComparator INSTANCE =
|
|
||||||
new AscendingHeaderComparator();
|
|
||||||
|
|
||||||
public int compare(MessageHeader a, MessageHeader b) {
|
|
||||||
// The oldest message comes first
|
|
||||||
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
|
||||||
if(aTime < bTime) return -1;
|
|
||||||
if(aTime > bTime) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package org.briarproject.android.contact;
|
|
||||||
|
|
||||||
import org.briarproject.api.Contact;
|
|
||||||
|
|
||||||
public class ContactItem {
|
|
||||||
|
|
||||||
public static final ContactItem NEW = new ContactItem(null);
|
|
||||||
|
|
||||||
private final Contact contact;
|
|
||||||
|
|
||||||
public ContactItem(Contact contact) {
|
|
||||||
this.contact = contact;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contact getContact() {
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package org.briarproject.android.contact;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class ContactItemComparator implements Comparator<ContactItem> {
|
|
||||||
|
|
||||||
public static final ContactItemComparator INSTANCE =
|
|
||||||
new ContactItemComparator();
|
|
||||||
|
|
||||||
public int compare(ContactItem a, ContactItem b) {
|
|
||||||
if(a == b) return 0;
|
|
||||||
if(a == ContactItem.NEW) return 1;
|
|
||||||
if(b == ContactItem.NEW) return -1;
|
|
||||||
String aName = a.getContact().getAuthor().getName();
|
|
||||||
String bName = b.getContact().getAuthor().getName();
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@ import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
|||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -178,7 +177,7 @@ ConnectionListener {
|
|||||||
// Add a new item
|
// Add a new item
|
||||||
adapter.add(new ContactListItem(c, connected, lastConnected,
|
adapter.add(new ContactListItem(c, connected, lastConnected,
|
||||||
inbox, headers));
|
inbox, headers));
|
||||||
adapter.sort(ItemComparator.INSTANCE);
|
adapter.sort(ContactListItemComparator.INSTANCE);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -318,15 +317,4 @@ ConnectionListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ItemComparator implements Comparator<ContactListItem> {
|
|
||||||
|
|
||||||
private static final ItemComparator INSTANCE = new ItemComparator();
|
|
||||||
|
|
||||||
public int compare(ContactListItem a, ContactListItem b) {
|
|
||||||
String aName = a.getContact().getAuthor().getName();
|
|
||||||
String bName = b.getContact().getAuthor().getName();
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.android.contact;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
class ContactListItemComparator implements Comparator<ContactListItem> {
|
||||||
|
|
||||||
|
static final ContactListItemComparator INSTANCE =
|
||||||
|
new ContactListItemComparator();
|
||||||
|
|
||||||
|
public int compare(ContactListItem a, ContactListItem b) {
|
||||||
|
String aName = a.getContact().getAuthor().getName();
|
||||||
|
String bName = b.getContact().getAuthor().getName();
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,13 +8,11 @@ import static android.widget.LinearLayout.HORIZONTAL;
|
|||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.groups.GroupListItem.MANAGE;
|
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -26,6 +24,7 @@ import org.briarproject.R;
|
|||||||
import org.briarproject.android.BriarActivity;
|
import org.briarproject.android.BriarActivity;
|
||||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||||
import org.briarproject.android.util.HorizontalBorder;
|
import org.briarproject.android.util.HorizontalBorder;
|
||||||
|
import org.briarproject.android.util.LayoutUtils;
|
||||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
@@ -54,6 +53,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class GroupListActivity extends BriarActivity
|
public class GroupListActivity extends BriarActivity
|
||||||
implements EventListener, OnClickListener, OnItemClickListener {
|
implements EventListener, OnClickListener, OnItemClickListener {
|
||||||
@@ -67,6 +67,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
private GroupListAdapter adapter = null;
|
private GroupListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
|
private TextView available = null;
|
||||||
private ImageButton newGroupButton = null, manageGroupsButton = null;
|
private ImageButton newGroupButton = null, manageGroupsButton = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@@ -82,26 +83,39 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
layout.setOrientation(VERTICAL);
|
layout.setOrientation(VERTICAL);
|
||||||
layout.setGravity(CENTER_HORIZONTAL);
|
layout.setGravity(CENTER_HORIZONTAL);
|
||||||
|
|
||||||
|
int pad = LayoutUtils.getPadding(this);
|
||||||
|
|
||||||
adapter = new GroupListAdapter(this);
|
adapter = new GroupListAdapter(this);
|
||||||
list = new ListView(this);
|
list = new ListView(this);
|
||||||
// Give me all the width and all the unused height
|
// Give me all the width and all the unused height
|
||||||
list.setLayoutParams(MATCH_WRAP_1);
|
list.setLayoutParams(MATCH_WRAP_1);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setOnItemClickListener(this);
|
list.setOnItemClickListener(this);
|
||||||
|
list.setVisibility(GONE);
|
||||||
layout.addView(list);
|
layout.addView(list);
|
||||||
|
|
||||||
// Show a progress bar while the list is loading
|
// Show a progress bar while the list is loading
|
||||||
list.setVisibility(GONE);
|
|
||||||
loading = new ListLoadingProgressBar(this);
|
loading = new ListLoadingProgressBar(this);
|
||||||
layout.addView(loading);
|
layout.addView(loading);
|
||||||
|
|
||||||
|
available = new TextView(this);
|
||||||
|
available.setLayoutParams(MATCH_WRAP);
|
||||||
|
available.setGravity(CENTER);
|
||||||
|
available.setTextSize(18);
|
||||||
|
Resources res = getResources();
|
||||||
|
int background = res.getColor(R.color.groups_available_background);
|
||||||
|
available.setBackgroundColor(background);
|
||||||
|
available.setPadding(pad, pad, pad, pad);
|
||||||
|
available.setOnClickListener(this);
|
||||||
|
available.setVisibility(GONE);
|
||||||
|
layout.addView(available);
|
||||||
|
|
||||||
layout.addView(new HorizontalBorder(this));
|
layout.addView(new HorizontalBorder(this));
|
||||||
|
|
||||||
LinearLayout footer = new LinearLayout(this);
|
LinearLayout footer = new LinearLayout(this);
|
||||||
footer.setLayoutParams(MATCH_WRAP);
|
footer.setLayoutParams(MATCH_WRAP);
|
||||||
footer.setOrientation(HORIZONTAL);
|
footer.setOrientation(HORIZONTAL);
|
||||||
footer.setGravity(CENTER);
|
footer.setGravity(CENTER);
|
||||||
Resources res = getResources();
|
|
||||||
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
|
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
|
||||||
footer.addView(new ElasticHorizontalSpace(this));
|
footer.addView(new ElasticHorizontalSpace(this));
|
||||||
|
|
||||||
@@ -136,7 +150,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
lifecycleManager.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
int available = 0;
|
int availableCount = 0;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(GroupStatus s : db.getAvailableGroups()) {
|
for(GroupStatus s : db.getAvailableGroups()) {
|
||||||
Group g = s.getGroup();
|
Group g = s.getGroup();
|
||||||
@@ -149,13 +163,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
// Continue
|
// Continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
available++;
|
availableCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Full load took " + duration + " ms");
|
LOG.info("Full load took " + duration + " ms");
|
||||||
displayAvailable(available);
|
displayAvailable(availableCount);
|
||||||
} 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);
|
||||||
@@ -173,6 +187,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
groups.clear();
|
groups.clear();
|
||||||
list.setVisibility(GONE);
|
list.setVisibility(GONE);
|
||||||
|
available.setVisibility(GONE);
|
||||||
loading.setVisibility(VISIBLE);
|
loading.setVisibility(VISIBLE);
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
@@ -193,20 +208,26 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
if(item != null) adapter.remove(item);
|
if(item != null) adapter.remove(item);
|
||||||
// Add a new item
|
// Add a new item
|
||||||
adapter.add(new GroupListItem(g, headers));
|
adapter.add(new GroupListItem(g, headers));
|
||||||
adapter.sort(ItemComparator.INSTANCE);
|
adapter.sort(GroupListItemComparator.INSTANCE);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
selectFirstUnread();
|
selectFirstUnread();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayAvailable(final int available) {
|
private void displayAvailable(final int availableCount) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
list.setVisibility(VISIBLE);
|
list.setVisibility(VISIBLE);
|
||||||
loading.setVisibility(GONE);
|
loading.setVisibility(GONE);
|
||||||
adapter.setAvailable(available);
|
if(availableCount == 0) {
|
||||||
adapter.notifyDataSetChanged();
|
available.setVisibility(GONE);
|
||||||
|
} else {
|
||||||
|
available.setVisibility(VISIBLE);
|
||||||
|
String format = getResources().getQuantityString(
|
||||||
|
R.plurals.forums_available, availableCount);
|
||||||
|
available.setText(String.format(format, availableCount));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -215,7 +236,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
int count = adapter.getCount();
|
int count = adapter.getCount();
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
GroupListItem item = adapter.getItem(i);
|
GroupListItem item = adapter.getItem(i);
|
||||||
if(item == MANAGE) continue;
|
|
||||||
if(item.getGroup().getId().equals(g)) return item;
|
if(item.getGroup().getId().equals(g)) return item;
|
||||||
}
|
}
|
||||||
return null; // Not found
|
return null; // Not found
|
||||||
@@ -224,9 +244,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
private void selectFirstUnread() {
|
private void selectFirstUnread() {
|
||||||
int firstUnread = -1, count = adapter.getCount();
|
int firstUnread = -1, count = adapter.getCount();
|
||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
GroupListItem item = adapter.getItem(i);
|
if(adapter.getItem(i).getUnreadCount() > 0) {
|
||||||
if(item == MANAGE) continue;
|
|
||||||
if(item.getUnreadCount() > 0) {
|
|
||||||
firstUnread = i;
|
firstUnread = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -334,7 +352,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(view == newGroupButton) {
|
if(view == available) {
|
||||||
|
startActivity(new Intent(this, ManageGroupsActivity.class));
|
||||||
|
} else if(view == newGroupButton) {
|
||||||
startActivity(new Intent(this, CreateGroupActivity.class));
|
startActivity(new Intent(this, CreateGroupActivity.class));
|
||||||
} else if(view == manageGroupsButton) {
|
} else if(view == manageGroupsButton) {
|
||||||
startActivity(new Intent(this, ManageGroupsActivity.class));
|
startActivity(new Intent(this, ManageGroupsActivity.class));
|
||||||
@@ -343,35 +363,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||||
long id) {
|
long id) {
|
||||||
GroupListItem item = adapter.getItem(position);
|
Intent i = new Intent(this, GroupActivity.class);
|
||||||
if(item == MANAGE) {
|
Group g = adapter.getItem(position).getGroup();
|
||||||
startActivity(new Intent(this, ManageGroupsActivity.class));
|
i.putExtra("briar.GROUP_ID", g.getId().getBytes());
|
||||||
} else {
|
i.putExtra("briar.GROUP_NAME", g.getName());
|
||||||
Intent i = new Intent(this, GroupActivity.class);
|
startActivity(i);
|
||||||
Group g = item.getGroup();
|
|
||||||
i.putExtra("briar.GROUP_ID", g.getId().getBytes());
|
|
||||||
i.putExtra("briar.GROUP_NAME", g.getName());
|
|
||||||
startActivity(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ItemComparator implements Comparator<GroupListItem> {
|
|
||||||
|
|
||||||
private static final ItemComparator INSTANCE = new ItemComparator();
|
|
||||||
|
|
||||||
public int compare(GroupListItem a, GroupListItem b) {
|
|
||||||
if(a == b) return 0;
|
|
||||||
// The manage groups item comes last
|
|
||||||
if(a == MANAGE) return 1;
|
|
||||||
if(b == MANAGE) return -1;
|
|
||||||
// The item with the newest message comes first
|
|
||||||
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
|
||||||
if(aTime > bTime) return -1;
|
|
||||||
if(aTime < bTime) return 1;
|
|
||||||
// Break ties by group name
|
|
||||||
String aName = a.getGroup().getName();
|
|
||||||
String bName = b.getGroup().getName();
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
package org.briarproject.android.groups;
|
package org.briarproject.android.groups;
|
||||||
|
|
||||||
import static android.text.TextUtils.TruncateAt.END;
|
import static android.text.TextUtils.TruncateAt.END;
|
||||||
import static android.view.Gravity.CENTER;
|
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
import static android.widget.LinearLayout.HORIZONTAL;
|
||||||
import static org.briarproject.android.groups.GroupListItem.MANAGE;
|
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
import org.briarproject.android.util.LayoutUtils;
|
||||||
@@ -19,61 +14,25 @@ import android.content.res.Resources;
|
|||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
class GroupListAdapter extends BaseAdapter {
|
class GroupListAdapter extends ArrayAdapter<GroupListItem> {
|
||||||
|
|
||||||
private final Context ctx;
|
|
||||||
private final int pad;
|
private final int pad;
|
||||||
private final List<GroupListItem> list = new ArrayList<GroupListItem>();
|
|
||||||
private int available = 0;
|
|
||||||
|
|
||||||
GroupListAdapter(Context ctx) {
|
GroupListAdapter(Context ctx) {
|
||||||
this.ctx = ctx;
|
super(ctx, android.R.layout.simple_expandable_list_item_1,
|
||||||
|
new ArrayList<GroupListItem>());
|
||||||
pad = LayoutUtils.getPadding(ctx);
|
pad = LayoutUtils.getPadding(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAvailable(int available) {
|
|
||||||
this.available = available;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(GroupListItem item) {
|
|
||||||
list.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return available == 0 ? list.size() : list.size() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GroupListItem getItem(int position) {
|
|
||||||
return position == list.size() ? MANAGE : list.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return android.R.layout.simple_expandable_list_item_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
GroupListItem item = getItem(position);
|
GroupListItem item = getItem(position);
|
||||||
|
Context ctx = getContext();
|
||||||
Resources res = ctx.getResources();
|
Resources res = ctx.getResources();
|
||||||
|
|
||||||
if(item == MANAGE) {
|
|
||||||
TextView manage = new TextView(ctx);
|
|
||||||
manage.setGravity(CENTER);
|
|
||||||
manage.setTextSize(18);
|
|
||||||
manage.setPadding(pad, pad, pad, pad);
|
|
||||||
String format = res.getQuantityString(R.plurals.forums_available,
|
|
||||||
available);
|
|
||||||
manage.setText(String.format(format, available));
|
|
||||||
return manage;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearLayout layout = new LinearLayout(ctx);
|
LinearLayout layout = new LinearLayout(ctx);
|
||||||
layout.setOrientation(HORIZONTAL);
|
layout.setOrientation(HORIZONTAL);
|
||||||
int unread = item.getUnreadCount();
|
int unread = item.getUnreadCount();
|
||||||
@@ -110,17 +69,4 @@ class GroupListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return list.isEmpty() && available == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(GroupListItem item) {
|
|
||||||
list.remove(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sort(Comparator<GroupListItem> comparator) {
|
|
||||||
Collections.sort(list, comparator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.android.groups;
|
package org.briarproject.android.groups;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.briarproject.api.Author;
|
import org.briarproject.api.Author;
|
||||||
import org.briarproject.api.db.MessageHeader;
|
import org.briarproject.api.db.MessageHeader;
|
||||||
@@ -9,9 +8,6 @@ import org.briarproject.api.messaging.Group;
|
|||||||
|
|
||||||
class GroupListItem {
|
class GroupListItem {
|
||||||
|
|
||||||
static final GroupListItem MANAGE = new GroupListItem(null,
|
|
||||||
Collections.<MessageHeader>emptyList());
|
|
||||||
|
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final boolean empty;
|
private final boolean empty;
|
||||||
private final String authorName, contentType;
|
private final String authorName, contentType;
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.briarproject.android.groups;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
class GroupListItemComparator implements Comparator<GroupListItem> {
|
||||||
|
|
||||||
|
static final GroupListItemComparator INSTANCE =
|
||||||
|
new GroupListItemComparator();
|
||||||
|
|
||||||
|
public int compare(GroupListItem a, GroupListItem b) {
|
||||||
|
if(a == b) return 0;
|
||||||
|
// The item with the newest message comes first
|
||||||
|
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
||||||
|
if(aTime > bTime) return -1;
|
||||||
|
if(aTime < bTime) return 1;
|
||||||
|
// Break ties by group name
|
||||||
|
String aName = a.getGroup().getName();
|
||||||
|
String bName = b.getGroup().getName();
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import static org.briarproject.android.groups.ManageGroupsItem.NONE;
|
|||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -100,7 +99,7 @@ implements EventListener, OnItemClickListener {
|
|||||||
adapter.clear();
|
adapter.clear();
|
||||||
for(GroupStatus s : available)
|
for(GroupStatus s : available)
|
||||||
adapter.add(new ManageGroupsItem(s));
|
adapter.add(new ManageGroupsItem(s));
|
||||||
adapter.sort(ItemComparator.INSTANCE);
|
adapter.sort(ManageGroupsItemComparator.INSTANCE);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -140,19 +139,4 @@ implements EventListener, OnItemClickListener {
|
|||||||
i.putExtra("briar.VISIBLE_TO_ALL", s.isVisibleToAll());
|
i.putExtra("briar.VISIBLE_TO_ALL", s.isVisibleToAll());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ItemComparator
|
|
||||||
implements Comparator<ManageGroupsItem> {
|
|
||||||
|
|
||||||
private static final ItemComparator INSTANCE = new ItemComparator();
|
|
||||||
|
|
||||||
public int compare(ManageGroupsItem a, ManageGroupsItem b) {
|
|
||||||
if(a == b) return 0;
|
|
||||||
if(a == NONE) return 1;
|
|
||||||
if(b == NONE) return -1;
|
|
||||||
String aName = a.getGroupStatus().getGroup().getName();
|
|
||||||
String bName = b.getGroupStatus().getGroup().getName();
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.android.groups;
|
||||||
|
|
||||||
|
import static org.briarproject.android.groups.ManageGroupsItem.NONE;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
class ManageGroupsItemComparator implements Comparator<ManageGroupsItem> {
|
||||||
|
|
||||||
|
static final ManageGroupsItemComparator INSTANCE =
|
||||||
|
new ManageGroupsItemComparator();
|
||||||
|
|
||||||
|
public int compare(ManageGroupsItem a, ManageGroupsItem b) {
|
||||||
|
if(a == b) return 0;
|
||||||
|
if(a == NONE) return 1;
|
||||||
|
if(b == NONE) return -1;
|
||||||
|
String aName = a.getGroupStatus().getGroup().getName();
|
||||||
|
String bName = b.getGroupStatus().getGroup().getName();
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user