mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-26 13:38:59 +00:00
Display the list of groups of the user
This commit is contained in:
parent
7fd4602091
commit
60fd6e75cc
@ -12,6 +12,7 @@ import org.communiquons.android.comunic.client.data.enums.GroupsMembershipLevels
|
||||
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -36,6 +37,31 @@ public class GroupsHelper extends BaseHelper {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of groups of the user
|
||||
*
|
||||
* @return The list of groups of the user / null in case of failure
|
||||
*/
|
||||
@Nullable
|
||||
public ArrayList<Integer> getUserList(){
|
||||
APIRequest request = new APIRequest(getContext(), "groups/get_my_list");
|
||||
|
||||
try {
|
||||
APIResponse response = new APIRequestHelper().exec(request);
|
||||
if(response.getResponse_code() != 200) return null;
|
||||
|
||||
JSONArray array = response.getJSONArray();
|
||||
ArrayList<Integer> list = new ArrayList<>();
|
||||
for (int i = 0; i < array.length(); i++)
|
||||
list.add(array.getInt(i));
|
||||
return list;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get information about multiple groups
|
||||
@ -45,12 +71,25 @@ public class GroupsHelper extends BaseHelper {
|
||||
*/
|
||||
@Nullable
|
||||
public ArrayMap<Integer, GroupInfo> getInfoMultiple(ArrayList<Integer> IDs){
|
||||
return getInfoMultiple(IDs, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about multiple groups
|
||||
*
|
||||
* @param IDs The ID of the target groups
|
||||
* @param force Specify whether the request has to be forced or not (if set to true, the cache
|
||||
* will be ignored)
|
||||
* @return Information about the related groups
|
||||
*/
|
||||
@Nullable
|
||||
public ArrayMap<Integer, GroupInfo> getInfoMultiple(ArrayList<Integer> IDs, boolean force){
|
||||
|
||||
//Process each group to check if its information are available in the cache or not
|
||||
ArrayList<Integer> toGet = new ArrayList<>();
|
||||
|
||||
for(int id : IDs){
|
||||
if(!mInfoCache.containsKey(id))
|
||||
if(!mInfoCache.containsKey(id) || force)
|
||||
toGet.add(id);
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ import org.communiquons.android.comunic.client.ui.fragments.LatestPostsFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.NotificationsFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.SinglePostFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.UpdateConversationFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.groups.UserGroupsFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.userpage.UserAccessDeniedFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.userpage.UserPageFragment;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.onOpenUsersPageListener;
|
||||
@ -234,6 +235,12 @@ public class MainActivity extends BaseActivity implements
|
||||
//Get action id
|
||||
int id = item.getItemId();
|
||||
|
||||
//Display user groups
|
||||
if(id == R.id.action_user_groups){
|
||||
openUserGroups();
|
||||
return true;
|
||||
}
|
||||
|
||||
//To search a user
|
||||
if (id == R.id.action_search_user) {
|
||||
searchUser();
|
||||
@ -714,6 +721,18 @@ public class MainActivity extends BaseActivity implements
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open user groups
|
||||
*/
|
||||
public void openUserGroups(){
|
||||
UserGroupsFragment userGroupsFragment = new UserGroupsFragment();
|
||||
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.replace(R.id.main_fragment, userGroupsFragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache database of the application
|
||||
*/
|
||||
|
@ -0,0 +1,85 @@
|
||||
package org.communiquons.android.comunic.client.ui.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
import org.communiquons.android.comunic.client.ui.views.GroupImageView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Groups list adapter
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class GroupsListAdapter extends BaseRecyclerViewAdapter {
|
||||
|
||||
/**
|
||||
* The list of groups
|
||||
*/
|
||||
private ArrayList<GroupInfo> mList = new ArrayList<>();
|
||||
|
||||
public GroupsListAdapter(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of groups
|
||||
*
|
||||
* @param List The list of groups
|
||||
*/
|
||||
public void setList(ArrayList<GroupInfo> List) {
|
||||
this.mList = List;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.viewholder_group, viewGroup, false);
|
||||
return new GroupHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
((GroupHolder)viewHolder).bind(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Single group holder class
|
||||
*/
|
||||
private class GroupHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private GroupImageView mGroupImageView;
|
||||
private TextView mGroupName;
|
||||
|
||||
GroupHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
mGroupImageView = itemView.findViewById(R.id.groupImage);
|
||||
mGroupName = itemView.findViewById(R.id.groupName);
|
||||
}
|
||||
|
||||
GroupInfo getGroup(int pos){
|
||||
return mList.get(pos);
|
||||
}
|
||||
|
||||
void bind(int pos){
|
||||
GroupInfo groupInfo = getGroup(pos);
|
||||
mGroupImageView.setGroup(groupInfo);
|
||||
mGroupName.setText(groupInfo.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package org.communiquons.android.comunic.client.ui.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.helpers.GroupsHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Get user groups AsyncTask
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class GetUserGroupsTask extends SafeAsyncTask<Void, Void, ArrayMap<Integer, GroupInfo>> {
|
||||
public GetUserGroupsTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ArrayMap<Integer, GroupInfo> doInBackground(Void... voids) {
|
||||
|
||||
GroupsHelper groupsHelper = new GroupsHelper(getContext());
|
||||
|
||||
ArrayList<Integer> groups = groupsHelper.getUserList();
|
||||
|
||||
if(groups == null)
|
||||
return null;
|
||||
|
||||
return groupsHelper.getInfoMultiple(groups, true);
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public abstract class AbstractFragment extends Fragment {
|
||||
*
|
||||
* @return The task manager
|
||||
*/
|
||||
SafeAsyncTasksManager getTasksManager() {
|
||||
public SafeAsyncTasksManager getTasksManager() {
|
||||
return mTasksManager;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package org.communiquons.android.comunic.client.ui.fragments.groups;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.AbstractFragment;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Base Group Fragment
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
abstract class AbstractGroupFragment extends AbstractFragment {
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
MainActivity.SetNavbarSelectedOption(Objects.requireNonNull(getActivity()),
|
||||
R.id.action_personal_page);
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
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.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.ArrayMap;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
import org.communiquons.android.comunic.client.ui.adapters.GroupsListAdapter;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.GetUserGroupsTask;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* User groups fragment
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class UserGroupsFragment extends AbstractGroupFragment {
|
||||
|
||||
/**
|
||||
* Views
|
||||
*/
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mGroupsView;
|
||||
|
||||
/**
|
||||
* User groups
|
||||
*/
|
||||
private ArrayMap<Integer, GroupInfo> mGroupsList;
|
||||
|
||||
/**
|
||||
* Groups adapter
|
||||
*/
|
||||
private GroupsListAdapter mGroupsAdapter;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_user_groups, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
//Get views
|
||||
mGroupsView = view.findViewById(R.id.groups_list);
|
||||
mProgressBar = view.findViewById(R.id.progressBar);
|
||||
|
||||
setProgressBarVisiblity(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if(mGroupsList == null)
|
||||
getGroupsList();
|
||||
else
|
||||
displayGroupsList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of groups of the user
|
||||
*/
|
||||
private void getGroupsList(){
|
||||
|
||||
setProgressBarVisiblity(true);
|
||||
|
||||
getTasksManager().unsetSpecificTasks(GetUserGroupsTask.class);
|
||||
GetUserGroupsTask getUserGroupsTask = new GetUserGroupsTask(getActivity());
|
||||
getUserGroupsTask.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<ArrayMap<Integer, GroupInfo>>() {
|
||||
@Override
|
||||
public void OnPostExecute(ArrayMap<Integer, GroupInfo> list) {
|
||||
getGroupsListCallback(list);
|
||||
}
|
||||
});
|
||||
getUserGroupsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
getTasksManager().addTask(getUserGroupsTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user groups callback
|
||||
*
|
||||
* @param list The list of groups of the user
|
||||
*/
|
||||
private void getGroupsListCallback(@Nullable ArrayMap<Integer, GroupInfo> list){
|
||||
|
||||
setProgressBarVisiblity(false);
|
||||
|
||||
if(list == null){
|
||||
Toast.makeText(getActivity(), R.string.err_get_user_groups, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
mGroupsList = list;
|
||||
displayGroupsList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the list of groups of the user
|
||||
*/
|
||||
private void displayGroupsList(){
|
||||
|
||||
setProgressBarVisiblity(false);
|
||||
|
||||
mGroupsAdapter = new GroupsListAdapter(getActivity());
|
||||
mGroupsAdapter.setList(new ArrayList<>(mGroupsList.values()));
|
||||
|
||||
mGroupsView.setAdapter(mGroupsAdapter);
|
||||
mGroupsView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mGroupsView.addItemDecoration(new DividerItemDecoration(getActivity(),
|
||||
DividerItemDecoration.VERTICAL));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update (set) progressbar visibility
|
||||
*
|
||||
* @param visible Visibility level of the progress bar
|
||||
*/
|
||||
private void setProgressBarVisiblity(boolean visible){
|
||||
mProgressBar.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package org.communiquons.android.comunic.client.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
|
||||
/**
|
||||
* Special view for group images
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class GroupImageView extends WebImageView {
|
||||
|
||||
public GroupImageView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public GroupImageView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public GroupImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
setDefaultDrawable(R.drawable.ic_friends);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new group to this view
|
||||
*
|
||||
* @param group The new group to set
|
||||
*/
|
||||
public void setGroup(GroupInfo group){
|
||||
loadURL(group.getIcon_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any group currently set in this view
|
||||
*/
|
||||
public void removeGroup(){
|
||||
removeImage();
|
||||
applyDefaultDrawable();
|
||||
}
|
||||
}
|
33
app/src/main/res/layout/fragment_user_groups.xml
Normal file
33
app/src/main/res/layout/fragment_user_groups.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/groups_list"
|
||||
android:layout_width="368dp"
|
||||
android:layout_height="551dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
32
app/src/main/res/layout/viewholder_group.xml
Normal file
32
app/src/main/res/layout/viewholder_group.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/groupName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
tools:text="Group Name"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintStart_toEndOf="@+id/groupImage"
|
||||
app:layout_constraintTop_toTopOf="@+id/groupImage" />
|
||||
|
||||
<org.communiquons.android.comunic.client.ui.views.GroupImageView
|
||||
android:id="@+id/groupImage"
|
||||
android:layout_width="@dimen/group_image_default_width"
|
||||
android:layout_height="@dimen/group_image_default_height"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_friends" />
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -2,6 +2,11 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!-- User groups -->
|
||||
<item
|
||||
android:id="@+id/action_user_groups"
|
||||
android:title="@string/action_user_groups"/>
|
||||
|
||||
<!-- Search user -->
|
||||
<item
|
||||
android:id="@+id/action_search_user"
|
||||
|
@ -14,6 +14,10 @@
|
||||
<dimen name="account_image_xsmall_width">16dp</dimen>
|
||||
<dimen name="account_image_xsmall_height">16dp</dimen>
|
||||
|
||||
<!-- Default size for a group image -->
|
||||
<dimen name="group_image_default_width">64dp</dimen>
|
||||
<dimen name="group_image_default_height">64dp</dimen>
|
||||
|
||||
<!-- Dimensions for the conversation list -->
|
||||
<dimen name="fragment_conversations_list_icon_width">20dp</dimen>
|
||||
<dimen name="fragment_conversations_list_icon_height">20dp</dimen>
|
||||
|
@ -296,4 +296,6 @@
|
||||
<string name="action_send_survey_response">Respond</string>
|
||||
<string name="err_cancel_response">Could not cancel your response to the survey!</string>
|
||||
<string name="err_respond_survey">Could not send response to the server!</string>
|
||||
<string name="action_user_groups">My groups</string>
|
||||
<string name="err_get_user_groups">Could not get the groups of the user!</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user