mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 22:09:30 +00:00
Display groups posts
This commit is contained in:
parent
5ce499f688
commit
e111bec5f0
@ -125,6 +125,50 @@ public class PostsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of the posts of a group
|
||||||
|
*
|
||||||
|
* @param groupID The ID of the group to get the post from
|
||||||
|
* @return The list of posts / null in case of failure
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public PostsList get_group(int groupID){
|
||||||
|
return get_group(groupID, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of the posts of a group
|
||||||
|
*
|
||||||
|
* @param groupID The ID of the group to get the post from
|
||||||
|
* @param from The post to start from (-1 not to specify)
|
||||||
|
* @return The list of posts / null in case of failure
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public PostsList get_group(int groupID, int from){
|
||||||
|
|
||||||
|
//Perform a request on the API
|
||||||
|
APIRequest params = new APIRequest(mContext, "posts/get_group");
|
||||||
|
params.addInt("groupID", groupID);
|
||||||
|
|
||||||
|
if(from > -1)
|
||||||
|
params.addInt("startFrom", from);
|
||||||
|
|
||||||
|
//Perform the request
|
||||||
|
try {
|
||||||
|
|
||||||
|
//Make the request on the API
|
||||||
|
APIResponse response = new APIRequestHelper().exec(params);
|
||||||
|
|
||||||
|
//Get the list of posts and process it
|
||||||
|
JSONArray posts = response.getJSONArray();
|
||||||
|
return parse_json_posts_list(posts);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of latest posts of a user
|
* Get the list of latest posts of a user
|
||||||
*
|
*
|
||||||
@ -255,6 +299,10 @@ public class PostsHelper {
|
|||||||
req.addString("kind-page", "user");
|
req.addString("kind-page", "user");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GROUP_PAGE:
|
||||||
|
req.addString("kind-page", "group");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unsupported kind of page !");
|
throw new RuntimeException("Unsupported kind of page !");
|
||||||
}
|
}
|
||||||
|
@ -135,4 +135,33 @@ public class GroupInfo {
|
|||||||
|| getMembershipLevel() == GroupsMembershipLevels.MODERATOR
|
|| getMembershipLevel() == GroupsMembershipLevels.MODERATOR
|
||||||
|| getMembershipLevel() == GroupsMembershipLevels.MEMBER;
|
|| getMembershipLevel() == GroupsMembershipLevels.MEMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user is at least the moderator of a group
|
||||||
|
*
|
||||||
|
* @return TRUE if the user is at least a moderator of the group / FALSE else
|
||||||
|
*/
|
||||||
|
public boolean isAtLeastModerator(){
|
||||||
|
return getMembershipLevel() == GroupsMembershipLevels.ADMINISTRATOR
|
||||||
|
|| getMembershipLevel() == GroupsMembershipLevels.MODERATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current user can post texts on this group or not
|
||||||
|
*
|
||||||
|
* @return TRUE if the user can posts texts / FALSE else
|
||||||
|
*/
|
||||||
|
public boolean canPostTexts(){
|
||||||
|
|
||||||
|
//Posting texts on a group requires to be at least a member of it
|
||||||
|
if(!isAtLeastMember())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(getPostCreationLevel() == GroupPostsCreationLevel.MODERATORS && !isAtLeastModerator())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//If we get there, the user can certainly create posts
|
||||||
|
//on the group
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.asynctasks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
||||||
|
import org.communiquons.android.comunic.client.data.helpers.PostsHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get group posts safe async task
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public class GetGroupPostsTask extends SafeAsyncTask<Integer, Void, PostsList> {
|
||||||
|
|
||||||
|
public GetGroupPostsTask(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PostsList doInBackground(Integer... integers) {
|
||||||
|
PostsHelper helper = new PostsHelper(getContext());
|
||||||
|
PostsList list;
|
||||||
|
|
||||||
|
//Check if a start point has been specified
|
||||||
|
if(integers.length == 1)
|
||||||
|
list = helper.get_group(integers[0]);
|
||||||
|
else
|
||||||
|
list = helper.get_group(integers[0], integers[1]);
|
||||||
|
|
||||||
|
//Check if the list of posts could not be retrieved
|
||||||
|
if(list == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//Try to load related information
|
||||||
|
if(!helper.load_related_information(list))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//Success. Now return information
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,11 @@ public class PostsCreateFormFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
public static final int PAGE_TYPE_USER = 1;
|
public static final int PAGE_TYPE_USER = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page type : group page
|
||||||
|
*/
|
||||||
|
public static final int PAGE_TYPE_GROUP = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On post created interface
|
* On post created interface
|
||||||
*/
|
*/
|
||||||
@ -249,6 +254,9 @@ public class PostsCreateFormFragment extends Fragment {
|
|||||||
switch (getArguments().getInt(PAGE_TYPE_ARG)){
|
switch (getArguments().getInt(PAGE_TYPE_ARG)){
|
||||||
case PAGE_TYPE_USER:
|
case PAGE_TYPE_USER:
|
||||||
post.setPage_type(PageType.USER_PAGE);
|
post.setPage_type(PageType.USER_PAGE);
|
||||||
|
|
||||||
|
case PAGE_TYPE_GROUP:
|
||||||
|
post.setPage_type(PageType.GROUP_PAGE);
|
||||||
}
|
}
|
||||||
post.setPage_id(getArguments().getInt(PAGE_ID_ARG));
|
post.setPage_id(getArguments().getInt(PAGE_ID_ARG));
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import android.os.AsyncTask;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -140,9 +141,27 @@ public class GroupPageMainFragment extends AbstractGroupFragment {
|
|||||||
*/
|
*/
|
||||||
private void applyGroupInfo(){
|
private void applyGroupInfo(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Apply main group information
|
//Apply main group information
|
||||||
mGroupName.setText(mAdvancedGroupInfo.getDisplayName());
|
mGroupName.setText(mAdvancedGroupInfo.getDisplayName());
|
||||||
mGroupImage.setGroup(mAdvancedGroupInfo);
|
mGroupImage.setGroup(mAdvancedGroupInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Show posts list
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt(GroupsPostsFragment.ARGUMENT_GROUP_ID, mGroupID);
|
||||||
|
args.putBoolean(GroupsPostsFragment.ARGUMENT_CAN_CREATE_GROUPS,
|
||||||
|
mAdvancedGroupInfo.canPostTexts());
|
||||||
|
|
||||||
|
GroupsPostsFragment fragment = new GroupsPostsFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
|
||||||
|
FragmentTransaction transaction
|
||||||
|
= Objects.requireNonNull(getActivity()).getSupportFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.postsListTarget, fragment);
|
||||||
|
transaction.commit();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
package org.communiquons.android.comunic.client.ui.fragments.groups;
|
||||||
|
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.arrays.PostsList;
|
||||||
|
import org.communiquons.android.comunic.client.ui.asynctasks.GetGroupPostsTask;
|
||||||
|
import org.communiquons.android.comunic.client.ui.asynctasks.GetLatestPostsTask;
|
||||||
|
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
|
||||||
|
import org.communiquons.android.comunic.client.ui.fragments.AbstractPostsListFragment;
|
||||||
|
import org.communiquons.android.comunic.client.ui.fragments.PostsCreateFormFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group posts fragment
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public class GroupsPostsFragment extends AbstractPostsListFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug tag
|
||||||
|
*/
|
||||||
|
private static final String TAG = GroupsPostsFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundle arguments
|
||||||
|
*/
|
||||||
|
public static final String ARGUMENT_GROUP_ID = "group_id";
|
||||||
|
public static final String ARGUMENT_CAN_CREATE_GROUPS = "can_create_posts";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the current group
|
||||||
|
*/
|
||||||
|
private int mGroupID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether posts can be created by the user
|
||||||
|
*/
|
||||||
|
private boolean mCanCreatePosts;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
//Get target group ID
|
||||||
|
assert getArguments() != null;
|
||||||
|
mGroupID = getArguments().getInt(ARGUMENT_GROUP_ID);
|
||||||
|
mCanCreatePosts = getArguments().getBoolean(ARGUMENT_CAN_CREATE_GROUPS);
|
||||||
|
|
||||||
|
setDisplayPostsTarget(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
enablePostFormFragment(mCanCreatePosts);
|
||||||
|
if(mCanCreatePosts)
|
||||||
|
init_create_post_fragment(PostsCreateFormFragment.PAGE_TYPE_GROUP, mGroupID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadPosts() {
|
||||||
|
loadPosts(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadMorePosts(int last_post_id) {
|
||||||
|
loadPosts(last_post_id-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a list of posts
|
||||||
|
*
|
||||||
|
* @param last_post_id The id of latest post to start from. Set -1 to get the latest posts
|
||||||
|
*/
|
||||||
|
private void loadPosts(int last_post_id){
|
||||||
|
getTasksManager().unsetSpecificTasks(GetLatestPostsTask.class);
|
||||||
|
GetGroupPostsTask task = new GetGroupPostsTask(getActivity());
|
||||||
|
task.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<PostsList>() {
|
||||||
|
@Override
|
||||||
|
public void OnPostExecute(PostsList posts) {
|
||||||
|
onGotNewPosts(posts);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mGroupID, last_post_id);
|
||||||
|
getTasksManager().addTask(task);
|
||||||
|
}
|
||||||
|
}
|
@ -5,8 +5,8 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<FrameLayout
|
||||||
android:id="@+id/postsList"
|
android:id="@+id/postsListTarget"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
|
Loading…
Reference in New Issue
Block a user