diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index d968b0a..2dbd36f 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -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.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; @@ -755,4 +756,42 @@ public class MainActivity extends BaseActivity implements 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(); + + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/GroupsListAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/GroupsListAdapter.java index 038d545..de2dfa2 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/GroupsListAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/GroupsListAdapter.java @@ -10,7 +10,7 @@ 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.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.GroupMembershipStatusView; @@ -28,7 +28,7 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter { */ private ArrayList mList = new ArrayList<>(); - private OnGroupMembershipUpdateListener mOnGroupMembershipUpdateListener; + private OnGroupActionListener mOnGroupActionListener; public GroupsListAdapter(Context 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) { - this.mOnGroupMembershipUpdateListener = onGroupMembershipUpdateListener; + public void setOnGroupActionListener(OnGroupActionListener onGroupActionListener) { + this.mOnGroupActionListener = onGroupActionListener; } @Override @@ -74,7 +74,11 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter { /** * 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 TextView mGroupName; @@ -83,11 +87,13 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter { GroupHolder(@NonNull View itemView) { super(itemView); + itemView.setOnClickListener(this); + mGroupImageView = itemView.findViewById(R.id.groupImage); mGroupName = itemView.findViewById(R.id.groupName); mGroupMembershipStatus = itemView.findViewById(R.id.groupMembershipStatusView); - mGroupMembershipStatus.setOnGroupMembershipUpdateListener(mOnGroupMembershipUpdateListener); + mGroupMembershipStatus.setOnGroupMembershipUpdateListener(mOnGroupActionListener); } GroupInfo getGroup(int pos){ @@ -95,10 +101,16 @@ public class GroupsListAdapter extends BaseRecyclerViewAdapter { } void bind(int pos){ - GroupInfo groupInfo = getGroup(pos); - mGroupImageView.setGroup(groupInfo); - mGroupName.setText(groupInfo.getDisplayName()); - mGroupMembershipStatus.setGroup(groupInfo); + mGroupInfo = getGroup(pos); + mGroupImageView.setGroup(mGroupInfo); + mGroupName.setText(mGroupInfo.getDisplayName()); + mGroupMembershipStatus.setGroup(mGroupInfo); + } + + @Override + public void onClick(View v) { + if(v.equals(itemView)) + mOnGroupActionListener.onOpenGroup(mGroupInfo.getId()); } } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/GroupPageMainFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/GroupPageMainFragment.java new file mode 100644 index 0000000..e52028b --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/GroupPageMainFragment.java @@ -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"; + + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/UserGroupsFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/UserGroupsFragment.java index 133488d..f4b5bad 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/UserGroupsFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/groups/UserGroupsFragment.java @@ -8,6 +8,7 @@ import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.ArrayMap; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; 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.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.asynctasks.GetUserGroupsTask; 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.Objects; /** * User groups fragment * * @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 @@ -120,17 +129,17 @@ public class UserGroupsFragment extends AbstractGroupFragment { setProgressBarVisibility(false); - if(mGroupsAdapter == null) { - mGroupsAdapter = new GroupsListAdapter(getActivity()); - mGroupsView.setAdapter(mGroupsAdapter); - mGroupsView.setLayoutManager(new LinearLayoutManager(getActivity())); - mGroupsView.addItemDecoration(new DividerItemDecoration(getActivity(), - DividerItemDecoration.VERTICAL)); - } + mGroupsAdapter = new GroupsListAdapter(getActivity()); + + mGroupsView.setAdapter(mGroupsAdapter); + 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.notifyDataSetChanged(); @@ -160,4 +169,10 @@ public class UserGroupsFragment extends AbstractGroupFragment { private void setNoGroupNoticeVisibility(boolean visible){ 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); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/listeners/OnGroupActionListener.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/listeners/OnGroupActionListener.java new file mode 100644 index 0000000..e5036d9 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/listeners/OnGroupActionListener.java @@ -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); + +} diff --git a/app/src/main/res/layout/fragment_user_groups.xml b/app/src/main/res/layout/fragment_user_groups.xml index ea81bcf..6182574 100644 --- a/app/src/main/res/layout/fragment_user_groups.xml +++ b/app/src/main/res/layout/fragment_user_groups.xml @@ -6,8 +6,8 @@