Show our own devices in security view

This commit is contained in:
Sylvain Berfini 2019-06-27 16:14:13 +02:00
parent 3f7d43aa2a
commit 795bd0b04d
5 changed files with 75 additions and 108 deletions

View file

@ -18,6 +18,11 @@ Group changes to describe their impact on the project, as follows:
- Added sample application to help developpers getting started with our SDK - Added sample application to help developpers getting started with our SDK
- Added picture in picture feature if supported instead of video overlay - Added picture in picture feature if supported instead of video overlay
- Added camera preview as dialer's background on tablets - Added camera preview as dialer's background on tablets
- Contact section in the settings
## Changed
- Call statistics are now available for each call & conference
- Added our own devices in LIME encrypted chatrooms' security view
## [4.1.0] - 2019-05-03 ## [4.1.0] - 2019-05-03
@ -173,6 +178,3 @@ Group changes to describe their impact on the project, as follows:
- Crashes Android 6/7 at starting - Crashes Android 6/7 at starting
- Permissions issues - Permissions issues
- Layout of tablet views - Layout of tablet views
### Changed
- management of the view for displaying call statistics

View file

@ -157,9 +157,11 @@ public class ChatMessagesFragment extends Fragment
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) { if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
ParticipantDevice[] devices = ParticipantDevice[] devices =
mChatRoom.getParticipants()[0].getDevices(); mChatRoom.getParticipants()[0].getDevices();
if (devices.length == 1) { // Only start a call automatically if both ourselves and the remote
oneParticipantOneDevice = true; // have 1 device exactly, otherwise show devices list.
} oneParticipantOneDevice =
devices.length == 1
&& mChatRoom.getMe().getDevices().length == 1;
} }
if (LinphonePreferences.instance().isLimeSecurityPopupEnabled()) { if (LinphonePreferences.instance().isLimeSecurityPopupEnabled()) {

View file

@ -39,16 +39,13 @@ import org.linphone.views.ContactAvatar;
class DevicesAdapter extends BaseExpandableListAdapter { class DevicesAdapter extends BaseExpandableListAdapter {
private final Context mContext; private final Context mContext;
private List<Participant> mParticipants; private List<Participant> mParticipants;
private boolean mOnlyDisplayChildsAsGroups;
public DevicesAdapter(Context context) { public DevicesAdapter(Context context) {
mContext = context; mContext = context;
mParticipants = new ArrayList<>(); mParticipants = new ArrayList<>();
mOnlyDisplayChildsAsGroups = false;
} }
public void updateListItems(List<Participant> participants, boolean childsAsGroups) { public void updateListItems(List<Participant> participants) {
mOnlyDisplayChildsAsGroups = childsAsGroups;
mParticipants = participants; mParticipants = participants;
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -56,43 +53,9 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public View getGroupView( public View getGroupView(
int groupPosition, boolean isExpanded, View view, ViewGroup viewGroup) { int groupPosition, boolean isExpanded, View view, ViewGroup viewGroup) {
if (mOnlyDisplayChildsAsGroups) {
ParticipantDevice device = (ParticipantDevice) getGroup(groupPosition);
DeviceChildViewHolder holder = null;
if (view != null) {
Object possibleHolder = view.getTag();
if (possibleHolder instanceof DeviceChildViewHolder) {
holder = (DeviceChildViewHolder) possibleHolder;
}
} else {
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.chat_device_cell_as_group, viewGroup, false);
}
if (holder == null) {
holder = new DeviceChildViewHolder(view);
view.setTag(holder);
}
holder.deviceName.setText(device.getName());
ChatRoomSecurityLevel level = device.getSecurityLevel();
switch (level) {
case Safe:
holder.securityLevel.setImageResource(R.drawable.security_2_indicator);
break;
case Encrypted:
holder.securityLevel.setImageResource(R.drawable.security_1_indicator);
break;
case ClearText:
case Unsafe:
default:
holder.securityLevel.setImageResource(R.drawable.security_alert_indicator);
break;
}
} else {
Participant participant = (Participant) getGroup(groupPosition); Participant participant = (Participant) getGroup(groupPosition);
// Group position 0 is reserved for ME participant & devices
DeviceGroupViewHolder holder = null; DeviceGroupViewHolder holder = null;
if (view != null) { if (view != null) {
Object possibleHolder = view.getTag(); Object possibleHolder = view.getTag();
@ -152,7 +115,6 @@ class DevicesAdapter extends BaseExpandableListAdapter {
holder.groupExpander.setImageResource( holder.groupExpander.setImageResource(
isExpanded ? R.drawable.chevron_list_open : R.drawable.chevron_list_close); isExpanded ? R.drawable.chevron_list_open : R.drawable.chevron_list_close);
} }
}
return view; return view;
} }
@ -199,32 +161,27 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public int getGroupCount() { public int getGroupCount() {
if (mParticipants.isEmpty()) return 0; return mParticipants.size();
return mOnlyDisplayChildsAsGroups
? mParticipants.get(0).getDevices().length
: mParticipants.size();
} }
@Override @Override
public int getChildrenCount(int groupPosition) { public int getChildrenCount(int groupPosition) {
if (mParticipants.isEmpty()) return 0; if (groupPosition >= mParticipants.size()) return 0;
return mOnlyDisplayChildsAsGroups return mParticipants.get(groupPosition).getDevices().length;
? 0
: mParticipants.get(groupPosition).getDevices().length;
} }
@Override @Override
public Object getGroup(int groupPosition) { public Object getGroup(int groupPosition) {
if (mParticipants.isEmpty()) return null; if (groupPosition >= mParticipants.size()) return null;
return mOnlyDisplayChildsAsGroups return mParticipants.get(groupPosition);
? mParticipants.get(0).getDevices()[groupPosition]
: mParticipants.get(groupPosition);
} }
@Override @Override
public Object getChild(int groupPosition, int childPosition) { public Object getChild(int groupPosition, int childPosition) {
if (mParticipants.isEmpty()) return null; if (groupPosition >= mParticipants.size()) return null;
return mParticipants.get(groupPosition).getDevices()[childPosition]; ParticipantDevice[] devices = mParticipants.get(groupPosition).getDevices();
if (devices.length == 0 || childPosition >= devices.length) return null;
return devices[childPosition];
} }
@Override @Override

View file

@ -28,7 +28,7 @@ import android.widget.ExpandableListView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.Arrays; import java.util.ArrayList;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
@ -38,6 +38,7 @@ import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomCapabilities; import org.linphone.core.ChatRoomCapabilities;
import org.linphone.core.Core; import org.linphone.core.Core;
import org.linphone.core.Factory; import org.linphone.core.Factory;
import org.linphone.core.Participant;
import org.linphone.core.ParticipantDevice; import org.linphone.core.ParticipantDevice;
import org.linphone.utils.LinphoneUtils; import org.linphone.utils.LinphoneUtils;
@ -173,8 +174,13 @@ public class DevicesFragment extends Fragment {
} }
if (mRoom != null && mRoom.getNbParticipants() > 0) { if (mRoom != null && mRoom.getNbParticipants() > 0) {
mOnlyDisplayChilds = mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt()); ArrayList<Participant> participantLists = new ArrayList<>();
mAdapter.updateListItems(Arrays.asList(mRoom.getParticipants()), mOnlyDisplayChilds); // Group position 0 is reserved for ME participant & devices
participantLists.add(mRoom.getMe());
for (Participant participant : mRoom.getParticipants()) {
participantLists.add(participant);
}
mAdapter.updateListItems(participantLists);
} }
} }
} }