mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Ready to implement group page.
This commit is contained in:
parent
820c68e2d2
commit
5861929aff
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<GroupInfo> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
|
||||
}
|
@ -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.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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -6,8 +6,8 @@
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/groups_list"
|
||||
android:layout_width="368dp"
|
||||
android:layout_height="551dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
|
Loading…
Reference in New Issue
Block a user