From a77254d0982e95ece868342c6baedf882954e76f Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 14 Apr 2018 17:11:23 +0200 Subject: [PATCH] Hide create post button if the user is not allowed to create post. --- .../client/data/helpers/GetUsersHelper.java | 2 ++ .../client/data/models/AdvancedUserInfo.java | 19 +++++++++++++++++++ .../client/ui/fragments/UserPageFragment.java | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GetUsersHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GetUsersHelper.java index 2836884..d1a07b2 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GetUsersHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GetUsersHelper.java @@ -400,6 +400,8 @@ public class GetUsersHelper { //Get account creation time advancedUserInfo.setAccount_creation_time(userObject.getInt("account_creation_time")); + //Check if user can post text or this page or not + advancedUserInfo.setCanPostText(userObject.getBoolean("can_post_texts")); } catch (JSONException e){ e.printStackTrace(); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/AdvancedUserInfo.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/AdvancedUserInfo.java index 0a0c3a0..9e2d204 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/models/AdvancedUserInfo.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/AdvancedUserInfo.java @@ -12,6 +12,7 @@ public class AdvancedUserInfo extends UserInfo { //Private fields private int account_creation_time; private boolean accessForbidden = false; + private boolean canPostText; /** * Get the account creation time @@ -48,4 +49,22 @@ public class AdvancedUserInfo extends UserInfo { public void setAccessForbidden(boolean accessForbidden) { this.accessForbidden = accessForbidden; } + + /** + * Set whether the current user can post a text on this user page or not + * + * @param canPostText TRUE to allow / FALSE to deny + */ + public void setCanPostText(boolean canPostText) { + this.canPostText = canPostText; + } + + /** + * Check whether the user can post text on this user page + * + * @return TRUE : yes / FALSE no + */ + public boolean isCanPostText() { + return canPostText; + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java index 50e0763..328c27b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPageFragment.java @@ -260,6 +260,10 @@ public class UserPageFragment extends Fragment implements PostsCreateFormFragmen ImageLoadHelper.remove(user_image); ImageLoadHelper.load(getActivity(), userInfo.getAcountImageURL(), user_image); + //Check if the user can post text on this page + mCreatePostButton.setVisibility(userInfo.isCanPostText() ? View.VISIBLE : View.GONE); + + //Load the list of posts of the user load_posts(); }