Skip to content

Commit

Permalink
Update links and permission model parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
daohoangson committed Feb 24, 2017
1 parent 2972e2c commit 06b6afa
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 46 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/xfrocks/api/androiddemo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static boolean getFeatureConfirmSignInWithRemember() {
return BuildConfig.FEATURE_CONFIRM_SIGN_IN_WITH_REMEMBER > 0;
}

@SuppressWarnings("SameReturnValue")
public static int getFeatureAttachmentResize() {
return BuildConfig.FEATURE_ATTACHMENT_RESIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class ApiAttachment extends ApiModel {
@SerializedName("filename")
private String mFileName;

@Override
@SerializedName("links")
private Links mLinks;

public Integer getId() {
return mId;
}
Expand All @@ -19,8 +21,28 @@ public String getFileName() {
return mFileName;
}

public String getPermalink() {
if (mLinks == null) {
return null;
}

return mLinks.mPermalink;
}

public String getThumbnail() {
return getLink("thumbnail");
if (mLinks == null) {
return null;
}

return mLinks.mThumbnail;
}

@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("permalink")
String mPermalink;

@SerializedName("thumbnail")
String mThumbnail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public boolean isComplete() {
@SerializedName("first_message")
ApiConversationMessage mFirstMessage;

@SerializedName("links")
Links mLinks;

@SerializedName("permissions")
Permissions mPermissions;

@Override
public Integer getId() {
return mId;
Expand Down Expand Up @@ -65,14 +71,41 @@ public ApiDiscussionMessage getFirstMessage() {
return mFirstMessage;
}

@Override
public String getPermalink() {
if (mLinks == null) {
return null;
}

return mLinks.mPermalink;
}

@Override
public boolean canPostMessage() {
return checkPermission("reply");
if (mPermissions == null) {
return false;
}

Boolean permission = mPermissions.mPostMessage;
if (permission == null) {
return false;
}

return permission;
}

@Override
public boolean canUploadAttachment() {
return checkPermission("upload_attachment");
if (mPermissions == null) {
return false;
}

Boolean permission = mPermissions.mUploadAttachment;
if (permission == null) {
return false;
}

return permission;
}

@Override
Expand Down Expand Up @@ -112,4 +145,20 @@ public Api.Params getPostMessagesParams(String bodyPlainText, String attachmentH
.and(ApiConstants.URL_CONVERSATION_MESSAGES_PARAM_ATTACHMENT_HASH, attachmentHash)
.and(ApiConstants.PARAM_FIELDS_INCLUDE, "message_id");
}


@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("permalink")
String mPermalink;
}

@SuppressWarnings("unused")
static class Permissions extends ApiModel {
@SerializedName("reply")
Boolean mPostMessage;

@SerializedName("upload_attachment")
Boolean mUploadAttachment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ApiConversationMessage extends ApiDiscussionMessage {
@SerializedName("message_body_plain_text")
private String mBodyPlainText;

@SerializedName("links")
private Links mLinks;

@Override
public Integer getId() {
return mId;
Expand All @@ -36,7 +39,11 @@ public String getCreatorName() {

@Override
public String getCreatorAvatar() {
return getLink("creator_avatar");
if (mLinks == null) {
return null;
}

return mLinks.mCreatorAvatar;
}

@Override
Expand All @@ -48,4 +55,10 @@ public Integer getCreateDate() {
public String getBodyPlainText() {
return mBodyPlainText;
}

@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("creator_avatar")
String mCreatorAvatar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.xfrocks.api.androiddemo.common.Api;

abstract public class ApiDiscussion extends ApiModel {
abstract public Integer getId();

abstract public String getTitle();

abstract public String getCreatorName();
Expand All @@ -13,6 +15,8 @@ abstract public class ApiDiscussion extends ApiModel {

abstract public ApiDiscussionMessage getFirstMessage();

abstract public String getPermalink();

abstract public boolean canPostMessage();

abstract public boolean canUploadAttachment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ abstract public class ApiDiscussionMessage extends ApiModel {
@SerializedName("attachments")
private ApiAttachment[] mAttachments;

abstract public Integer getId();

abstract public Integer getCreatorUserId();

abstract public String getCreatorName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
package com.xfrocks.api.androiddemo.common.model;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.Map;

abstract public class ApiModel implements Serializable {

@SerializedName("links")
Map<String, String> mLinks;

@SerializedName("permissions")
Map<String, Boolean> mPermissions;

abstract public Integer getId();

public String getPermalink() {
return getLink("permalink");
}

public boolean isComplete() {
return true;
}

String getLink(String key) {
if (mLinks == null) {
return null;
}

return mLinks.get(key);
}

boolean checkPermission(String key) {
if (mPermissions == null) {
return false;
}

Boolean value = mPermissions.get(key);
if (value == null) {
return false;
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ApiPost extends ApiDiscussionMessage {
@SerializedName("post_body_plain_text")
private String mBodyPlainText;

@SerializedName("links")
private Links mLinks;

@Override
public Integer getId() {
return mId;
Expand All @@ -36,7 +39,11 @@ public String getCreatorName() {

@Override
public String getCreatorAvatar() {
return getLink("poster_avatar");
if (mLinks == null) {
return null;
}

return mLinks.mCreatorAvatar;
}

@Override
Expand All @@ -48,4 +55,10 @@ public Integer getCreateDate() {
public String getBodyPlainText() {
return mBodyPlainText;
}

@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("poster_avatar")
String mCreatorAvatar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public boolean isComplete() {
@SerializedName("first_post")
ApiPost mFirstMessage;

@SerializedName("links")
Links mLinks;

@SerializedName("permissions")
Permissions mPermissions;

@Override
public Integer getId() {
return mId;
Expand All @@ -54,7 +60,11 @@ public String getCreatorName() {

@Override
public String getCreatorAvatar() {
return getLink("first_poster_avatar");
if (mLinks == null) {
return null;
}

return mLinks.mCreatorAvatar;
}

@Override
Expand All @@ -67,14 +77,41 @@ public ApiDiscussionMessage getFirstMessage() {
return mFirstMessage;
}

@Override
public String getPermalink() {
if (mLinks == null) {
return null;
}

return mLinks.mPermalink;
}

@Override
public boolean canPostMessage() {
return checkPermission("post");
if (mPermissions == null) {
return false;
}

Boolean permission = mPermissions.mPostMessage;
if (permission == null) {
return false;
}

return permission;
}

@Override
public boolean canUploadAttachment() {
return checkPermission("upload_attachment");
if (mPermissions == null) {
return false;
}

Boolean permission = mPermissions.mUploadAttachment;
if (permission == null) {
return false;
}

return permission;
}

@Override
Expand Down Expand Up @@ -117,4 +154,22 @@ public Api.Params getPostMessagesParams(String bodyPlainText, String attachmentH
.and(ApiConstants.URL_POSTS_PARAM_ATTACHMENT_HASH, attachmentHash)
.and(ApiConstants.PARAM_FIELDS_INCLUDE, "post_id");
}

@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("first_poster_avatar")
String mCreatorAvatar;

@SerializedName("permalink")
String mPermalink;
}

@SuppressWarnings("unused")
static class Permissions extends ApiModel {
@SerializedName("post")
Boolean mPostMessage;

@SerializedName("upload_attachment")
Boolean mUploadAttachment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ApiUser extends ApiModel {
@SerializedName("user_dob_day")
private Integer mDobDay;

@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@SerializedName("associatable")
private Map<Integer, ApiUser> mAssociatable;

Expand All @@ -33,7 +34,9 @@ public class ApiUser extends ApiModel {
@SerializedName("extra_timestamp")
private long mExtraTimestamp;

@Override
@SerializedName("links")
private Links mLinks;

public Integer getId() {
return mId;
}
Expand Down Expand Up @@ -83,7 +86,16 @@ public long getExtraTimestamp() {
}

public String getAvatar() {
return getLink("avatar_big");
if (mLinks == null) {
return null;
}

return mLinks.mAvatar;
}

@SuppressWarnings("unused")
static class Links extends ApiModel {
@SerializedName("avatar_big")
String mAvatar;
}
}

0 comments on commit 06b6afa

Please sign in to comment.