/soc/2012/michael/android: b8df7ab233d3: Added a click and long ...
Michael Zangl
michael at soc.pidgin.im
Tue Aug 7 07:23:38 EDT 2012
Changeset: b8df7ab233d33f7fe0bcbd2deaaed92bfb3db960
Author: Michael Zangl <michael at soc.pidgin.im>
Date: 2012-08-07 13:23 +0200
Branch: soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/b8df7ab233d3
Description:
Added a click and long click listener to the buddy list.
diffstat:
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/PurpleTestClient.java | 6 +-
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistAdapter.java | 17 +++-
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/blist/BlistView.java | 38 +++++++++-
android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java | 3 +-
4 files changed, 54 insertions(+), 10 deletions(-)
diffs (170 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
@@ -1,6 +1,7 @@
package im.pidgin.libpurple.testclient;
import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.buddy.PurpleBuddy;
import im.pidgin.libpurple.core.PurpleInstance;
import im.pidgin.libpurple.plugin.PurplePlugin;
import im.pidgin.libpurple.testclient.about.AboutView;
@@ -124,10 +125,11 @@ public class PurpleTestClient extends Ac
public void displayAddBuddyDialog() {
showView(new AddBuddyView(this));
}
-
+
@Override
- public void displayConversation() {
+ public void displayConversation(PurpleBuddy buddy) {
// TODO Auto-generated method stub
+
}
@Override
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
--- 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
@@ -28,7 +28,7 @@ public class BlistAdapter extends BaseAd
notifyDataSetChanged();
}
}
-
+
private final ViewController viewController;
private final PurpleBlist blist;
private final ArrayList<GroupEntry> groups = new ArrayList<GroupEntry>();
@@ -59,7 +59,6 @@ public class BlistAdapter extends BaseAd
private void reloadGroups(PurpleBlistNode root) {
groups.clear();
-
PurpleBlistNode current = root;
while (current != null) {
addGroups(current);
@@ -128,11 +127,11 @@ public class BlistAdapter extends BaseAd
} else {
view = arg1;
}
-
+
TextView name = (TextView) view
.findViewById(R.id.blistitem_group_name);
name.setText(group.getGroup().getName());
-
+
}
return view;
}
@@ -153,11 +152,19 @@ public class BlistAdapter extends BaseAd
: VIEW_CONTACT;
}
+ public PurpleBlistNode getNodeAt(int position) {
+ GroupEntry group = getGroup(position);
+ if (group.getOffset() == position) {
+ return group.getGroup();
+ } else {
+ return group.getContacts().get(position - group.getOffset() - 1);
+ }
+ }
private void notifyDataChangeAsync() {
viewController.runOnUiThread(new NotifyDataChanged());
}
-
+
@Override
public void nodeAdded(PurpleBlistNode node) {
notifyDataChangeAsync();
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
--- 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
@@ -1,17 +1,24 @@
package im.pidgin.libpurple.testclient.blist;
+import im.pidgin.libpurple.blist.PurpleBlistGroup;
+import im.pidgin.libpurple.blist.PurpleBlistNode;
+import im.pidgin.libpurple.buddy.PurpleBuddy;
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.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.ListView;
-public class BlistView implements TestClientView {
+public class BlistView implements TestClientView, OnItemLongClickListener, OnItemClickListener {
private final ViewController viewController;
private View view;
+ private BlistAdapter blistAdapter;
public BlistView(ViewController viewController) {
this.viewController = viewController;
@@ -23,7 +30,10 @@ public class BlistView implements TestCl
view = viewController.getLayoutInflater().inflate(R.layout.blist, null);
ListView list = (ListView) view.findViewById(R.id.blist_list);
- list.setAdapter(new BlistAdapter(viewController));
+ blistAdapter = new BlistAdapter(viewController);
+ list.setAdapter(blistAdapter);
+ list.setOnItemClickListener(this);
+ list.setOnItemLongClickListener(this);
Button newButton = (Button) view.findViewById(R.id.blist_new);
newButton.setOnClickListener(new OnClickListener() {
@@ -41,4 +51,28 @@ public class BlistView implements TestCl
public void removed(View view) {
}
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position,
+ long id) {
+ PurpleBlistNode node = blistAdapter.getNodeAt(position);
+ if (node instanceof PurpleBuddy) {
+ PurpleBuddy buddy = (PurpleBuddy) node;
+ viewController.displayConversation(buddy);
+ }
+ }
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ PurpleBlistNode node = blistAdapter.getNodeAt(position);
+ if (node instanceof PurpleBuddy) {
+ PurpleBuddy buddy = (PurpleBuddy) node;
+ /* TODO: buddy menu */
+ } else if (node instanceof PurpleBlistGroup) {
+ PurpleBlistGroup group = (PurpleBlistGroup) node;
+ /* TODO: group menu */
+ }
+ return false;
+ }
+
}
diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/core/ViewController.java
@@ -1,6 +1,7 @@
package im.pidgin.libpurple.testclient.core;
import im.pidgin.libpurple.account.PurpleAccount;
+import im.pidgin.libpurple.buddy.PurpleBuddy;
import im.pidgin.libpurple.core.PurpleInstance;
import android.content.res.Resources;
import android.view.LayoutInflater;
@@ -18,7 +19,7 @@ public interface ViewController {
void displayAddBuddyDialog();
- void displayConversation();
+ void displayConversation(PurpleBuddy buddy);
LayoutInflater getLayoutInflater();
More information about the Commits
mailing list