Determine post type

This commit is contained in:
Pierre 2018-01-28 21:13:45 +01:00
parent 0b2ecd0626
commit 9d1e294c9b
3 changed files with 55 additions and 0 deletions

View File

@ -16,6 +16,7 @@ public class Post {
private int userID;
private int post_time;
private String content;
private PostTypes type;
//Set and get the ID of the post
@ -56,5 +57,15 @@ public class Post {
public String getContent() {
return content;
}
//Set and get the type of the post
public void setType(PostTypes type) {
this.type = type;
}
public PostTypes getType() {
return type;
}
}

View File

@ -0,0 +1,27 @@
package org.communiquons.android.comunic.client.data.posts;
/**
* Posts types enum
*
* @author Pierre HUBERT
* Created by pierre on 1/28/18.
*/
public enum PostTypes {
/**
* Text post
*/
TEXT,
/**
* Image post
*/
IMAGE,
/**
* Unknown type
*/
UNKNOWN
}

View File

@ -2,6 +2,7 @@ package org.communiquons.android.comunic.client.data.posts;
import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import org.communiquons.android.comunic.client.api.APIRequest;
import org.communiquons.android.comunic.client.api.APIRequestParameters;
@ -86,6 +87,22 @@ public class PostsHelper {
post.setPost_time(json.getInt("post_time"));
post.setContent(json.getString("content"));
//Determine the type of the post
switch (json.getString("kind")){
case "text":
post.setType(PostTypes.TEXT);
break;
case "image":
post.setType(PostTypes.IMAGE);
break;
default:
post.setType(PostTypes.UNKNOWN);
}
return post;
}
}