diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Post.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Post.java index 0bbc6ee..e7b3aa6 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/entities/Post.java +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Post.java @@ -69,7 +69,7 @@ public String getGraphPath() { private static final String OBJECT_ID = "object_id"; private static final String PICTURE = "picture"; private static final String PLACE = "place"; - // private static final String PRIVACY = "privacy"; + private static final String PRIVACY = "privacy"; private static final String PROPERTIES = "properties"; private static final String SHARES = "shares"; private static final String SOURCE = "source"; @@ -99,7 +99,7 @@ public String getGraphPath() { private String mObjectId; private String mPicture; private Place mPlace; - // private Privacy mPrivacy; + private Privacy mPrivacy; private List mProperties; private Integer mShares; private String mSource; @@ -190,8 +190,7 @@ public InlineTag convert(GraphObject graphObject) { mPlace = Place.create(Utils.getPropertyGraphObject(graphObject, PLACE)); // privacy - // mPrivacy = Privacy.create(Utils.getPropertyGraphObject(graphObject, - // PRIVACY)); + mPrivacy = Privacy.create(Utils.getPropertyGraphObject(graphObject, PRIVACY)); // properties mProperties = Utils.createList(graphObject, PROPERTIES, new Converter() { @@ -381,9 +380,9 @@ public Place getPlace() { /** * The privacy settings of the Post. */ - // public Privacy getPrivacy() { - // return mPrivacy; - // } + public Privacy getPrivacy() { + return mPrivacy; + } /** * A list of properties for an uploaded video, for example, the length of diff --git a/Simple Facebook/src/com/sromku/simple/fb/entities/Privacy.java b/Simple Facebook/src/com/sromku/simple/fb/entities/Privacy.java index 4402158..4a9a8bf 100644 --- a/Simple Facebook/src/com/sromku/simple/fb/entities/Privacy.java +++ b/Simple Facebook/src/com/sromku/simple/fb/entities/Privacy.java @@ -1,7 +1,11 @@ package com.sromku.simple.fb.entities; +import android.text.TextUtils; + import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import org.json.JSONException; import org.json.JSONObject; @@ -19,21 +23,52 @@ */ public class Privacy { // private static final String DESCRIPTION = "description"; - private static final String PRIVACY = "value"; + private static final String VALUE = "value"; private static final String ALLOW = "allow"; private static final String DENY = "deny"; // private String mDescription; private PrivacySettings mPrivacySetting = null; - private ArrayList mAllowedUsers = new ArrayList(); - private ArrayList mDeniedUsers = new ArrayList(); + private List mAllowedUsers = new ArrayList(); + private List mDeniedUsers = new ArrayList(); public static enum PrivacySettings { - EVERYONE, - ALL_FRIENDS, - FRIENDS_OF_FRIENDS, - SELF, - CUSTOM + EVERYONE("EVERYONE"), + ALL_FRIENDS("ALL_FRIENDS"), + FRIENDS_OF_FRIENDS("FRIENDS_OF_FRIENDS"), + CUSTOM("CUSTOM"), + SELF("SELF"); + + private String value; + + private PrivacySettings(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static PrivacySettings fromValue(String value) { + for (PrivacySettings privacy : values()) { + if (privacy.value.equals(value)) return privacy; + } + return null; + } + } + + public String getValue() { + String value = ""; + if (mPrivacySetting != null) value = mPrivacySetting.getValue(); + return value; + } + + public List getAllow() { + return mAllowedUsers; + } + + public List getDeny() { + return mDeniedUsers; } private Privacy(Builder builder) { @@ -43,7 +78,14 @@ private Privacy(Builder builder) { } private Privacy(GraphObject graphObject) { - // not supported currently. It is used as output in 'Post' entity + String privacy = Utils.getPropertyString(graphObject, VALUE); + mPrivacySetting = PrivacySettings.fromValue(privacy); + + String allow = Utils.getPropertyString(graphObject, ALLOW); + if (!TextUtils.isEmpty(allow)) mAllowedUsers = Arrays.asList(allow.split(",")); + + String deny = Utils.getPropertyString(graphObject, DENY); + if (!TextUtils.isEmpty(deny)) mDeniedUsers = Arrays.asList(deny.split(",")); } public static Privacy create(GraphObject graphObject) { @@ -52,8 +94,8 @@ public static Privacy create(GraphObject graphObject) { public static class Builder { private PrivacySettings mPrivacySetting = null; - private ArrayList mAllowedUsers = new ArrayList(); - private ArrayList mDeniedUsers = new ArrayList(); + private List mAllowedUsers = new ArrayList(); + private List mDeniedUsers = new ArrayList(); public Builder() { } @@ -227,7 +269,7 @@ private void validateListsAccessRequest() { public String getJSONString() { JSONObject jsonRepresentation = new JSONObject(); try { - jsonRepresentation.put(PRIVACY, mPrivacySetting.name()); + jsonRepresentation.put(VALUE, mPrivacySetting.name()); if (mPrivacySetting == PrivacySettings.CUSTOM) { if (!mAllowedUsers.isEmpty()) { jsonRepresentation.put(ALLOW, Utils.join(mAllowedUsers.iterator(), ",")); @@ -243,4 +285,4 @@ public String getJSONString() { return jsonRepresentation.toString(); } -} \ No newline at end of file +}