diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/CreatePost.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/CreatePost.java new file mode 100644 index 0000000..929b37b --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/CreatePost.java @@ -0,0 +1,15 @@ +package org.communiquons.android.comunic.client.data.posts; + +/** + * This object extends the Post object in order to include all the required informations to + * create a new post + * + * @author Pierre HUBERT + * Created by pierre on 4/1/18. + */ + +public class CreatePost extends Post { + + + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PageType.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PageType.java new file mode 100644 index 0000000..cd5bebd --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PageType.java @@ -0,0 +1,17 @@ +package org.communiquons.android.comunic.client.data.posts; + +/** + * Page types + * + * @author Pierre HUBERT + * Created by pierre on 4/1/18. + */ + +public enum PageType { + + /** + * User page + */ + USER_PAGE + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java index f3dc06e..88a4413 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/Post.java @@ -9,7 +9,7 @@ import java.util.ArrayList; /** * Post model * - * This object contains the informations about a single post + * This object contains the information about a single post * * @author Pierre HUBERT * Created by pierre on 1/21/18. @@ -21,6 +21,8 @@ public class Post { private int id; private int userID; private int post_time; + private PageType page_type; + private int page_id; private String content; private PostTypes type; private PostVisibilityLevels visibilityLevel; @@ -61,6 +63,25 @@ public class Post { } + //Set and get the type of the page + void setPage_type(PageType page_type) { + this.page_type = page_type; + } + + public PageType getPage_type() { + return page_type; + } + + + //Get and set page id + void setPage_id(int page_id) { + this.page_id = page_id; + } + + public int getPage_id() { + return page_id; + } + //Set and get the content of the post public void setContent(String content) { this.content = content; diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java index 3642ce9..0c8bad5 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/posts/PostsHelper.java @@ -110,6 +110,15 @@ public class PostsHelper { post.setId(json.getInt("ID")); post.setUserID(json.getInt("userID")); post.setPost_time(json.getInt("post_time")); + + //Determine the type and the id of the page + if(json.getInt("user_page_id") != 0){ + //Set information about the user + post.setPage_type(PageType.USER_PAGE); + post.setPage_id(json.getInt("user_page_id")); + } + + post.setContent(json.getString("content")); post.setComments_list(CommentsHelper.parse_json_array(json.getJSONArray("comments"))); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsCreateFormFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsCreateFormFragment.java index bd8f64f..5f79617 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsCreateFormFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/PostsCreateFormFragment.java @@ -6,9 +6,15 @@ import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.posts.CreatePost; import org.communiquons.android.comunic.client.data.posts.Post; +import org.communiquons.android.comunic.client.data.posts.PostsHelper; /** * Posts creation form @@ -39,12 +45,53 @@ public class PostsCreateFormFragment extends Fragment { */ private OnPostCreated mOnPostCreated; + /** + * Post helper + */ + private PostsHelper mPostHelper; + + /** + * Submit form button + */ + private Button mSendButton; + + /** + * Post content + */ + private EditText mPostContent; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + //Initialize post helper + mPostHelper = new PostsHelper(getActivity()); + + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_post_create_form, container, false); } + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + //Get post text area + mPostContent = view.findViewById(R.id.new_post_content); + + //Get send button and makes it lives + mSendButton = view.findViewById(R.id.submit_create_post_form); + mSendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + submit_form(); + } + }); + } + /** * Set the on post created class to trigger when an event occur * @@ -54,6 +101,23 @@ public class PostsCreateFormFragment extends Fragment { this.mOnPostCreated = onPostCreated; } + /** + * Submit create post form + */ + private void submit_form(){ + + //Check if the content of the post is empty / too short + if(mPostContent.getText().length() < 5){ + Toast.makeText(getActivity(), R.string.err_post_content_too_short, + Toast.LENGTH_SHORT).show(); + return; + } + + //Create a post object and fill it with the required information + CreatePost post = new CreatePost(); + + } + /** * This interface is called when a post is created */ diff --git a/app/src/main/res/layout/post_create_form.xml b/app/src/main/res/layout/post_create_form.xml index 29b1f4b..0c8886d 100644 --- a/app/src/main/res/layout/post_create_form.xml +++ b/app/src/main/res/layout/post_create_form.xml @@ -15,6 +15,7 @@