/soc/2012/michael/android: 573a66d6ed4e: added blist display to ...

Michael Zangl michael at soc.pidgin.im
Wed Jul 18 07:06:47 EDT 2012


Changeset: 573a66d6ed4ea21c4ffb86bd7d8974acf685b712
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-18 12:44 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/573a66d6ed4e

Description:

added blist display to testclient.

diffstat:

 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java   |    3 +-
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java |  141 ++++++++++
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java    |   35 ++
 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/GroupEntry.java   |   54 +++
 android/workspace/im.pidgin.libpurple/.project                                                              |    4 +-
 5 files changed, 234 insertions(+), 3 deletions(-)

diffs (286 lines):

diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java
@@ -6,6 +6,7 @@
 import im.pidgin.libpurple.testclient.about.AboutView;
 import im.pidgin.libpurple.testclient.account.AccountEditView;
 import im.pidgin.libpurple.testclient.accountlist.AccountListView;
+import im.pidgin.libpurple.testclient.blist.BlistView;
 import im.pidgin.libpurple.testclient.core.TestClientView;
 import im.pidgin.libpurple.testclient.core.ViewController;
 
@@ -115,7 +116,7 @@
 
 	@Override
 	public void displayBuddylist() {
-		// TODO Auto-generated method stub
+		showView(new BlistView(this));
 
 	}
 
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java
@@ -0,0 +1,141 @@
+package im.pidgin.libpurple.testclient.blist;
+
+import im.pidgin.libpurple.blist.PurpleBlist;
+import im.pidgin.libpurple.blist.PurpleBlistGroup;
+import im.pidgin.libpurple.blist.PurpleBlistNode;
+import im.pidgin.libpurple.blist.PurpleContact;
+import im.pidgin.libpurple.core.PurpleInstance;
+import im.pidgin.libpurple.testclient.R;
+import im.pidgin.libpurple.testclient.core.ViewController;
+
+import java.util.ArrayList;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+public class BlistAdapter extends BaseAdapter {
+
+	private static final int VIEW_GROUP = 0;
+	private static final int VIEW_CONTACT = 1;
+	private final ViewController viewController;
+	private final PurpleBlist blist;
+	private final ArrayList<GroupEntry> groups = new ArrayList<GroupEntry>();
+	private int count;
+
+	public BlistAdapter(ViewController viewController) {
+		this.viewController = viewController;
+		PurpleInstance instance = viewController.getPurple();
+		blist = instance.getBlist();
+		reloadGroups(blist.getRoot());
+		recomputeOffsets();
+	}
+
+	private void recomputeOffsets() {
+		int offset = 0;
+		for (int i = 0; i < groups.size(); i++) {
+			GroupEntry groupEntry = groups.get(i);
+			groupEntry.setOffset(offset);
+			offset++;
+			if (groupEntry.isExpanded()) {
+				offset += groupEntry.getContacts().size();
+			}
+		}
+		count = offset;
+	}
+
+	private void reloadGroups(PurpleBlistNode root) {
+		groups.clear();
+
+		if (root != null) {
+			addGroups(root);
+		}
+	}
+
+	private void addGroups(PurpleBlistNode node) {
+		if (node instanceof PurpleBlistGroup) {
+			groups.add(new GroupEntry((PurpleBlistGroup) node));
+		} else {
+			for (PurpleBlistNode child : node) {
+				addGroups(child);
+			}
+		}
+	}
+
+	private GroupEntry getGroup(int position) {
+		for (int i = 1; i < groups.size(); i++) {
+			if (position < groups.get(i).getOffset()) {
+				return groups.get(i - 1);
+			}
+		}
+		return groups.get(groups.size() - 1);
+	}
+
+	@Override
+	public int getCount() {
+		return count;
+	}
+
+	@Override
+	public Object getItem(int arg0) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public long getItemId(int arg0) {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public View getView(int position, View arg1, ViewGroup arg2) {
+		View view;
+		GroupEntry group = getGroup(position);
+		if (group.getOffset() != position) {
+			if (arg1 == null) {
+				view = viewController.getLayoutInflater().inflate(
+						R.layout.blistitem_contact, null);
+			} else {
+				view = arg1;
+			}
+
+			PurpleContact contact = group.getContacts().get(
+					position - group.getOffset() - 1);
+			TextView name = (TextView) view
+					.findViewById(R.id.blistitem_contact_name);
+			name.setText(contact.getAlias());
+		} else {
+			if (arg1 == null) {
+				view = viewController.getLayoutInflater().inflate(
+						R.layout.blistitem_group, null);
+			} else {
+				view = arg1;
+			}
+			
+			TextView name = (TextView) view
+					.findViewById(R.id.blistitem_group_name);
+			name.setText(group.getGroup().getName());
+			
+		}
+		return view;
+	}
+
+	@Override
+	public boolean hasStableIds() {
+		return false;
+	}
+
+	@Override
+	public int getViewTypeCount() {
+		return 2;
+	}
+
+	@Override
+	public int getItemViewType(int position) {
+		return getGroup(position).getOffset() == position ? VIEW_GROUP
+				: VIEW_CONTACT;
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java
@@ -0,0 +1,35 @@
+package im.pidgin.libpurple.testclient.blist;
+
+import im.pidgin.libpurple.testclient.R;
+import im.pidgin.libpurple.testclient.core.TestClientView;
+import im.pidgin.libpurple.testclient.core.ViewController;
+import android.view.View;
+import android.widget.ListView;
+
+public class BlistView implements TestClientView {
+
+	private final ViewController viewController;
+	private View view;
+
+	public BlistView(ViewController viewController) {
+		this.viewController = viewController;
+	}
+
+	@Override
+	public View createView() {
+		if (view == null) {
+			view = viewController.getLayoutInflater().inflate(R.layout.blist, null);
+			
+			ListView list = (ListView) view.findViewById(R.id.blist_list);
+			list.setAdapter(new BlistAdapter(viewController));
+		}
+		
+		return view;
+		
+	}
+
+	@Override
+	public void removed(View view) {		
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/GroupEntry.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/GroupEntry.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/GroupEntry.java
@@ -0,0 +1,54 @@
+package im.pidgin.libpurple.testclient.blist;
+
+import im.pidgin.libpurple.blist.PurpleBlistGroup;
+import im.pidgin.libpurple.blist.PurpleBlistNode;
+import im.pidgin.libpurple.blist.PurpleContact;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GroupEntry {
+	private int offset;
+	private boolean expanded = true;
+	private final PurpleBlistGroup group;
+	private final List<PurpleContact> contacts = new ArrayList<PurpleContact>();
+
+	public GroupEntry(PurpleBlistGroup group) {
+		this.group = group;
+		recomputeContacts();
+	}
+
+	public int getOffset() {
+		return offset;
+	}
+
+	public void setOffset(int offset) {
+		this.offset = offset;
+	}
+
+	public boolean isExpanded() {
+		return expanded;
+	}
+
+	public void setExpanded(boolean expanded) {
+		this.expanded = expanded;
+	}
+
+	public synchronized List<PurpleContact> getContacts() {
+		return contacts;
+	}
+
+	private synchronized void recomputeContacts() {
+		contacts.clear();
+		for (PurpleBlistNode node : getGroup()) {
+			if (node instanceof PurpleContact) {
+				contacts.add((PurpleContact) node);
+			}
+		}
+	}
+
+	public PurpleBlistGroup getGroup() {
+		return group;
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple/.project b/android/workspace/im.pidgin.libpurple/.project
--- a/android/workspace/im.pidgin.libpurple/.project
+++ b/android/workspace/im.pidgin.libpurple/.project
@@ -34,7 +34,7 @@
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.buildArguments</key>
-					<value></value>
+					<value>-j</value>
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.buildCommand</key>
@@ -42,7 +42,7 @@
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.buildLocation</key>
-					<value>${workspace_loc:/im.pidgin.libpurple/X86}</value>
+					<value>${workspace_loc:/im.pidgin.libpurple/Android}</value>
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>



More information about the Commits mailing list