diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/PostsList.java b/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/PostsList.java index cef8984..4e46123 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/PostsList.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/arrays/PostsList.java @@ -3,7 +3,9 @@ package org.communiquons.android.comunic.client.data.arrays; import android.support.annotation.Nullable; import android.util.ArrayMap; +import org.communiquons.android.comunic.client.data.enums.PageType; import org.communiquons.android.comunic.client.data.models.Comment; +import org.communiquons.android.comunic.client.data.models.GroupInfo; import org.communiquons.android.comunic.client.data.models.Post; import org.communiquons.android.comunic.client.data.models.UserInfo; @@ -28,6 +30,11 @@ public class PostsList extends ArrayList { */ private ArrayMap mUsersInfo = new ArrayMap<>(); + /** + * Associated groups information + */ + private ArrayMap mGroupsInfo = new ArrayMap<>(); + /** * Get the IDs of the users who created the posts and their comments * @@ -44,6 +51,9 @@ public class PostsList extends ArrayList { if(!ids.contains(userID)) ids.add(userID); + if(post.getPage_type() == PageType.USER_PAGE && !ids.contains(post.getPage_id())) + ids.add(post.getPage_id()); + if(post.getComments_list() != null){ //Process the list of comments @@ -61,12 +71,28 @@ public class PostsList extends ArrayList { } + /** + * Get IDs of the related groups + * + * @return The list of IDs of related groups (may be an empty array) + */ + public ArrayList getGroupsId(){ + + ArrayList list = new ArrayList<>(); + + for (Post post : this){ + if(post.getPage_type() == PageType.GROUP_PAGE && !list.contains(post.getPage_id())) + list.add(post.getPage_id()); + } + + return list; + } + /** * Get associated user information * * @return Associated user information */ - @Nullable public ArrayMap getUsersInfo() { return mUsersInfo; } @@ -86,4 +112,31 @@ public class PostsList extends ArrayList { public boolean hasUsersInfo(){ return this.mUsersInfo != null; } + + /** + * Get related groups information + * + * @return Information about the groups + */ + public ArrayMap getGroupsInfo() { + return mGroupsInfo; + } + + /** + * Set groups information + * + * @param groupsInfo Information about related groups + */ + public void setGroupsInfo(ArrayMap groupsInfo) { + this.mGroupsInfo = groupsInfo; + } + + /** + * Check whether groups information have been set or not + * + * @return TRUE if information about groups have been set / FALSE else + */ + public boolean hasGroupsInfo(){ + return this.mGroupsInfo != null; + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java index 9c6f464..5b40b7b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/PostsHelper.java @@ -145,6 +145,7 @@ public class PostsHelper { public PostsList get_latest(int from) { //Perform a request on the API APIRequest params = new APIRequest(mContext, "posts/get_latest"); + params.addBoolean("include_groups", true); //Check if we have to start from a precise post if(from > 0) @@ -166,6 +167,23 @@ public class PostsHelper { } } + /** + * Load information related to a post + * + * @param list The list of posts to process + * @return TRUE if all the information have been successfully loaded / FALSE else + */ + public boolean load_related_information(@NonNull PostsList list){ + + //Get information about related users + list.setUsersInfo(new GetUsersHelper(mContext).getMultiple(list.getUsersId())); + + //Get information about related groups + list.setGroupsInfo(new GroupsHelper(mContext).getInfoMultiple(list.getGroupsId())); + + return list.hasUsersInfo() && list.hasGroupsInfo(); + } + /** * Intend to delete a post specified by its ID * diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/GroupInfo.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/GroupInfo.java index a72fc55..326575e 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/models/GroupInfo.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/GroupInfo.java @@ -6,6 +6,7 @@ import org.communiquons.android.comunic.client.data.enums.GroupRegistrationLevel import org.communiquons.android.comunic.client.data.enums.GroupVisibility; import org.communiquons.android.comunic.client.data.enums.GroupsMembershipLevels; import org.communiquons.android.comunic.client.data.enums.GroupPostsCreationLevel; +import org.communiquons.android.comunic.client.data.utils.Utilities; /** * Group information base model @@ -43,6 +44,13 @@ public class GroupInfo { this.name = name; } + /** + * @return The name of the group ready to be shown on a TextView + */ + public String getDisplayName(){ + return Utilities.prepareStringTextView(getName()); + } + public String getIcon_url() { return icon_url; } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java index db24682..a321dc5 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java @@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; -import android.util.ArrayMap; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -17,6 +16,7 @@ import android.widget.TextView; import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.data.arrays.PostsList; +import org.communiquons.android.comunic.client.data.enums.PageType; import org.communiquons.android.comunic.client.data.models.Comment; import org.communiquons.android.comunic.client.data.models.Post; import org.communiquons.android.comunic.client.data.models.UserInfo; @@ -64,9 +64,10 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { private PostsList mList; /** - * Information about the users + * Specify whether the posts target should be shown or not */ - private ArrayMap mUsersInfo; + private boolean mDisplayPostsTarget = true; + /** * Utilities object @@ -90,7 +91,6 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { super(context); mList = list; - mUsersInfo = list.getUsersInfo(); //Utilities mUtils = new Utilities(getContext()); @@ -98,6 +98,15 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mListener = listener; } + /** + * Specify whether the target of the posts should be shown or not + * + * @param displayPostsTarget TRUE to display posts target / FALSE else + */ + public void setDisplayPostsTarget(boolean displayPostsTarget) { + this.mDisplayPostsTarget = displayPostsTarget; + } + @Override public int getItemCount() { return mList.size(); @@ -161,6 +170,7 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { ((TextPostHolder)viewHolder).bind(position); } + /** * Text posts holder */ @@ -168,6 +178,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { private WebUserAccountImage mUserAccountImage; private TextView mUserAccountName; + private ImageView mPostTargetArrow; + private TextView mTargetPageName; private TextView mPostDate; private ImageView mPostVisibility; private ImageView mPostActions; @@ -184,6 +196,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mUserAccountImage = itemView.findViewById(R.id.user_account_image); mUserAccountName = itemView.findViewById(R.id.user_account_name); + mPostTargetArrow = itemView.findViewById(R.id.target_arrow); + mTargetPageName = itemView.findViewById(R.id.target_page_name); mPostDate = itemView.findViewById(R.id.post_creation_time); mPostVisibility = itemView.findViewById(R.id.post_visibility); mPostActions = itemView.findViewById(R.id.post_actions_btn); @@ -212,8 +226,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { Post post = getPost(position); UserInfo user = null; - if(mUsersInfo.containsKey(post.getUserID())) - user = mUsersInfo.get(post.getUserID()); + if(mList.getUsersInfo().containsKey(post.getUserID())) + user = mList.getUsersInfo().get(post.getUserID()); //Apply user information @@ -226,6 +240,40 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { mUserAccountName.setText(""); } + //Specify post target + setTargetNameVisibility(true); + + //Check if posts target has not to be shown + if(!mDisplayPostsTarget) + setTargetNameVisibility(false); + + //Do not display post target if the user who created the post created it on his page + else if(post.getPage_type() == PageType.USER_PAGE + && post.getPage_id() == post.getUserID()) + setTargetNameVisibility(false); + + //For user page + else if(post.getPage_type() == PageType.USER_PAGE + && mList.getUsersInfo().containsKey(post.getPage_id())){ + + mTargetPageName.setText(mList.getUsersInfo().get(post.getPage_id()) + .getDisplayFullName()); + + } + + //For group page + else if(post.getPage_type() == PageType.GROUP_PAGE + && mList.getGroupsInfo().containsKey(post.getPage_id())){ + + mTargetPageName.setText(mList.getGroupsInfo().get(post.getPage_id()) + .getDisplayName()); + + } + + //Information about user / group not found + else + setTargetNameVisibility(false); + //Post date mPostDate.setText(mUtils.timeToString(Utilities.time() - post.getPost_time())); @@ -292,8 +340,8 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { if(comment.isDeleted()) continue; - UserInfo commentUser = mUsersInfo.containsKey(comment.getUserID()) ? - mUsersInfo.get(comment.getUserID()) : null; + UserInfo commentUser = mList.getUsersInfo().containsKey(comment.getUserID()) ? + mList.getUsersInfo().get(comment.getUserID()) : null; View commentView = CommentsAdapter.getInflatedView(getContext(), comment, mListener, commentUser, mCommentsList); @@ -339,6 +387,11 @@ public class PostsAdapter extends BaseRecyclerViewAdapter { } } + private void setTargetNameVisibility(boolean visible){ + mPostTargetArrow.setVisibility(visible ? View.VISIBLE : View.GONE); + mTargetPageName.setVisibility(visible ? View.VISIBLE : View.GONE); + } + private void sendComment(){ mListener.onCreateComment(getLayoutPosition(), mSendCommentButton, getPost(getLayoutPosition()), mEditCommentContentView); diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetLatestPostsTask.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetLatestPostsTask.java index f802a4a..3a6f216 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetLatestPostsTask.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetLatestPostsTask.java @@ -21,13 +21,16 @@ public class GetLatestPostsTask extends SafeAsyncTask @Override protected PostsList doInBackground(Integer... integers) { + PostsHelper helper = new PostsHelper(getContext()); + //Get the list of posts int from = integers[0] == 0 ? -1 : integers[0]; - PostsList list = new PostsHelper(getContext()).get_latest(from); + PostsList list = helper.get_latest(from); if(list == null) return null; - list.setUsersInfo(new GetUsersHelper(getContext()).getMultiple(list.getUsersId())); - if(!list.hasUsersInfo()) return null; + //Load related information + if(!helper.load_related_information(list)) + return null; return list; } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetSinglePostTask.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetSinglePostTask.java index 705cccd..c793198 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetSinglePostTask.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/GetSinglePostTask.java @@ -22,13 +22,16 @@ public class GetSinglePostTask extends SafeAsyncTask { @Override protected PostsList doInBackground(Integer... integers) { - Post post = new PostsHelper(getContext()).getSingle(integers[0]); + PostsHelper helper = new PostsHelper(getContext()); + + Post post = helper.getSingle(integers[0]); if(post == null) return null; PostsList list = new PostsList(); list.add(post); - list.setUsersInfo(new GetUsersHelper(getContext()).getMultiple(list.getUsersId())); + if(!helper.load_related_information(list)) + return null; return list; } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/LoadUserPostsTask.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/LoadUserPostsTask.java index 7ea3925..05cf5c1 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/LoadUserPostsTask.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/asynctasks/LoadUserPostsTask.java @@ -31,16 +31,20 @@ public class LoadUserPostsTask extends SafeAsyncTask { @Override protected PostsList doInBackground(Integer ...integers) { + PostsHelper helper = new PostsHelper(getContext()); + PostsList list; if(integers.length == 0) - list = new PostsHelper(getContext()).get_user(mUserID); + list = helper.get_user(mUserID); else - list = new PostsHelper(getContext()).get_user(mUserID, integers[0]); + list = helper.get_user(mUserID, integers[0]); //Get associated user information, if possible - if(list != null) - list.setUsersInfo(new GetUsersHelper(getContext()).getMultiple(list.getUsersId())); + if(list == null) return null; + + if(!helper.load_related_information(list)) + return null; return list; } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/AbstractPostsListFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/AbstractPostsListFragment.java index 29cbd76..18bdf39 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/AbstractPostsListFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/AbstractPostsListFragment.java @@ -79,6 +79,11 @@ abstract class AbstractPostsListFragment extends Fragment */ private int MENU_ACTION = MENU_ACTION_NONE; + /** + * Specify whether posts target should be shown or not + */ + private boolean mDisplayPostsTarget = true; + /** * Current processed comment that context menu display actions for */ @@ -131,8 +136,7 @@ abstract class AbstractPostsListFragment extends Fragment /** * Arguments used to create post form */ - Bundle mCreateFormArgs; - + private Bundle mCreateFormArgs; @Nullable @Override @@ -256,12 +260,20 @@ abstract class AbstractPostsListFragment extends Fragment return; if(list == null){ - Toast.makeText(getActivity(), R.string.err_get_posts_list, Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), R.string.err_get_posts_list, + Toast.LENGTH_SHORT).show(); return; } if(!list.hasUsersInfo()){ - Toast.makeText(getActivity(), R.string.err_get_user_info, Toast.LENGTH_SHORT).show(); + Toast.makeText(getActivity(), R.string.err_get_user_info, + Toast.LENGTH_SHORT).show(); + return; + } + + if(!list.hasGroupsInfo()){ + Toast.makeText(getActivity(), R.string.err_get_related_groups_info, + Toast.LENGTH_SHORT).show(); return; } @@ -292,6 +304,7 @@ abstract class AbstractPostsListFragment extends Fragment //Create posts adapter (if required) if(mPostsAdapter == null) { mPostsAdapter = new PostsAdapter(getActivity(), mPostsList, this); + mPostsAdapter.setDisplayPostsTarget(mDisplayPostsTarget); //Connect the adapter to the view mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -319,6 +332,15 @@ abstract class AbstractPostsListFragment extends Fragment return getPostsList().get(getPostsList().size() - 1).getId(); } + /** + * Specify whether posts target should be shown or not + * + * @param displayPostsTarget TRUE to display / FALSE else + */ + protected void setDisplayPostsTarget(boolean displayPostsTarget) { + this.mDisplayPostsTarget = displayPostsTarget; + } + @Override public void onReachTop() { //Nothing diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPostsFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPostsFragment.java index d4176aa..cbf2249 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPostsFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/UserPostsFragment.java @@ -46,6 +46,8 @@ public class UserPostsFragment extends AbstractPostsListFragment { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setDisplayPostsTarget(false); + //Get arguments Bundle bundle = getArguments(); assert bundle != null; diff --git a/app/src/main/res/drawable/ic_play_arrow.xml b/app/src/main/res/drawable/ic_play_arrow.xml new file mode 100644 index 0000000..4eb0bd6 --- /dev/null +++ b/app/src/main/res/drawable/ic_play_arrow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index fa6b4ab..5320961 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -28,6 +28,27 @@ app:layout_constraintTop_toTopOf="parent" tools:text="User name" /> + + + + Une erreur a survenue lors de la mise à jour du contenu du message ! Veuillez réessayer… Le contenu du message a bien été mis à jour ! Une erreur a survenue lors de la récupération de posts plus anciens ! + Impossible de récupérer la liste de posts ! + Il n\'y a aucun post à afficher ici pour le moment. + Visiblité du post + Une erreur a survenue lors de la récupération d\'information sur les groupes liés ! \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2602993..a151bbe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -268,4 +268,5 @@ Could not get the list of posts! There is no post to display here yet. Post visibility + Could not get information about related groups! diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9a39607..3214ba5 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -93,6 +93,12 @@ bold + + +