Finished GroupInfoFragment RecyclerView implementation. TODO: ContactsListFragment and History conversion to RecyclerView.
This commit is contained in:
parent
d595653b12
commit
52cdc51847
4 changed files with 127 additions and 81 deletions
|
@ -173,7 +173,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/footer"/>
|
||||
|
||||
<!--<ListView-->
|
||||
<android.support.v7.widget.RecyclerView
|
||||
|
||||
android:id="@+id/chat_message_list"
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<ListView
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/chat_room_participants"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -107,7 +107,7 @@
|
|||
android:divider="@color/colorE"
|
||||
android:dividerHeight="1dp">
|
||||
|
||||
</ListView>
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/leaveGroupLayout"
|
||||
|
|
|
@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
package org.linphone.chat;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -32,117 +34,150 @@ import org.linphone.R;
|
|||
import org.linphone.activities.LinphoneActivity;
|
||||
import org.linphone.contacts.ContactAddress;
|
||||
import org.linphone.contacts.LinphoneContact;
|
||||
import org.linphone.contacts.SearchContactsListAdapter;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.Participant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupInfoAdapter extends BaseAdapter {
|
||||
public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.ViewHolder> {
|
||||
//public class GroupInfoAdapter extends BaseAdapter {
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder{
|
||||
public TextView name;
|
||||
public ImageView avatar;
|
||||
public ImageView delete;
|
||||
public LinearLayout isAdmin;
|
||||
public LinearLayout isNotAdmin;
|
||||
|
||||
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
name = view.findViewById(R.id.name);
|
||||
avatar = view.findViewById(R.id.contact_picture);
|
||||
delete = view.findViewById(R.id.delete);
|
||||
isAdmin = view.findViewById(R.id.isAdminLayout);
|
||||
isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private List<ContactAddress> mItems;
|
||||
private View.OnClickListener mDeleteListener;
|
||||
private boolean mHideAdminFeatures;
|
||||
private ChatRoom mChatRoom;
|
||||
public ImageView avatar;
|
||||
|
||||
|
||||
|
||||
public GroupInfoAdapter(LayoutInflater inflater, List<ContactAddress> items, boolean hideAdminFeatures, boolean isCreation) {
|
||||
mInflater = inflater;
|
||||
mItems = items;
|
||||
mHideAdminFeatures = hideAdminFeatures || isCreation;
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_infos_cell, parent, false);
|
||||
return new ViewHolder(v);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
|
||||
final ContactAddress ca = (ContactAddress)getItem(position);
|
||||
LinphoneContact c = ca.getContact();
|
||||
this.avatar=holder.avatar;
|
||||
holder.name.setText((c.getFullName() != null) ? c.getFullName() :
|
||||
(ca.getDisplayName() != null) ? ca.getDisplayName() : ca.getUsername());
|
||||
if (c.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), avatar, c.getThumbnailUri());
|
||||
}
|
||||
|
||||
holder.delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mDeleteListener != null) {
|
||||
mDeleteListener.onClick(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.delete.setTag(ca);
|
||||
|
||||
holder.isAdmin.setVisibility(ca.isAdmin() ? View.VISIBLE : View.GONE);
|
||||
holder.isNotAdmin.setVisibility(ca.isAdmin() ? View.GONE : View.VISIBLE);
|
||||
|
||||
holder.isAdmin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
holder.isNotAdmin.setVisibility(View.VISIBLE);
|
||||
holder.isAdmin.setVisibility(View.GONE);
|
||||
ca.setAdmin(false);
|
||||
}
|
||||
});
|
||||
|
||||
holder.isNotAdmin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
holder.isNotAdmin.setVisibility(View.GONE);
|
||||
holder.isAdmin.setVisibility(View.VISIBLE);
|
||||
ca.setAdmin(true);
|
||||
}
|
||||
});
|
||||
|
||||
holder.delete.setVisibility(View.VISIBLE);
|
||||
if (mHideAdminFeatures) {
|
||||
holder.delete.setVisibility(View.INVISIBLE);
|
||||
holder.isAdmin.setOnClickListener(null); // Do not allow not admin to remove it's rights but display admins
|
||||
holder.isNotAdmin.setVisibility(View.GONE); // Hide not admin button for not admin participants
|
||||
} else if (mChatRoom != null) {
|
||||
boolean found = false;
|
||||
for (Participant p : mChatRoom.getParticipants()) {
|
||||
if (p.getAddress().weakEqual(ca.getAddress())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
holder.isNotAdmin.setVisibility(View.GONE); // Hide not admin button for participant not yet added so even if user click it it won't have any effect
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
public void setChatRoom(ChatRoom room) {
|
||||
mChatRoom = room;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return mItems.get(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
if (view == null) {
|
||||
view = mInflater.inflate(R.layout.chat_infos_cell, null);
|
||||
}
|
||||
|
||||
final ContactAddress ca = (ContactAddress)getItem(i);
|
||||
LinphoneContact c = ca.getContact();
|
||||
|
||||
TextView name = view.findViewById(R.id.name);
|
||||
ImageView avatar = view.findViewById(R.id.contact_picture);
|
||||
ImageView delete = view.findViewById(R.id.delete);
|
||||
final LinearLayout isAdmin = view.findViewById(R.id.isAdminLayout);
|
||||
final LinearLayout isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
|
||||
|
||||
name.setText((c.getFullName() != null) ? c.getFullName() :
|
||||
(ca.getDisplayName() != null) ? ca.getDisplayName() : ca.getUsername());
|
||||
if (c.hasPhoto()) {
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), avatar, c.getThumbnailUri());
|
||||
}
|
||||
|
||||
delete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mDeleteListener != null) {
|
||||
mDeleteListener.onClick(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
delete.setTag(ca);
|
||||
|
||||
isAdmin.setVisibility(ca.isAdmin() ? View.VISIBLE : View.GONE);
|
||||
isNotAdmin.setVisibility(ca.isAdmin() ? View.GONE : View.VISIBLE);
|
||||
|
||||
isAdmin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isNotAdmin.setVisibility(View.VISIBLE);
|
||||
isAdmin.setVisibility(View.GONE);
|
||||
ca.setAdmin(false);
|
||||
}
|
||||
});
|
||||
|
||||
isNotAdmin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
isNotAdmin.setVisibility(View.GONE);
|
||||
isAdmin.setVisibility(View.VISIBLE);
|
||||
ca.setAdmin(true);
|
||||
}
|
||||
});
|
||||
|
||||
delete.setVisibility(View.VISIBLE);
|
||||
if (mHideAdminFeatures) {
|
||||
delete.setVisibility(View.INVISIBLE);
|
||||
isAdmin.setOnClickListener(null); // Do not allow not admin to remove it's rights but display admins
|
||||
isNotAdmin.setVisibility(View.GONE); // Hide not admin button for not admin participants
|
||||
} else if (mChatRoom != null) {
|
||||
boolean found = false;
|
||||
for (Participant p : mChatRoom.getParticipants()) {
|
||||
if (p.getAddress().weakEqual(ca.getAddress())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
isNotAdmin.setVisibility(View.GONE); // Hide not admin button for participant not yet added so even if user click it it won't have any effect
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setOnDeleteClickListener(View.OnClickListener onClickListener) {
|
||||
mDeleteListener = onClickListener;
|
||||
}
|
||||
|
@ -154,6 +189,6 @@ public class GroupInfoAdapter extends BaseAdapter {
|
|||
|
||||
public void setAdminFeaturesVisible(boolean visible) {
|
||||
mHideAdminFeatures = !visible;
|
||||
notifyDataSetInvalidated();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@ package org.linphone.chat;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -61,7 +64,9 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
|||
private Address mGroupChatRoomAddress;
|
||||
private EditText mSubjectField;
|
||||
private LayoutInflater mInflater;
|
||||
private ListView mParticipantsList;
|
||||
|
||||
private RecyclerView mParticipantsList;
|
||||
|
||||
private LinearLayout mLeaveGroupButton;
|
||||
private RelativeLayout mWaitLayout;
|
||||
private GroupInfoAdapter mAdapter;
|
||||
|
@ -73,6 +78,7 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
|||
private Dialog mAdminStateChangedDialog;
|
||||
private ChatRoomListenerStub mChatRoomCreationListener;
|
||||
private Bundle mShareInfos;
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -82,6 +88,8 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
|||
if (getArguments() == null || getArguments().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
this.mContext = getActivity().getApplicationContext();
|
||||
|
||||
mParticipants = (ArrayList<ContactAddress>) getArguments().getSerializable("ContactAddress");
|
||||
|
||||
mGroupChatRoomAddress = null;
|
||||
|
@ -118,6 +126,10 @@ public class GroupInfoFragment extends Fragment implements ChatRoomListener {
|
|||
});
|
||||
mParticipantsList.setAdapter(mAdapter);
|
||||
mAdapter.setChatRoom(mChatRoom);
|
||||
mParticipantsList.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
|
||||
|
||||
|
||||
|
||||
String fileSharedUri = getArguments().getString("fileSharedUri");
|
||||
String messageDraft = getArguments().getString("messageDraft");
|
||||
|
|
Loading…
Reference in a new issue