Ready to implement group page.

This commit is contained in:
Pierre HUBERT 2018-11-24 22:38:05 +01:00
parent 820c68e2d2
commit 5861929aff
6 changed files with 127 additions and 23 deletions

View File

@ -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.NotificationsFragment;
import org.communiquons.android.comunic.client.ui.fragments.SinglePostFragment; 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.UpdateConversationFragment;
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.groups.UserGroupsFragment;
import org.communiquons.android.comunic.client.ui.fragments.userpage.UserAccessDeniedFragment; 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.fragments.userpage.UserPageFragment;
@ -755,4 +756,42 @@ public class MainActivity extends BaseActivity implements
startActivityForResult(intent, MAIN_ACTIVITY_SEARCH_USER_INTENT); startActivityForResult(intent, MAIN_ACTIVITY_SEARCH_USER_INTENT);
} }
/**
* 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){
//Specify fragment arguments
Bundle args = new Bundle();
args.putInt(GroupPageMainFragment.ARGUMENT_GROUP_ID, groupID);
//Initialize fragment
GroupPageMainFragment fragment = new GroupPageMainFragment();
fragment.setArguments(args);
//Perform fragment transaction
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.main_fragment, fragment);
transaction.commit();
}
} }

View File

@ -10,7 +10,7 @@ import android.widget.TextView;
import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.models.GroupInfo; import org.communiquons.android.comunic.client.data.models.GroupInfo;
import org.communiquons.android.comunic.client.ui.listeners.OnGroupMembershipUpdateListener; import org.communiquons.android.comunic.client.ui.listeners.OnGroupActionListener;
import org.communiquons.android.comunic.client.ui.views.GroupImageView; import org.communiquons.android.comunic.client.ui.views.GroupImageView;
import org.communiquons.android.comunic.client.ui.views.GroupMembershipStatusView; import org.communiquons.android.comunic.client.ui.views.GroupMembershipStatusView;
@ -28,7 +28,7 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter {
*/ */
private ArrayList<GroupInfo> mList = new ArrayList<>(); private ArrayList<GroupInfo> mList = new ArrayList<>();
private OnGroupMembershipUpdateListener mOnGroupMembershipUpdateListener; private OnGroupActionListener mOnGroupActionListener;
public GroupsListAdapter(Context context) { public GroupsListAdapter(Context context) {
super(context); super(context);
@ -44,12 +44,12 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter {
} }
/** /**
* Set the group membership update listener * Set the group action listener
* *
* @param onGroupMembershipUpdateListener The listener * @param onGroupActionListener The listener
*/ */
public void setOnGroupMembershipUpdateListener(OnGroupMembershipUpdateListener onGroupMembershipUpdateListener) { public void setOnGroupActionListener(OnGroupActionListener onGroupActionListener) {
this.mOnGroupMembershipUpdateListener = onGroupMembershipUpdateListener; this.mOnGroupActionListener = onGroupActionListener;
} }
@Override @Override
@ -74,7 +74,11 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter {
/** /**
* Single group holder class * Single group holder class
*/ */
private class GroupHolder extends RecyclerView.ViewHolder { private class GroupHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private GroupInfo mGroupInfo;
private GroupImageView mGroupImageView; private GroupImageView mGroupImageView;
private TextView mGroupName; private TextView mGroupName;
@ -83,11 +87,13 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter {
GroupHolder(@NonNull View itemView) { GroupHolder(@NonNull View itemView) {
super(itemView); super(itemView);
itemView.setOnClickListener(this);
mGroupImageView = itemView.findViewById(R.id.groupImage); mGroupImageView = itemView.findViewById(R.id.groupImage);
mGroupName = itemView.findViewById(R.id.groupName); mGroupName = itemView.findViewById(R.id.groupName);
mGroupMembershipStatus = itemView.findViewById(R.id.groupMembershipStatusView); mGroupMembershipStatus = itemView.findViewById(R.id.groupMembershipStatusView);
mGroupMembershipStatus.setOnGroupMembershipUpdateListener(mOnGroupMembershipUpdateListener); mGroupMembershipStatus.setOnGroupMembershipUpdateListener(mOnGroupActionListener);
} }
GroupInfo getGroup(int pos){ GroupInfo getGroup(int pos){
@ -95,10 +101,16 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter {
} }
void bind(int pos){ void bind(int pos){
GroupInfo groupInfo = getGroup(pos); mGroupInfo = getGroup(pos);
mGroupImageView.setGroup(groupInfo); mGroupImageView.setGroup(mGroupInfo);
mGroupName.setText(groupInfo.getDisplayName()); mGroupName.setText(mGroupInfo.getDisplayName());
mGroupMembershipStatus.setGroup(groupInfo); mGroupMembershipStatus.setGroup(mGroupInfo);
}
@Override
public void onClick(View v) {
if(v.equals(itemView))
mOnGroupActionListener.onOpenGroup(mGroupInfo.getId());
} }
} }
} }

View File

@ -0,0 +1,21 @@
package org.communiquons.android.comunic.client.ui.fragments.groups;
/**
* Group main page
*
* @author Pierre HUBERT
*/
public class GroupPageMainFragment extends AbstractGroupFragment {
/**
* Debug tag
*/
private static final String TAG = GroupPageMainFragment.class.getSimpleName();
/**
* Page arguments
*/
public static final String ARGUMENT_GROUP_ID = "group_id";
}

View File

@ -8,6 +8,7 @@ import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -17,18 +18,26 @@ import android.widget.Toast;
import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.models.GroupInfo; import org.communiquons.android.comunic.client.data.models.GroupInfo;
import org.communiquons.android.comunic.client.ui.activities.MainActivity;
import org.communiquons.android.comunic.client.ui.adapters.GroupsListAdapter; 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.GetUserGroupsTask;
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask; import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
import org.communiquons.android.comunic.client.ui.listeners.OnGroupActionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
/** /**
* User groups fragment * User groups fragment
* *
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
public class UserGroupsFragment extends AbstractGroupFragment { public class UserGroupsFragment extends AbstractGroupFragment implements OnGroupActionListener {
/**
* Debug tag
*/
private static final String TAG = UserGroupsFragment.class.getSimpleName();
/** /**
* Views * Views
@ -120,17 +129,17 @@ public class UserGroupsFragment extends AbstractGroupFragment {
setProgressBarVisibility(false); setProgressBarVisibility(false);
if(mGroupsAdapter == null) {
mGroupsAdapter = new GroupsListAdapter(getActivity());
mGroupsView.setAdapter(mGroupsAdapter); mGroupsAdapter = new GroupsListAdapter(getActivity());
mGroupsView.setLayoutManager(new LinearLayoutManager(getActivity()));
mGroupsView.addItemDecoration(new DividerItemDecoration(getActivity(), mGroupsView.setAdapter(mGroupsAdapter);
DividerItemDecoration.VERTICAL)); mGroupsView.setLayoutManager(new LinearLayoutManager(getActivity()));
} mGroupsView.addItemDecoration(new DividerItemDecoration(getActivity(),
DividerItemDecoration.VERTICAL));
mGroupsAdapter.setOnGroupMembershipUpdateListener(this);
mGroupsAdapter.setOnGroupActionListener(this);
mGroupsAdapter.setList(new ArrayList<>(mGroupsList.values())); mGroupsAdapter.setList(new ArrayList<>(mGroupsList.values()));
mGroupsAdapter.notifyDataSetChanged(); mGroupsAdapter.notifyDataSetChanged();
@ -160,4 +169,10 @@ public class UserGroupsFragment extends AbstractGroupFragment {
private void setNoGroupNoticeVisibility(boolean visible){ private void setNoGroupNoticeVisibility(boolean visible){
mNoGroupNotice.setVisibility(visible ? View.VISIBLE : View.GONE); mNoGroupNotice.setVisibility(visible ? View.VISIBLE : View.GONE);
} }
@Override
public void onOpenGroup(int groupID) {
Log.v(TAG, "Open group " + groupID);
MainActivity.OpenGroup(Objects.requireNonNull(getActivity()), groupID);
}
} }

View File

@ -0,0 +1,17 @@
package org.communiquons.android.comunic.client.ui.listeners;
/**
* Action on group listener
*
* @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);
}

View File

@ -6,8 +6,8 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/groups_list" android:id="@+id/groups_list"
android:layout_width="368dp" android:layout_width="match_parent"
android:layout_height="551dp" android:layout_height="match_parent"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"