# HG changeset patch # User Jean-Manuel Da Silva # Date 1258306552 -3600 # Node ID da650185bf8bda3ff5944e9172c540be02e3d9cf # Parent 5e4b8b7908f6512000980512b8f6612d5718ad0a PrivacyListManagerAdapter implementation. diff -r 5e4b8b7908f6 -r da650185bf8b src/com/beem/project/beem/service/PrivacyListItem.java --- a/src/com/beem/project/beem/service/PrivacyListItem.java Sun Nov 15 02:28:42 2009 +0100 +++ b/src/com/beem/project/beem/service/PrivacyListItem.java Sun Nov 15 18:35:52 2009 +0100 @@ -3,11 +3,16 @@ import android.os.Parcel; import android.os.Parcelable; +/** + * A simplified version of the Smack PrivacyItem class. + * @author Jean-Manuel Da Silva + */ public class PrivacyListItem implements Parcelable { - private int mType; - private String mValue; - + /** + * Constructor. Needed to implements the Parcelable.Creator interface. Generates instances of PrivacyListItem from a + * Parcel. + */ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public PrivacyListItem createFromParcel(Parcel in) { return new PrivacyListItem(in); @@ -18,46 +23,87 @@ } }; + private int mType; + private String mValue; + + /** + * Constructor. + */ public PrivacyListItem() { } - public PrivacyListItem(Parcel in) { + /** + * Constructor. Generates instances of PrivacyListItem from a Parcel. + * @param in The Parcel used to initialize object's attributes. + */ + public PrivacyListItem(final Parcel in) { readFromParcel(in); } - public PrivacyListItem(int type, String value) { + /** + * Constructor. + * @param type The type of the item. + * @param value The value of the item. + */ + public PrivacyListItem(final int type, final String value) { mType = type; mValue = value; } + /** + * {@inheritDoc}. + */ @Override public int describeContents() { return 0; } + /** + * Initialize object's attributes from a Parcel. + * @param in The Parcel used to initialize object's attributes. + */ public void readFromParcel(Parcel in) { mType = in.readInt(); mValue = in.readString(); } + /** + * {@inheritDoc}. + */ @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mType); dest.writeString(mValue); } + /** + * PrivacyListItem type accessor. + * @return The type of the PrivacyListItem. + */ public int getType() { return mType; } + /** + * PrivacyListItem value accessor. + * @return The value of the PrivacyListItem. + */ public String getValue() { return mValue; } + /** + * PrivacyListItem type mutator. + * @param type The type of the PrivacyListItem. + */ public void setType(final int type) { mType = type; } + /** + * PrivacyListItem value mutator. + * @param value The value of the PrivacyListItem. + */ public void setValue(final String value) { mValue = value; } diff -r 5e4b8b7908f6 -r da650185bf8b src/com/beem/project/beem/service/PrivacyListManagerAdapter.java --- a/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Sun Nov 15 02:28:42 2009 +0100 +++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Sun Nov 15 18:35:52 2009 +0100 @@ -1,11 +1,16 @@ package com.beem.project.beem.service; +import java.util.ArrayList; import java.util.List; +import org.jivesoftware.smack.PrivacyList; import org.jivesoftware.smack.PrivacyListManager; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.PrivacyItem; import android.os.RemoteException; +import android.util.Log; import com.beem.project.beem.service.aidl.IPrivacyListManager; @@ -20,93 +25,150 @@ */ public static final String TAG = "PrivacyListManagerAdapter"; - private final PrivacyListManager mAdaptee; - private final XMPPConnection mConnection; + private final PrivacyListManager mPrivacyListManager; + private final XMPPConnection mXmppConnection; /** * Constructor. - * @param The XMPP connection that will be used by the PrivacyListManagerAdapter. + * @param connection The XMPP connection that will be used by the PrivacyListManagerAdapter. */ public PrivacyListManagerAdapter(final XMPPConnection connection) { - mConnection = connection; - mAdaptee = PrivacyListManager.getInstanceFor(mConnection); - } - - @Override - public void addPrivacyList(String listName) throws RemoteException { - // TODO Auto-generated method stub - + mXmppConnection = connection; + mPrivacyListManager = PrivacyListManager.getInstanceFor(mXmppConnection); } @Override public void blockUser(String listName, String jid) throws RemoteException { - // TODO Auto-generated method stub - } @Override public void createPrivacyList(String listName, List items) throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.createPrivacyList(listName, tranformPrivacyListItemsToPrivacyItems(items)); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public void declineActivePrivacyList() throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.declineActiveList(); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public void declineDefaultPrivacyList() throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.declineDefaultList(); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public void editPrivacyList(String listName, List items) throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.updatePrivacyList(listName, tranformPrivacyListItemsToPrivacyItems(items)); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public String getActivePrivacyList() throws RemoteException { - // TODO Auto-generated method stub + try { + PrivacyList activePrivacyList = mPrivacyListManager.getActiveList(); + return activePrivacyList.toString(); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } return null; } @Override - public void getBlockedGroupsByList(String listName, List blockedGroupsByList) throws RemoteException { - // TODO Auto-generated method stub - + public List getBlockedGroupsByList(String listName) throws RemoteException { + List blockedGroups = new ArrayList(); + try { + PrivacyList pL = mPrivacyListManager.getPrivacyList(listName); + for (PrivacyItem pI : pL.getItems()) { + if (pI.getType().equals(PrivacyItem.Type.group) && !pI.isAllow()) + blockedGroups.add(pI.getValue()); + } + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } + return blockedGroups; } @Override - public void getBlockedUsersByList(String listName, List blockedUsersByList) throws RemoteException { - // TODO Auto-generated method stub - + public List getBlockedUsersByList(String listName) throws RemoteException { + List blockedUsers = new ArrayList(); + try { + PrivacyList pL = mPrivacyListManager.getPrivacyList(listName); + for (PrivacyItem pI : pL.getItems()) { + if (pI.getType().equals(PrivacyItem.Type.jid) && !pI.isAllow()) + blockedUsers.add(pI.getValue()); + } + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } + return blockedUsers; } @Override public String getDefaultPrivacyList() throws RemoteException { - // TODO Auto-generated method stub + try { + PrivacyList defaultPrivacyList = mPrivacyListManager.getDefaultList(); + return defaultPrivacyList.toString(); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } return null; } @Override public void removePrivacyList(String listName) throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.deletePrivacyList(listName); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public void setActivePrivacyList(String listName) throws RemoteException { - // TODO Auto-generated method stub - + try { + mPrivacyListManager.setActiveListName(listName); + } catch (XMPPException e) { + Log.e(TAG, e.getMessage()); + } } @Override public void setDefaultPrivacyList(String listName) throws RemoteException { - // TODO Auto-generated method stub + try { + mPrivacyListManager.setDefaultListName(listName); + } catch (XMPPException e) { + e.getMessage(); + } + } + /** + * From a List of PrivacyListItem get a List of PrivacyItem. + * @param items The List of PrivacyListItem. + * @return A list of PrivacyItem. + */ + private List tranformPrivacyListItemsToPrivacyItems(List items) { + List rItems = new ArrayList(); + PrivacyItem.Type[] itemTypes = PrivacyItem.Type.values(); + + for (int i = 0; i < items.size(); i++) { + rItems.add(new PrivacyItem(itemTypes[items.get(i).getType()].name(), false, i)); + } + + return rItems; } } diff -r 5e4b8b7908f6 -r da650185bf8b src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl --- a/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl Sun Nov 15 02:28:42 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IPrivacyListManager.aidl Sun Nov 15 18:35:52 2009 +0100 @@ -5,8 +5,6 @@ interface IPrivacyListManager { void createPrivacyList(in String listName, in List items); - - void addPrivacyList(in String listName); void removePrivacyList(in String listName); @@ -26,8 +24,8 @@ void blockUser(in String listName, in String jid); - void getBlockedUsersByList(in String listName, out List blockedUsersByList); + List getBlockedUsersByList(in String listName); - void getBlockedGroupsByList(in String listName, out List blockedGroupsByList); + List getBlockedGroupsByList(in String listName); } \ No newline at end of file