Browse Source

Bug fixes against crashes & dpToPx fixes

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 years ago
parent
commit
d781247074

+ 11 - 7
app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.java

@@ -294,7 +294,9 @@ public class ConversationInfoController extends BaseController {
                                         break;
                                 }
 
-                                messageNotificationLevel.setValue(stringValue);
+                                if (messageNotificationLevel != null) {
+                                    messageNotificationLevel.setValue(stringValue);
+                                }
                             } else {
                                 setProperNotificationValue(conversation);
                             }
@@ -320,15 +322,17 @@ public class ConversationInfoController extends BaseController {
     }
 
     private void setProperNotificationValue(Conversation conversation) {
-        if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL)) {
-            // hack to see if we get mentioned always or just on mention
-            if (conversationUser.hasSpreedCapabilityWithName("mention-flag")) {
-                messageNotificationLevel.setValue("always");
+        if (messageNotificationLevel != null) {
+            if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL)) {
+                // hack to see if we get mentioned always or just on mention
+                if (conversationUser.hasSpreedCapabilityWithName("mention-flag")) {
+                    messageNotificationLevel.setValue("always");
+                } else {
+                    messageNotificationLevel.setValue("mention");
+                }
             } else {
                 messageNotificationLevel.setValue("mention");
             }
-        } else {
-            messageNotificationLevel.setValue("mention");
         }
     }
 

+ 3 - 4
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -47,6 +47,7 @@ import android.text.style.ForegroundColorSpan;
 import android.text.style.StyleSpan;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
@@ -178,10 +179,8 @@ public class DisplayUtils {
     }
 
     public static float convertDpToPixel(float dp, Context context) {
-        Resources resources = context.getResources();
-        DisplayMetrics metrics = resources.getDisplayMetrics();
-        float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
-        return px;
+        return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
+                context.getResources().getDisplayMetrics()) + 0.5f);
     }
 
     // Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected