Display posts visibility level.

This commit is contained in:
Pierre 2018-02-03 14:26:43 +01:00
parent 9b4ed6da7e
commit 9662015b3a
7 changed files with 100 additions and 0 deletions

View File

@ -17,6 +17,7 @@ public class Post {
private int post_time; private int post_time;
private String content; private String content;
private PostTypes type; private PostTypes type;
private PostVisibilityLevels visibilityLevel;
//Files specific //Files specific
private String file_path_url; private String file_path_url;
@ -70,6 +71,16 @@ public class Post {
return type; return type;
} }
//Set and get post visibility level
public void setVisibilityLevel(PostVisibilityLevels visibilityLevel) {
this.visibilityLevel = visibilityLevel;
}
public PostVisibilityLevels getVisibilityLevel() {
return visibilityLevel;
}
//Set and get file path url //Set and get file path url
public void setFile_path_url(String file_path_url) { public void setFile_path_url(String file_path_url) {
this.file_path_url = file_path_url; this.file_path_url = file_path_url;

View File

@ -0,0 +1,27 @@
package org.communiquons.android.comunic.client.data.posts;
/**
* Post visibility levels
*
* @author Pierre HUBERT
* Created by pierre on 2/3/18.
*/
public enum PostVisibilityLevels {
/**
* Public post
*/
PUBLIC,
/**
* Friends-visible post
*/
FRIENDS,
/**
* Private post
*/
PRIVATE
}

View File

@ -86,6 +86,24 @@ public class PostsHelper {
post.setPost_time(json.getInt("post_time")); post.setPost_time(json.getInt("post_time"));
post.setContent(json.getString("content")); post.setContent(json.getString("content"));
//Determine the visibility level of the post
switch (json.getString("visibility_level")){
case "public":
post.setVisibilityLevel(PostVisibilityLevels.PUBLIC);
break;
case "friends":
post.setVisibilityLevel(PostVisibilityLevels.FRIENDS);
break;
case "private":
default :
post.setVisibilityLevel(PostVisibilityLevels.PRIVATE);
break;
}
//Determine the type of the post //Determine the type of the post
switch (json.getString("kind")){ switch (json.getString("kind")){

View File

@ -88,13 +88,35 @@ public class PostsAdapter extends ArrayAdapter<Post>{
ImageLoadManager.load(getContext(), userInfo.getAcountImageURL(), userAccountImage); ImageLoadManager.load(getContext(), userInfo.getAcountImageURL(), userAccountImage);
} }
//Set post creation time //Set post creation time
((TextView) convertView.findViewById(R.id.post_creation_time)).setText(utils. ((TextView) convertView.findViewById(R.id.post_creation_time)).setText(utils.
timeToString(Utilities.time() - post.getPost_time())); timeToString(Utilities.time() - post.getPost_time()));
//Set post visibility level
TextView visibilityLevel = convertView.findViewById(R.id.post_visibility);
switch (post.getVisibilityLevel()){
case PUBLIC:
visibilityLevel.setText(R.string.post_visibility_public);
break;
case FRIENDS:
visibilityLevel.setText(R.string.post_visibility_friends);
break;
case PRIVATE:
default:
visibilityLevel.setText(R.string.post_visibility_private);
break;
}
//Set post content //Set post content
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
//Set post image (if any) //Set post image (if any)
ImageView postImage = convertView.findViewById(R.id.post_image); ImageView postImage = convertView.findViewById(R.id.post_image);
postImage.setVisibility(View.GONE); postImage.setVisibility(View.GONE);

View File

@ -44,6 +44,20 @@
</LinearLayout> </LinearLayout>
<!-- Separator -->
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<!-- Post visibility level -->
<TextView
android:id="@+id/post_visibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Public"
style="@style/PostVisibility"/>
</LinearLayout> </LinearLayout>

View File

@ -97,4 +97,7 @@
<string name="dialog_loading_msg">Loading…</string> <string name="dialog_loading_msg">Loading…</string>
<string name="navigation_bottom_user_item">User</string> <string name="navigation_bottom_user_item">User</string>
<string name="err_get_user_posts">Couldn\'t get user posts !</string> <string name="err_get_user_posts">Couldn\'t get user posts !</string>
<string name="post_visibility_public">public</string>
<string name="post_visibility_friends">friends</string>
<string name="post_visibility_private">private</string>
</resources> </resources>

View File

@ -51,6 +51,11 @@
<item name="android:paddingLeft">10dp</item> <item name="android:paddingLeft">10dp</item>
</style> </style>
<!-- Post visibility -->
<style name="PostVisibility">
<item name="android:paddingEnd">2dp</item>
</style>
<!-- Post content --> <!-- Post content -->
<style name="PostContent"> <style name="PostContent">
<item name="android:textAlignment">center</item> <item name="android:textAlignment">center</item>