mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-26 13:38:59 +00:00
Display group access denied page.
This commit is contained in:
parent
fcf31fdae1
commit
5ee02aea0a
@ -24,6 +24,11 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class GroupsHelper extends BaseHelper {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
*/
|
||||
private static final String TAG = GroupsHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Groups information cache
|
||||
*/
|
||||
@ -64,6 +69,28 @@ public class GroupsHelper extends BaseHelper {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get information about a single group
|
||||
*
|
||||
* @param groupID Target group ID
|
||||
* @param force Specify whether the request should be forced or not
|
||||
* @return null in case of failure / Group information else
|
||||
*/
|
||||
@Nullable
|
||||
public GroupInfo getInfoSingle(int groupID, boolean force){
|
||||
|
||||
//Prepare request
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ids.add(groupID);
|
||||
|
||||
//Execute request
|
||||
ArrayMap<Integer, GroupInfo> list = getInfoMultiple(ids, force);
|
||||
if(list == null || !list.containsKey(groupID))
|
||||
return null;
|
||||
|
||||
return list.get(groupID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about multiple groups
|
||||
*
|
||||
@ -172,11 +199,27 @@ public class GroupsHelper extends BaseHelper {
|
||||
public AdvancedGroupInfo getAdvancedInformation(int groupID){
|
||||
APIRequest request = new APIRequest(getContext(), "groups/get_advanced_info");
|
||||
request.addInt("id", groupID);
|
||||
request.setTryContinueOnError(true);
|
||||
|
||||
try {
|
||||
|
||||
//Execute request and get result
|
||||
JSONObject object = new APIRequestHelper().exec(request).getJSONObject();
|
||||
APIResponse response = new APIRequestHelper().exec(request);
|
||||
|
||||
if (response.getResponse_code() != 200) {
|
||||
if(response.getResponse_code() == 401){
|
||||
//Access was explicitly denied to the group
|
||||
AdvancedGroupInfo groupInfo = new AdvancedGroupInfo();
|
||||
groupInfo.setAccess_forbidden(true);
|
||||
return groupInfo;
|
||||
}
|
||||
|
||||
//Could not get group information
|
||||
return null;
|
||||
}
|
||||
|
||||
//Parse and return result
|
||||
JSONObject object = response.getJSONObject();
|
||||
return parse_advanced_group_info(object);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -10,12 +10,21 @@ package org.communiquons.android.comunic.client.data.models;
|
||||
public class AdvancedGroupInfo extends GroupInfo {
|
||||
|
||||
//Private fields
|
||||
private boolean access_forbidden = false;
|
||||
private int time_create;
|
||||
private String url;
|
||||
private String description;
|
||||
private int number_likes;
|
||||
private boolean is_liking;
|
||||
|
||||
public boolean isAccess_forbidden() {
|
||||
return access_forbidden;
|
||||
}
|
||||
|
||||
public void setAccess_forbidden(boolean access_forbidden) {
|
||||
this.access_forbidden = access_forbidden;
|
||||
}
|
||||
|
||||
public int getTime_create() {
|
||||
return time_create;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
@ -43,10 +44,12 @@ 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.GroupAccessDeniedFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.groups.GroupPageMainFragment;
|
||||
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.OnOpenGroupListener;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.onOpenUsersPageListener;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.onPostOpenListener;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.openConversationListener;
|
||||
@ -64,7 +67,7 @@ import static org.communiquons.android.comunic.client.ui.Constants.IntentRequest
|
||||
*/
|
||||
public class MainActivity extends BaseActivity implements
|
||||
openConversationListener, updateConversationListener, onOpenUsersPageListener,
|
||||
onPostOpenListener, NavigationBar.OnNavigationItemSelectedListener {
|
||||
onPostOpenListener, NavigationBar.OnNavigationItemSelectedListener, OnOpenGroupListener {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
@ -757,28 +760,13 @@ public class MainActivity extends BaseActivity implements
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the page of a group to be opened
|
||||
*
|
||||
* @param activity Current activity (MUST BE THIS ACTIVITY)
|
||||
* @param groupID Group ID to open
|
||||
*/
|
||||
public static void OpenGroup(@NonNull Activity activity, int groupID){
|
||||
|
||||
if(!(activity instanceof MainActivity))
|
||||
throw new RuntimeException("Specified activity is not an instance of MainActivity!");
|
||||
|
||||
((MainActivity)activity).openGroupPage(groupID);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open group page
|
||||
*
|
||||
* @param groupID The ID of the group to open
|
||||
*/
|
||||
private void openGroupPage(int groupID){
|
||||
|
||||
@Override
|
||||
public void onOpenGroup(int groupID) {
|
||||
//Specify fragment arguments
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(GroupPageMainFragment.ARGUMENT_GROUP_ID, groupID);
|
||||
@ -792,6 +780,26 @@ public class MainActivity extends BaseActivity implements
|
||||
transaction.addToBackStack(null);
|
||||
transaction.replace(R.id.main_fragment, fragment);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpenGroupAccessDenied(int groupID) {
|
||||
|
||||
//Add arguments
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(GroupAccessDeniedFragment.ARGUMENT_GROUP_ID, groupID);
|
||||
|
||||
//Create fragment
|
||||
Fragment fragment = new GroupAccessDeniedFragment();
|
||||
fragment.setArguments(args);
|
||||
|
||||
//Remove last transaction from list
|
||||
getSupportFragmentManager().popBackStackImmediate();
|
||||
|
||||
//Perform fragment transaction
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.addToBackStack(null);
|
||||
transaction.replace(R.id.main_fragment, fragment);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
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.GroupInfo;
|
||||
|
||||
public class GetGroupInfoTask extends SafeAsyncTask<Integer, Void, GroupInfo> {
|
||||
|
||||
public GetGroupInfoTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupInfo doInBackground(Integer... integers) {
|
||||
|
||||
//By default, we force the request
|
||||
return new GroupsHelper(getContext()).getInfoSingle(integers[0], true);
|
||||
|
||||
}
|
||||
}
|
@ -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.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.enums.GroupsMembershipLevels;
|
||||
import org.communiquons.android.comunic.client.data.models.GroupInfo;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.GetGroupInfoTask;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.OnOpenGroupListener;
|
||||
import org.communiquons.android.comunic.client.ui.views.GroupImageView;
|
||||
import org.communiquons.android.comunic.client.ui.views.GroupMembershipStatusView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Group access denied fragment
|
||||
*
|
||||
* This fragment appears when the user was explicitly denied
|
||||
* access to a group advanced information
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class GroupAccessDeniedFragment extends AbstractGroupFragment {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
*/
|
||||
private static final String TAG = GroupAccessDeniedFragment.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Mandatory argument to use this fragment : target group id
|
||||
*/
|
||||
public static final String ARGUMENT_GROUP_ID = "group_id";
|
||||
|
||||
/**
|
||||
* Current group ID
|
||||
*/
|
||||
private int mGroupID;
|
||||
|
||||
/**
|
||||
* Views
|
||||
*/
|
||||
private GroupImageView mGroupImageView;
|
||||
private TextView mGroupNameView;
|
||||
private GroupMembershipStatusView mGroupMembershipView;
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.layout_group_access_denied, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mGroupImageView = view.findViewById(R.id.groupImageView);
|
||||
mGroupNameView = view.findViewById(R.id.groupName);
|
||||
mGroupMembershipView = view.findViewById(R.id.groupMembershipStatusView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
assert getArguments() != null;
|
||||
mGroupID = getArguments().getInt(ARGUMENT_GROUP_ID);
|
||||
|
||||
getGroupInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupMembershipUpdated(boolean success, int groupID) {
|
||||
super.onGroupMembershipUpdated(success, groupID);
|
||||
getGroupInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return information about the group
|
||||
*/
|
||||
private void getGroupInfo(){
|
||||
|
||||
getTasksManager().unsetSpecificTasks(GetGroupInfoTask.class);
|
||||
|
||||
GetGroupInfoTask task = new GetGroupInfoTask(getActivity());
|
||||
task.setOnPostExecuteListener(new SafeAsyncTask.OnPostExecuteListener<GroupInfo>() {
|
||||
@Override
|
||||
public void OnPostExecute(GroupInfo groupInfo) {
|
||||
onGotGroupInfo(groupInfo);
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mGroupID);
|
||||
getTasksManager().addTask(task);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called once we have got group information
|
||||
*
|
||||
* @param info Information about the group
|
||||
*/
|
||||
private void onGotGroupInfo(@Nullable GroupInfo info){
|
||||
|
||||
//Check for errors
|
||||
if(info == null){
|
||||
Toast.makeText(getActivity(), R.string.err_get_group_info, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the user is now at least a member of the group
|
||||
if(info.getMembershipLevel() == GroupsMembershipLevels.MEMBER
|
||||
|| info.getMembershipLevel() == GroupsMembershipLevels.MODERATOR
|
||||
|| info.getMembershipLevel() == GroupsMembershipLevels.ADMINISTRATOR){
|
||||
|
||||
//Go back to the group
|
||||
Objects.requireNonNull(getActivity())
|
||||
.getSupportFragmentManager().popBackStack();
|
||||
((OnOpenGroupListener)getActivity()).onOpenGroup(info.getId());
|
||||
}
|
||||
|
||||
//Apply group information
|
||||
mGroupImageView.setGroup(info);
|
||||
mGroupNameView.setText(info.getDisplayName());
|
||||
mGroupMembershipView.setGroup(info);
|
||||
mGroupMembershipView.setOnGroupMembershipUpdateListener(this);
|
||||
}
|
||||
}
|
@ -15,9 +15,12 @@ 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.listeners.OnOpenGroupListener;
|
||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||
import org.communiquons.android.comunic.client.ui.views.GroupImageView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Group main page
|
||||
*
|
||||
@ -121,6 +124,13 @@ public class GroupPageMainFragment extends AbstractGroupFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if access to the group was denied
|
||||
if(info.isAccess_forbidden()){
|
||||
((OnOpenGroupListener) Objects.requireNonNull(getActivity()))
|
||||
.onOpenGroupAccessDenied(mGroupID);
|
||||
return;
|
||||
}
|
||||
|
||||
mAdvancedGroupInfo = info;
|
||||
applyGroupInfo();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ 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 org.communiquons.android.comunic.client.ui.listeners.OnGroupActionListener;
|
||||
import org.communiquons.android.comunic.client.ui.listeners.OnOpenGroupListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
@ -134,7 +135,7 @@ public class UserGroupsFragment extends AbstractGroupFragment implements OnGroup
|
||||
|
||||
mGroupsView.setAdapter(mGroupsAdapter);
|
||||
mGroupsView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mGroupsView.addItemDecoration(new DividerItemDecoration(getActivity(),
|
||||
mGroupsView.addItemDecoration(new DividerItemDecoration(Objects.requireNonNull(getActivity()),
|
||||
DividerItemDecoration.VERTICAL));
|
||||
|
||||
|
||||
@ -173,6 +174,12 @@ public class UserGroupsFragment extends AbstractGroupFragment implements OnGroup
|
||||
@Override
|
||||
public void onOpenGroup(int groupID) {
|
||||
Log.v(TAG, "Open group " + groupID);
|
||||
MainActivity.OpenGroup(Objects.requireNonNull(getActivity()), groupID);
|
||||
((OnOpenGroupListener)Objects.requireNonNull(getActivity())).onOpenGroup(groupID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpenGroupAccessDenied(int groupID) {
|
||||
((OnOpenGroupListener)Objects.requireNonNull(getActivity()))
|
||||
.onOpenGroupAccessDenied(groupID);
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,7 @@ package org.communiquons.android.comunic.client.ui.listeners;
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public interface OnGroupActionListener extends OnGroupMembershipUpdateListener {
|
||||
|
||||
/**
|
||||
* Open a group page
|
||||
*
|
||||
* @param groupID The ID of the group to open
|
||||
*/
|
||||
void onOpenGroup(int groupID);
|
||||
public interface OnGroupActionListener
|
||||
extends OnGroupMembershipUpdateListener, OnOpenGroupListener {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package org.communiquons.android.comunic.client.ui.listeners;
|
||||
|
||||
/**
|
||||
* This interface is implemented by all classes that have to relay
|
||||
* the opening of a group
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public interface OnOpenGroupListener {
|
||||
|
||||
/**
|
||||
* Open a group page
|
||||
*
|
||||
* @param groupID The ID of the group to open
|
||||
*/
|
||||
void onOpenGroup(int groupID);
|
||||
|
||||
/**
|
||||
* Open a group access denied fragment page
|
||||
*
|
||||
* @param groupID The ID of the group to open
|
||||
*/
|
||||
void onOpenGroupAccessDenied(int groupID);
|
||||
}
|
58
app/src/main/res/layout/layout_group_access_denied.xml
Normal file
58
app/src/main/res/layout/layout_group_access_denied.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?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="match_parent">
|
||||
|
||||
<org.communiquons.android.comunic.client.ui.views.GroupMembershipStatusView
|
||||
android:id="@+id/groupMembershipStatusView"
|
||||
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_toBottomOf="@+id/textView12" />
|
||||
|
||||
<org.communiquons.android.comunic.client.ui.views.GroupImageView
|
||||
android:id="@+id/groupImageView"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintEnd_toEndOf="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_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
tools:text="Group name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/groupImageView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/notice_group_access_denied"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/groupName" />
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -312,4 +312,5 @@
|
||||
<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>
|
||||
<string name="notice_group_access_denied">Access to the group denied.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user