Show empty list text for contact list, group list, etc. Dev task #71.

This commit is contained in:
akwizgran
2014-02-27 23:07:26 +00:00
parent 80824b848c
commit 07b4d9b5d8
16 changed files with 141 additions and 123 deletions

View File

@@ -52,6 +52,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class ContactListActivity extends BriarActivity
implements OnClickListener, OnItemClickListener, EventListener,
@@ -61,6 +62,7 @@ ConnectionListener {
Logger.getLogger(ContactListActivity.class.getName());
@Inject private ConnectionRegistry connectionRegistry;
private TextView empty = null;
private ContactListAdapter adapter = null;
private ListView list = null;
private ListLoadingProgressBar loading = null;
@@ -79,16 +81,23 @@ ConnectionListener {
layout.setOrientation(VERTICAL);
layout.setGravity(CENTER_HORIZONTAL);
empty = new TextView(this);
empty.setLayoutParams(MATCH_WRAP_1);
empty.setGravity(CENTER);
empty.setTextSize(18);
empty.setText(R.string.no_contacts);
empty.setVisibility(GONE);
layout.addView(empty);
adapter = new ContactListAdapter(this);
list = new ListView(this);
// Give me all the width and all the unused height
list.setLayoutParams(MATCH_WRAP_1);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setVisibility(GONE);
layout.addView(list);
// Show a progress bar while the list is loading
list.setVisibility(GONE);
loading = new ListLoadingProgressBar(this);
layout.addView(loading);
@@ -156,6 +165,7 @@ ConnectionListener {
private void clearContacts() {
runOnUiThread(new Runnable() {
public void run() {
empty.setVisibility(GONE);
list.setVisibility(GONE);
loading.setVisibility(VISIBLE);
adapter.clear();
@@ -186,7 +196,8 @@ ConnectionListener {
private void hideProgressBar() {
runOnUiThread(new Runnable() {
public void run() {
list.setVisibility(VISIBLE);
if(adapter.isEmpty()) empty.setVisibility(VISIBLE);
else list.setVisibility(VISIBLE);
loading.setVisibility(GONE);
}
});
@@ -291,6 +302,10 @@ ConnectionListener {
if(item != null) {
adapter.remove(item);
adapter.notifyDataSetChanged();
if(adapter.isEmpty()) {
empty.setVisibility(VISIBLE);
list.setVisibility(GONE);
}
}
}
});

View File

@@ -52,7 +52,6 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
layout.addView(bulb);
TextView name = new TextView(ctx);
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setSingleLine();

View File

@@ -2,6 +2,7 @@ package org.briarproject.android.contact;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
@@ -72,6 +73,7 @@ import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ConversationActivity extends BriarActivity
@@ -84,6 +86,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
@Inject @CryptoExecutor private Executor cryptoExecutor;
private Map<MessageId, byte[]> bodyCache = new HashMap<MessageId, byte[]>();
private String contactName = null;
private TextView empty = null;
private ConversationAdapter adapter = null;
private ListView list = null;
private ListLoadingProgressBar loading = null;
@@ -126,6 +129,14 @@ implements EventListener, OnClickListener, OnItemClickListener {
layout.setLayoutParams(MATCH_MATCH);
layout.setOrientation(VERTICAL);
empty = new TextView(this);
empty.setLayoutParams(MATCH_WRAP_1);
empty.setGravity(CENTER);
empty.setTextSize(18);
empty.setText(R.string.no_private_messages);
empty.setVisibility(GONE);
layout.addView(empty);
adapter = new ConversationAdapter(this);
list = new ListView(this) {
@Override
@@ -135,7 +146,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
setSelection(getCount() - 1);
}
};
// Give me all the width and all the unused height
list.setLayoutParams(MATCH_WRAP_1);
int pad = LayoutUtils.getPadding(this);
list.setPadding(0, pad, 0, pad);
@@ -143,7 +153,6 @@ implements EventListener, OnClickListener, OnItemClickListener {
// Make the dividers the same colour as the background
Resources res = getResources();
int background = res.getColor(R.color.window_background);
list.setBackgroundColor(background);
list.setDivider(new ColorDrawable(background));
list.setDividerHeight(pad);
list.setAdapter(adapter);
@@ -224,21 +233,27 @@ implements EventListener, OnClickListener, OnItemClickListener {
private void displayHeaders(final Collection<MessageHeader> headers) {
runOnUiThread(new Runnable() {
public void run() {
list.setVisibility(VISIBLE);
loading.setVisibility(GONE);
sendButton.setEnabled(true);
adapter.clear();
for(MessageHeader h : headers) {
ConversationItem item = new ConversationItem(h);
byte[] body = bodyCache.get(h.getId());
if(body == null) loadMessageBody(h);
else item.setBody(body);
adapter.add(item);
if(headers.isEmpty()) {
empty.setVisibility(VISIBLE);
list.setVisibility(GONE);
} else {
empty.setVisibility(GONE);
list.setVisibility(VISIBLE);
for(MessageHeader h : headers) {
ConversationItem item = new ConversationItem(h);
byte[] body = bodyCache.get(h.getId());
if(body == null) loadMessageBody(h);
else item.setBody(body);
adapter.add(item);
}
adapter.sort(ConversationItemComparator.INSTANCE);
// Scroll to the bottom
list.setSelection(adapter.getCount() - 1);
}
adapter.sort(ConversationItemComparator.INSTANCE);
adapter.notifyDataSetChanged();
// Scroll to the bottom
list.setSelection(adapter.getCount() - 1);
}
});
}

View File

@@ -75,6 +75,7 @@ implements OnClickListener {
Intent i = getIntent();
contactName = i.getStringExtra("briar.CONTACT_NAME");
if(contactName == null) throw new IllegalStateException();
setTitle(contactName);
byte[] b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
if(b == null) throw new IllegalStateException();
localAuthorId = new AuthorId(b);
@@ -105,7 +106,6 @@ implements OnClickListener {
layout.setOrientation(VERTICAL);
ScrollView scrollView = new ScrollView(this);
// Give me all the width and all the unused height
scrollView.setLayoutParams(MATCH_WRAP_1);
LinearLayout message = new LinearLayout(this);