Skip to content
This repository was archived by the owner on Aug 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Simple Facebook/src/com/sromku/simple/fb/entities/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -99,7 +99,7 @@ public String getGraphPath() {
private String mObjectId;
private String mPicture;
private Place mPlace;
// private Privacy mPrivacy;
private Privacy mPrivacy;
private List<Property> mProperties;
private Integer mShares;
private String mSource;
Expand Down Expand Up @@ -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<Property>() {
Expand Down Expand Up @@ -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
Expand Down
68 changes: 55 additions & 13 deletions Simple Facebook/src/com/sromku/simple/fb/entities/Privacy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> mAllowedUsers = new ArrayList<String>();
private ArrayList<String> mDeniedUsers = new ArrayList<String>();
private List<String> mAllowedUsers = new ArrayList<String>();
private List<String> mDeniedUsers = new ArrayList<String>();

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<String> getAllow() {
return mAllowedUsers;
}

public List<String> getDeny() {
return mDeniedUsers;
}

private Privacy(Builder builder) {
Expand All @@ -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) {
Expand All @@ -52,8 +94,8 @@ public static Privacy create(GraphObject graphObject) {

public static class Builder {
private PrivacySettings mPrivacySetting = null;
private ArrayList<String> mAllowedUsers = new ArrayList<String>();
private ArrayList<String> mDeniedUsers = new ArrayList<String>();
private List<String> mAllowedUsers = new ArrayList<String>();
private List<String> mDeniedUsers = new ArrayList<String>();

public Builder() {
}
Expand Down Expand Up @@ -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(), ","));
Expand All @@ -243,4 +285,4 @@ public String getJSONString() {

return jsonRepresentation.toString();
}
}
}