src/com/beem/project/beem/ui/PrivacyList.java
changeset 528 a77a7b4e7f34
parent 520 88a19fcd70b3
child 529 7964f04c2bf7
--- a/src/com/beem/project/beem/ui/PrivacyList.java	Tue Nov 17 00:29:37 2009 +0100
+++ b/src/com/beem/project/beem/ui/PrivacyList.java	Wed Nov 18 00:16:35 2009 +0100
@@ -20,8 +20,10 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.EditText;
+import android.widget.AdapterView.OnItemClickListener;
 
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
@@ -74,6 +76,12 @@
 	mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPrivacyListNames);
 	setListAdapter(mAdapter);
 
+	this.getListView().setOnItemClickListener(new OnItemClickListener() {
+	    @Override
+	    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+	    }
+	});
+
 	mPrivacyListListener = new PrivacyListListener();
 	mBroadcastReceiver = new BeemBroadcastReceiver(mConn);
 	this.registerReceiver(mBroadcastReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
@@ -90,6 +98,13 @@
 
 	Log.v(TAG, "BEGIN onDestroy.");
 	this.unregisterReceiver(mBroadcastReceiver);
+	if (mPrivacyListManager != null) {
+	    try {
+		mPrivacyListManager.removePrivacyListListener(mPrivacyListListener);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
+	}
 	Log.v(TAG, "END onDestroy.");
     }
 
@@ -157,14 +172,8 @@
 	    try {
 		mPrivacyListManager = mXmppFacade.getPrivacyListManager();
 		mPrivacyListManager.addPrivacyListListener(mPrivacyListListener);
-		/**
-		 * FIXME: ERROR /AndroidRuntime(21999): java.lang.ClassCastException:
-		 * org.jivesoftware.smack.PacketReader$4 ERROR/AndroidRuntime(21999): at
-		 * org.jivesoftware.smack.PrivacyListManager.getRequest(PrivacyListManager.java:189) at
-		 * org.jivesoftware.smack.PrivacyListManager.getPrivacyWithListNames(PrivacyListManager.java:254)
-		 */
-		// mPrivacyListNames = mPrivacyListManager.getPrivacyLists();
-		// mAdapter.notifyDataSetChanged();
+		mPrivacyListNames.addAll(mPrivacyListManager.getPrivacyLists());
+		mAdapter.notifyDataSetChanged();
 	    } catch (RemoteException e) {
 		Log.e(TAG, e.getMessage());
 	    }
@@ -176,6 +185,11 @@
 	    Log.v(TAG, "BEGIN onServiceDisconnected.");
 	    mXmppFacade = null;
 	    mBroadcastReceiver.setBinded(false);
+	    try {
+		mPrivacyListManager.removePrivacyListListener(mPrivacyListListener);
+	    } catch (RemoteException e) {
+		Log.e(TAG, e.getMessage());
+	    }
 	    Log.v(TAG, "END onServiceDisconnected.");
 	}
     }
@@ -185,14 +199,27 @@
 	@Override
 	public void setPrivacyList(String listName, List<PrivacyListItem> listItem) throws RemoteException {
 	    Log.d(TAG, "BEGIN PrivacyListListener >> setPrivacyList.");
-	    Log.d(TAG, listName);
+	    Log.d(TAG, "> " + listName + " has been setted.");
 	    Log.d(TAG, "END PrivacyListListener >> setPrivacyList.");
 	}
 
 	@Override
-	public void updatedPrivacyList(String listName) throws RemoteException {
+	public void updatedPrivacyList(final String listName) throws RemoteException {
 	    Log.d(TAG, "BEGIN PrivacyListListener >> updatedPrivacyList.");
-	    Log.d(TAG, listName);
+	    mHandler.post(new Runnable() {
+		@Override
+		public void run() {
+		    try {
+			mPrivacyListNames.clear();
+			// Not that much lists and require some server queries to know if the list has been
+			// updated/deleted or set to default/active by this activity or another IM client.
+			mPrivacyListNames.addAll(mPrivacyListManager.getPrivacyLists());
+		    } catch (RemoteException e) {
+			Log.e(TAG, e.getMessage());
+		    }
+		    mAdapter.notifyDataSetChanged();
+		}
+	    });
 	    Log.d(TAG, "END PrivacyListListener >> updatedPrivacyList.");
 	}
     }