mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Ready to implement post creation.
This commit is contained in:
parent
c9617b5b52
commit
870ed9443f
@ -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 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,7 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* Post model
|
* Post model
|
||||||
*
|
*
|
||||||
* This object contains the informations about a single post
|
* This object contains the information about a single post
|
||||||
*
|
*
|
||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
* Created by pierre on 1/21/18.
|
* Created by pierre on 1/21/18.
|
||||||
@ -21,6 +21,8 @@ public class Post {
|
|||||||
private int id;
|
private int id;
|
||||||
private int userID;
|
private int userID;
|
||||||
private int post_time;
|
private int post_time;
|
||||||
|
private PageType page_type;
|
||||||
|
private int page_id;
|
||||||
private String content;
|
private String content;
|
||||||
private PostTypes type;
|
private PostTypes type;
|
||||||
private PostVisibilityLevels visibilityLevel;
|
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
|
//Set and get the content of the post
|
||||||
public void setContent(String content) {
|
public void setContent(String content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
@ -110,6 +110,15 @@ public class PostsHelper {
|
|||||||
post.setId(json.getInt("ID"));
|
post.setId(json.getInt("ID"));
|
||||||
post.setUserID(json.getInt("userID"));
|
post.setUserID(json.getInt("userID"));
|
||||||
post.setPost_time(json.getInt("post_time"));
|
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.setContent(json.getString("content"));
|
||||||
post.setComments_list(CommentsHelper.parse_json_array(json.getJSONArray("comments")));
|
post.setComments_list(CommentsHelper.parse_json_array(json.getJSONArray("comments")));
|
||||||
|
|
||||||
|
@ -6,9 +6,15 @@ import android.support.annotation.Nullable;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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.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.Post;
|
||||||
|
import org.communiquons.android.comunic.client.data.posts.PostsHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts creation form
|
* Posts creation form
|
||||||
@ -39,12 +45,53 @@ public class PostsCreateFormFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private OnPostCreated mOnPostCreated;
|
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
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_post_create_form, container, false);
|
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
|
* Set the on post created class to trigger when an event occur
|
||||||
*
|
*
|
||||||
@ -54,6 +101,23 @@ public class PostsCreateFormFragment extends Fragment {
|
|||||||
this.mOnPostCreated = onPostCreated;
|
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
|
* This interface is called when a post is created
|
||||||
*/
|
*/
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
<!-- Submit post -->
|
<!-- Submit post -->
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/submit_create_post_form"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/post_action_send"
|
android:text="@string/post_action_send"
|
||||||
|
@ -122,4 +122,5 @@
|
|||||||
<string name="new_post_hint">New post…</string>
|
<string name="new_post_hint">New post…</string>
|
||||||
<string name="post_action_send">Send</string>
|
<string name="post_action_send">Send</string>
|
||||||
<string name="btn_show_create_form_description">Show / Hide create post form.</string>
|
<string name="btn_show_create_form_description">Show / Hide create post form.</string>
|
||||||
|
<string name="err_post_content_too_short">The content of the post is too short !</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user