From 7fe92e67acbad623c130263ff663507eb5eb9394 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 27 Nov 2018 13:52:24 +0100 Subject: [PATCH] Switch to enum --- .../talk/adapters/items/UserItem.java | 59 ++++++++++--------- .../CallNotificationController.java | 2 +- .../converters/ParticipantFlagsConverter.java | 38 ++++++++++++ .../models/json/participants/Participant.java | 41 ++++++++++++- 4 files changed, 109 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/converters/ParticipantFlagsConverter.java diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java index 703c4849b..ad0bb6b40 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java @@ -180,34 +180,37 @@ public class UserItem extends AbstractFlexibleItem Resources resources = NextcloudTalkApplication.getSharedApplication().getResources(); if (header == null) { - long participantFlags = participant.getParticipantFlags(); - if (participantFlags == 0) { - holder.voiceOrSimpleCallImageView.setVisibility(View.GONE); - holder.videoCallImageView.setVisibility(View.GONE); - } else if (participantFlags == 1) { - holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_call_bubble)); - holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); - holder.videoCallImageView.setVisibility(View.GONE); - } else if (participantFlags == 3) { - // with audio - holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_voice_bubble)); - holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); - holder.videoCallImageView.setVisibility(View.GONE); - } else if (participantFlags == 5) { - // with video - holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_call_bubble)); - holder.videoCallImageView.setBackground(resources.getDrawable(R.drawable.shape_video_bubble)); - holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); - holder.videoCallImageView.setVisibility(View.VISIBLE); - } else if (participantFlags == 7) { - // video and audio - holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_voice_bubble)); - holder.videoCallImageView.setBackground(resources.getDrawable(R.drawable.shape_video_bubble)); - holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); - holder.videoCallImageView.setVisibility(View.VISIBLE); - } else { - holder.voiceOrSimpleCallImageView.setVisibility(View.GONE); - holder.videoCallImageView.setVisibility(View.GONE); + Participant.ParticipantFlags participantFlags = participant.getParticipantFlags(); + switch (participantFlags) { + case NOT_IN_CALL: + holder.voiceOrSimpleCallImageView.setVisibility(View.GONE); + holder.videoCallImageView.setVisibility(View.GONE); + break; + case IN_CALL: + holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_call_bubble)); + holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); + holder.videoCallImageView.setVisibility(View.GONE); + break; + case IN_CALL_WITH_AUDIO: + holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_voice_bubble)); + holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); + holder.videoCallImageView.setVisibility(View.GONE); + break; + case IN_CALL_WITH_VIDEO: + holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_call_bubble)); + holder.videoCallImageView.setBackground(resources.getDrawable(R.drawable.shape_video_bubble)); + holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); + holder.videoCallImageView.setVisibility(View.VISIBLE); + break; + case IN_CALL_WITH_AUDIO_AND_VIDEO: + holder.voiceOrSimpleCallImageView.setBackground(resources.getDrawable(R.drawable.shape_voice_bubble)); + holder.videoCallImageView.setBackground(resources.getDrawable(R.drawable.shape_video_bubble)); + holder.voiceOrSimpleCallImageView.setVisibility(View.VISIBLE); + holder.videoCallImageView.setVisibility(View.VISIBLE); + break; + default: + holder.voiceOrSimpleCallImageView.setVisibility(View.GONE); + holder.videoCallImageView.setVisibility(View.GONE); } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java index 5abe89da7..f3c01da74 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java @@ -216,7 +216,7 @@ public class CallNotificationController extends BaseController { boolean inCallOnDifferentDevice = false; List participantList = participantsOverall.getOcs().getData(); for (Participant participant : participantList) { - if (participant.isInCall() || (userBeingCalled.hasSpreedCapabilityWithName("in-call-flags") && participant.getParticipantFlags() != 0)) { + if (participant.isInCall() || (userBeingCalled.hasSpreedCapabilityWithName("in-call-flags") && !participant.getParticipantFlags().equals(Participant.ParticipantFlags.NOT_IN_CALL))) { hasParticipantsInCall = true; if (participant.getUserId().equals(userBeingCalled.getUserId())) { diff --git a/app/src/main/java/com/nextcloud/talk/models/json/converters/ParticipantFlagsConverter.java b/app/src/main/java/com/nextcloud/talk/models/json/converters/ParticipantFlagsConverter.java new file mode 100644 index 000000000..a87d3ea99 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/converters/ParticipantFlagsConverter.java @@ -0,0 +1,38 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.models.json.converters; + +import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; +import com.nextcloud.talk.models.json.participants.Participant; +import com.nextcloud.talk.models.json.participants.Participant.ParticipantFlags; +import com.nextcloud.talk.models.json.rooms.Conversation; + +public class ParticipantFlagsConverter extends IntBasedTypeConverter { + @Override + public ParticipantFlags getFromInt(int i) { + return ParticipantFlags.fromValue(i); + } + + @Override + public int convertToInt(ParticipantFlags object) { + return object.getValue(); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java index 60eaa3950..a3dbb6cf4 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java @@ -23,6 +23,7 @@ package com.nextcloud.talk.models.json.participants; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter; +import com.nextcloud.talk.models.json.converters.ParticipantFlagsConverter; import org.parceler.Parcel; @@ -56,8 +57,8 @@ public class Participant { @JsonField(name = "inCall") boolean inCall; - @JsonField(name = "participantFlags") - long participantFlags; + @JsonField(name = "participantFlags", typeConverter = ParticipantFlagsConverter.class) + ParticipantFlags participantFlags; String source; @@ -69,4 +70,40 @@ public class Participant { GUEST, USER_FOLLOWING_LINK } + + public enum ParticipantFlags { + NOT_IN_CALL (0), + IN_CALL (1), + IN_CALL_WITH_AUDIO (3), + IN_CALL_WITH_VIDEO (5), + IN_CALL_WITH_AUDIO_AND_VIDEO (7); + + private int value; + + ParticipantFlags(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static ParticipantFlags fromValue(int value) { + switch (value) { + case 0: + return NOT_IN_CALL; + case 1: + return IN_CALL; + case 3: + return IN_CALL_WITH_AUDIO; + case 5: + return IN_CALL_WITH_VIDEO; + case 7: + return IN_CALL_WITH_AUDIO_AND_VIDEO; + default: + return NOT_IN_CALL; + } + } + + } }