mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Display group name
This commit is contained in:
		@@ -11,6 +11,7 @@ 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.models.APIRequest;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.models.APIResponse;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.models.AdvancedGroupInfo;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
 | 
			
		||||
import org.json.JSONArray;
 | 
			
		||||
import org.json.JSONException;
 | 
			
		||||
@@ -161,6 +162,32 @@ public class GroupsHelper extends BaseHelper {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get advanced information about a group
 | 
			
		||||
     *
 | 
			
		||||
     * @param groupID Target group to get information about
 | 
			
		||||
     * @return Information about the group / null in case of failure
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public AdvancedGroupInfo getAdvancedInformation(int groupID){
 | 
			
		||||
        APIRequest request = new APIRequest(getContext(), "groups/get_advanced_info");
 | 
			
		||||
        request.addInt("id", groupID);
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
            //Execute request and get result
 | 
			
		||||
            JSONObject object = new APIRequestHelper().exec(request).getJSONObject();
 | 
			
		||||
            return parse_advanced_group_info(object);
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
 | 
			
		||||
            //Could not execute request
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send a group membership request
 | 
			
		||||
     *
 | 
			
		||||
@@ -225,30 +252,59 @@ public class GroupsHelper extends BaseHelper {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Overloaded method (see below)
 | 
			
		||||
     */
 | 
			
		||||
    private GroupInfo parse_group_info(@NonNull JSONObject object) throws JSONException {
 | 
			
		||||
        return parse_group_info(object, new GroupInfo());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Parse group information into GroupInfo object
 | 
			
		||||
     *
 | 
			
		||||
     * @param object The object to parse
 | 
			
		||||
     * @param group Group object to complete with group information
 | 
			
		||||
     * @return Generated group object
 | 
			
		||||
     * @throws JSONException In case of failure
 | 
			
		||||
     */
 | 
			
		||||
    private GroupInfo parse_group_info(@NonNull JSONObject object) throws JSONException {
 | 
			
		||||
    private GroupInfo parse_group_info(@NonNull JSONObject object, GroupInfo group) throws JSONException {
 | 
			
		||||
 | 
			
		||||
        GroupInfo info = new GroupInfo();
 | 
			
		||||
        group.setId(object.getInt("id"));
 | 
			
		||||
        group.setName(object.getString("name"));
 | 
			
		||||
        group.setIcon_url(object.getString("icon_url"));
 | 
			
		||||
        group.setNumber_members(object.getInt("number_members"));
 | 
			
		||||
        group.setMembershipLevel(parse_membership_level(object.getString("membership")));
 | 
			
		||||
        group.setVisibility(parse_group_visibility(object.getString("visibility")));
 | 
			
		||||
        group.setRegistrationLevel(parse_group_registration_level(object.getString("registration_level")));
 | 
			
		||||
        group.setPostCreationLevel(parse_post_creation_level(object.getString("posts_level")));
 | 
			
		||||
        group.setVirtualDirectory(object.getString("virtual_directory"));
 | 
			
		||||
        group.setFollowing(object.getBoolean("following"));
 | 
			
		||||
 | 
			
		||||
        info.setId(object.getInt("id"));
 | 
			
		||||
        info.setName(object.getString("name"));
 | 
			
		||||
        info.setIcon_url(object.getString("icon_url"));
 | 
			
		||||
        info.setNumber_members(object.getInt("number_members"));
 | 
			
		||||
        info.setMembershipLevel(parse_membership_level(object.getString("membership")));
 | 
			
		||||
        info.setVisibility(parse_group_visibility(object.getString("visibility")));
 | 
			
		||||
        info.setRegistrationLevel(parse_group_registration_level(object.getString("registration_level")));
 | 
			
		||||
        info.setPostCreationLevel(parse_post_creation_level(object.getString("posts_level")));
 | 
			
		||||
        info.setVirtualDirectory(object.getString("virtual_directory"));
 | 
			
		||||
        info.setFollowing(object.getBoolean("following"));
 | 
			
		||||
        return group;
 | 
			
		||||
 | 
			
		||||
        return info;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Parse advanced group information into AdvancedGroupInfo object
 | 
			
		||||
     *
 | 
			
		||||
     * @param object The object to parse
 | 
			
		||||
     * @return Generated group information object
 | 
			
		||||
     * @throws JSONException In case of failure
 | 
			
		||||
     */
 | 
			
		||||
    private AdvancedGroupInfo parse_advanced_group_info(@NonNull JSONObject object) throws JSONException {
 | 
			
		||||
 | 
			
		||||
        AdvancedGroupInfo group = new AdvancedGroupInfo();
 | 
			
		||||
 | 
			
		||||
        //Parse basic group information
 | 
			
		||||
        parse_group_info(object, group);
 | 
			
		||||
 | 
			
		||||
        group.setTime_create(object.getInt("time_create"));
 | 
			
		||||
        group.setUrl(object.getString("url"));
 | 
			
		||||
        group.setDescription(object.getString("description"));
 | 
			
		||||
        group.setNumber_likes(object.getInt("number_likes"));
 | 
			
		||||
        group.setIs_liking(object.getBoolean("is_liking"));
 | 
			
		||||
 | 
			
		||||
        return group;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,58 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.data.models;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Advanced group information
 | 
			
		||||
 *
 | 
			
		||||
 * Contains more information about group than GroupInfo
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
public class AdvancedGroupInfo extends GroupInfo {
 | 
			
		||||
 | 
			
		||||
    //Private fields
 | 
			
		||||
    private int time_create;
 | 
			
		||||
    private String url;
 | 
			
		||||
    private String description;
 | 
			
		||||
    private int number_likes;
 | 
			
		||||
    private boolean is_liking;
 | 
			
		||||
 | 
			
		||||
    public int getTime_create() {
 | 
			
		||||
        return time_create;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTime_create(int time_create) {
 | 
			
		||||
        this.time_create = time_create;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getUrl() {
 | 
			
		||||
        return url;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUrl(String url) {
 | 
			
		||||
        this.url = url;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getDescription() {
 | 
			
		||||
        return description;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDescription(String description) {
 | 
			
		||||
        this.description = description;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getNumber_likes() {
 | 
			
		||||
        return number_likes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNumber_likes(int number_likes) {
 | 
			
		||||
        this.number_likes = number_likes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isIs_liking() {
 | 
			
		||||
        return is_liking;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIs_liking(boolean is_liking) {
 | 
			
		||||
        this.is_liking = is_liking;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.ui.asynctasks;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.android.comunic.client.data.helpers.GroupsHelper;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.models.AdvancedGroupInfo;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This task is used to get a group advanced information
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
public class GetGroupAdvancedInfoTask extends SafeAsyncTask<Integer, Void, AdvancedGroupInfo> {
 | 
			
		||||
    public GetGroupAdvancedInfoTask(Context context) {
 | 
			
		||||
        super(context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected AdvancedGroupInfo doInBackground(Integer... integers) {
 | 
			
		||||
        return new GroupsHelper(getContext()).getAdvancedInformation(integers[0]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,23 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.ui.fragments.groups;
 | 
			
		||||
 | 
			
		||||
import android.app.AlertDialog;
 | 
			
		||||
import android.os.AsyncTask;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.support.annotation.NonNull;
 | 
			
		||||
import android.support.annotation.Nullable;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.android.comunic.client.R;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.models.AdvancedGroupInfo;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.asynctasks.GetGroupAdvancedInfoTask;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.views.GroupImageView;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Group main page
 | 
			
		||||
 *
 | 
			
		||||
@@ -17,5 +35,104 @@ public class GroupPageMainFragment extends AbstractGroupFragment {
 | 
			
		||||
     */
 | 
			
		||||
    public static final String ARGUMENT_GROUP_ID = "group_id";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Target group ID
 | 
			
		||||
     */
 | 
			
		||||
    private int mGroupID;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Target group advanced information
 | 
			
		||||
     */
 | 
			
		||||
    private AdvancedGroupInfo mAdvancedGroupInfo;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Loading dialog
 | 
			
		||||
     */
 | 
			
		||||
    private AlertDialog mLoadingDialog;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * UI views
 | 
			
		||||
     */
 | 
			
		||||
    private GroupImageView mGroupImage;
 | 
			
		||||
    private TextView mGroupName;
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 | 
			
		||||
        return inflater.inflate(R.layout.layout_group_main_page, container, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
 | 
			
		||||
        super.onViewCreated(view, savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        //Get views
 | 
			
		||||
        mGroupImage = view.findViewById(R.id.groupImageView);
 | 
			
		||||
        mGroupName = view.findViewById(R.id.groupName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onStart() {
 | 
			
		||||
        super.onStart();
 | 
			
		||||
 | 
			
		||||
        //Get group ID
 | 
			
		||||
        assert getArguments() != null;
 | 
			
		||||
        mGroupID = getArguments().getInt(ARGUMENT_GROUP_ID);
 | 
			
		||||
 | 
			
		||||
        if(mAdvancedGroupInfo == null)
 | 
			
		||||
            loadGroupInformation();
 | 
			
		||||
        else
 | 
			
		||||
            applyGroupInfo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Download group information
 | 
			
		||||
     */
 | 
			
		||||
    private void loadGroupInformation(){
 | 
			
		||||
 | 
			
		||||
        //Display a loading dialog
 | 
			
		||||
        mLoadingDialog = UiUtils.create_loading_dialog(getActivity());
 | 
			
		||||
 | 
			
		||||
        getTasksManager().unsetSpecificTasks(GetGroupAdvancedInfoTask.class);
 | 
			
		||||
 | 
			
		||||
        GetGroupAdvancedInfoTask task =  new GetGroupAdvancedInfoTask(getActivity());
 | 
			
		||||
        task.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<AdvancedGroupInfo>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void OnPostExecute(@Nullable AdvancedGroupInfo advancedGroupInfo) {
 | 
			
		||||
                onLoadGroupAdvancedInfoCallback(advancedGroupInfo);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mGroupID);
 | 
			
		||||
        getTasksManager().addTask(task);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get group advanced information callback
 | 
			
		||||
     *
 | 
			
		||||
     * @param info Information about the target group
 | 
			
		||||
     */
 | 
			
		||||
    private void onLoadGroupAdvancedInfoCallback(@Nullable AdvancedGroupInfo info){
 | 
			
		||||
 | 
			
		||||
        //Hide loading dialog
 | 
			
		||||
        mLoadingDialog.dismiss();
 | 
			
		||||
 | 
			
		||||
        if(info == null) {
 | 
			
		||||
            Toast.makeText(getActivity(), R.string.err_get_group_info, Toast.LENGTH_SHORT).show();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mAdvancedGroupInfo = info;
 | 
			
		||||
        applyGroupInfo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Apply previously downloaded group information
 | 
			
		||||
     */
 | 
			
		||||
    private void applyGroupInfo(){
 | 
			
		||||
 | 
			
		||||
        //Apply main group information
 | 
			
		||||
        mGroupName.setText(mAdvancedGroupInfo.getDisplayName());
 | 
			
		||||
        mGroupImage.setGroup(mAdvancedGroupInfo);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								app/src/main/res/layout/layout_group_main_page.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								app/src/main/res/layout/layout_group_main_page.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
<?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"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools">
 | 
			
		||||
 | 
			
		||||
    <android.support.v7.widget.RecyclerView
 | 
			
		||||
        android:id="@+id/postsList"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="0dp"
 | 
			
		||||
        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_toBottomOf="@+id/constraintLayout4"
 | 
			
		||||
        app:layout_constraintVertical_weight="1" />
 | 
			
		||||
 | 
			
		||||
    <android.support.constraint.ConstraintLayout
 | 
			
		||||
        android:id="@+id/constraintLayout4"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="30dp"
 | 
			
		||||
        android:background="@color/colorPrimary"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent">
 | 
			
		||||
 | 
			
		||||
        <org.communiquons.android.comunic.client.ui.views.GroupImageView
 | 
			
		||||
            android:id="@+id/groupImageView"
 | 
			
		||||
            android:layout_width="28dp"
 | 
			
		||||
            android:layout_height="28dp"
 | 
			
		||||
            android:layout_marginStart="8dp"
 | 
			
		||||
            app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
            app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
            app:layout_constraintTop_toTopOf="parent"
 | 
			
		||||
            app:srcCompat="@drawable/ic_friends" />
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            android:id="@+id/groupName"
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_marginBottom="8dp"
 | 
			
		||||
            android:layout_marginStart="8dp"
 | 
			
		||||
            android:layout_marginTop="8dp"
 | 
			
		||||
            tools:text="Group name"
 | 
			
		||||
            android:textColor="@android:color/white"
 | 
			
		||||
            app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
            app:layout_constraintStart_toEndOf="@+id/groupImageView"
 | 
			
		||||
            app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
    </android.support.constraint.ConstraintLayout>
 | 
			
		||||
</android.support.constraint.ConstraintLayout>
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<resources>
 | 
			
		||||
    <color name="colorPrimary">#3F51B5</color>
 | 
			
		||||
    <color name="colorPrimary">#3f51b5</color>
 | 
			
		||||
    <color name="colorPrimaryDark">#303F9F</color>
 | 
			
		||||
    <color name="colorAccent">#ff4081</color>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -311,4 +311,5 @@
 | 
			
		||||
    <string name="dialog_leave_group_cancel">Cancel</string>
 | 
			
		||||
    <string name="dialog_leave_group_confirm">Leave</string>
 | 
			
		||||
    <string name="err_update_group_membership">Could not update group membership!</string>
 | 
			
		||||
    <string name="err_get_group_info">Could not get group information!</string>
 | 
			
		||||
</resources>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user