Explorar o código

Fix participant flags

Mario Danic %!s(int64=6) %!d(string=hai) anos
pai
achega
e2a74f53dc

+ 30 - 30
app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java

@@ -216,7 +216,7 @@ public class CallNotificationController extends BaseController {
                         boolean inCallOnDifferentDevice = false;
                         List<Participant> participantList = participantsOverall.getOcs().getData();
                         for (Participant participant : participantList) {
-                            if (participant.isInCall() || (userBeingCalled.hasSpreedCapabilityWithName("in-call-flags") && !participant.getParticipantFlags().equals(Participant.ParticipantFlags.NOT_IN_CALL))) {
+                            if (participant.getParticipantFlags() != Participant.ParticipantFlags.NOT_IN_CALL) {
                                 hasParticipantsInCall = true;
 
                                 if (participant.getUserId().equals(userBeingCalled.getUserId())) {
@@ -436,38 +436,38 @@ public class CallNotificationController extends BaseController {
                                             (getActivity()).getBitmapPool(), resource, avatarSize, avatarSize));
                                 }
 
-                                    if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 200 &&
-                                            userBeingCalled.hasSpreedCapabilityWithName("no-ping")) {
-                                        final Allocation input = Allocation.createFromBitmap(renderScript, resource);
-                                        final Allocation output = Allocation.createTyped(renderScript, input.getType());
-                                        final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element
-                                                .U8_4(renderScript));
-                                        script.setRadius(15f);
-                                        script.setInput(input);
-                                        script.forEach(output);
-                                        output.copyTo(resource);
-
-                                        if (getResources() != null) {
-                                            incomingTextRelativeLayout.setBackground(getResources().getDrawable(R.drawable
-                                                    .incoming_gradient));
-                                            constraintLayout.setBackground(new BitmapDrawable(resource));
-                                        }
-                                    } else if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 201) {
-                                        Palette palette = Palette.from(resource).generate();
-                                        if (getResources() != null) {
-                                            int color = palette.getDominantColor(getResources().getColor(R.color.grey950));
-
-                                            if (color != getResources().getColor(R.color.grey950)) {
-                                                float[] hsv = new float[3];
-                                                Color.colorToHSV(color, hsv);
-                                                hsv[2] *= 0.75f;
-                                                color = Color.HSVToColor(hsv);
-                                            }
-
-                                            constraintLayout.setBackgroundColor(color);
+                                if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 200 &&
+                                        userBeingCalled.hasSpreedCapabilityWithName("no-ping")) {
+                                    final Allocation input = Allocation.createFromBitmap(renderScript, resource);
+                                    final Allocation output = Allocation.createTyped(renderScript, input.getType());
+                                    final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element
+                                            .U8_4(renderScript));
+                                    script.setRadius(15f);
+                                    script.setInput(input);
+                                    script.forEach(output);
+                                    output.copyTo(resource);
+
+                                    if (getResources() != null) {
+                                        incomingTextRelativeLayout.setBackground(getResources().getDrawable(R.drawable
+                                                .incoming_gradient));
+                                        constraintLayout.setBackground(new BitmapDrawable(resource));
+                                    }
+                                } else if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 201) {
+                                    Palette palette = Palette.from(resource).generate();
+                                    if (getResources() != null) {
+                                        int color = palette.getDominantColor(getResources().getColor(R.color.grey950));
+
+                                        if (color != getResources().getColor(R.color.grey950)) {
+                                            float[] hsv = new float[3];
+                                            Color.colorToHSV(color, hsv);
+                                            hsv[2] *= 0.75f;
+                                            color = Color.HSVToColor(hsv);
                                         }
+
+                                        constraintLayout.setBackgroundColor(color);
                                     }
                                 }
+                            }
                         });
 
 

+ 38 - 0
app/src/main/java/com/nextcloud/talk/models/json/converters/ObjectParcelConverter.java

@@ -0,0 +1,38 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.models.json.converters;
+
+import android.os.Parcel;
+
+import org.parceler.ParcelConverter;
+import org.parceler.Parcels;
+
+public class ObjectParcelConverter implements ParcelConverter<Object> {
+    @Override
+    public void toParcel(Object input, Parcel parcel) {
+        parcel.writeParcelable(Parcels.wrap(input), 0);
+    }
+
+    @Override
+    public Object fromParcel(Parcel parcel) {
+        return parcel.readParcelable(Object.class.getClassLoader());
+    }
+}

+ 6 - 8
app/src/main/java/com/nextcloud/talk/models/json/converters/ParticipantFlagsConverter.java

@@ -20,19 +20,17 @@
 
 package com.nextcloud.talk.models.json.converters;
 
-import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter;
-import com.nextcloud.talk.models.json.participants.Participant;
+import com.bluelinelabs.logansquare.typeconverters.LongBasedTypeConverter;
 import com.nextcloud.talk.models.json.participants.Participant.ParticipantFlags;
-import com.nextcloud.talk.models.json.rooms.Conversation;
 
-public class ParticipantFlagsConverter extends IntBasedTypeConverter<ParticipantFlags> {
+public class ParticipantFlagsConverter extends LongBasedTypeConverter<ParticipantFlags> {
     @Override
-    public ParticipantFlags getFromInt(int i) {
-        return ParticipantFlags.fromValue(i);
-    }
+    public ParticipantFlags getFromLong(long l) {
+        return ParticipantFlags.fromValue(l);
+    };
 
     @Override
-    public int convertToInt(ParticipantFlags object) {
+    public long convertToLong(ParticipantFlags object) {
         return object.getValue();
     }
 }

+ 36 - 22
app/src/main/java/com/nextcloud/talk/models/json/participants/Participant.java

@@ -23,9 +23,10 @@ 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 com.nextcloud.talk.models.json.converters.ObjectParcelConverter;
 
 import org.parceler.Parcel;
+import org.parceler.ParcelPropertyConverter;
 
 import lombok.Data;
 
@@ -54,12 +55,26 @@ public class Participant {
     @JsonField(name = "roomId")
     long roomId;
 
+    @ParcelPropertyConverter(ObjectParcelConverter.class)
     @JsonField(name = "inCall")
-    boolean inCall;
-
-    @JsonField(name = "participantFlags", typeConverter = ParticipantFlagsConverter.class)
-    ParticipantFlags participantFlags;
+    Object inCall;
+
+    public ParticipantFlags getParticipantFlags() {
+        ParticipantFlags participantFlags = ParticipantFlags.NOT_IN_CALL;
+        if (inCall != null) {
+            if (inCall instanceof Long) {
+                participantFlags = ParticipantFlags.fromValue((Long) inCall);
+            } else if (inCall instanceof Boolean) {
+                if ((boolean) inCall) {
+                    participantFlags = ParticipantFlags.IN_CALL;
+                } else {
+                    participantFlags = ParticipantFlags.NOT_IN_CALL;
+                }
+            }
+        }
 
+        return participantFlags;
+    }
     String source;
 
     public enum ParticipantType {
@@ -78,30 +93,29 @@ public class Participant {
         IN_CALL_WITH_VIDEO (5),
         IN_CALL_WITH_AUDIO_AND_VIDEO (7);
 
-        private int value;
+        private long value;
 
-        ParticipantFlags(int value) {
+        ParticipantFlags(long value) {
             this.value = value;
         }
 
-        public int getValue() {
+        public long 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;
+        public static ParticipantFlags fromValue(long value) {
+            if (value == 0) {
+                return NOT_IN_CALL;
+            } else if (value == 1) {
+                return IN_CALL;
+            } else if (value == 3) {
+                return IN_CALL_WITH_AUDIO;
+            } else if (value == 5) {
+                return IN_CALL_WITH_VIDEO;
+            } else if (value == 7) {
+                return IN_CALL_WITH_AUDIO_AND_VIDEO;
+            } else {
+                return NOT_IN_CALL;
             }
         }