Browse Source

Fix #337 and closing websocket connections

Mario Danic 6 years ago
parent
commit
e5532a5842

BIN
app/assets/fonts/Nunito-Black.ttf


BIN
app/assets/fonts/Nunito-BlackItalic.ttf


BIN
app/assets/fonts/Nunito-Bold.ttf


BIN
app/assets/fonts/Nunito-BoldItalic.ttf


BIN
app/assets/fonts/Nunito-ExtraBold.ttf


BIN
app/assets/fonts/Nunito-ExtraBoldItalic.ttf


BIN
app/assets/fonts/Nunito-ExtraLight.ttf


BIN
app/assets/fonts/Nunito-ExtraLightItalic.ttf


BIN
app/assets/fonts/Nunito-Italic.ttf


BIN
app/assets/fonts/Nunito-Light.ttf


BIN
app/assets/fonts/Nunito-LightItalic.ttf


BIN
app/assets/fonts/Nunito-Regular.ttf


BIN
app/assets/fonts/Nunito-SemiBold.ttf


BIN
app/assets/fonts/Nunito-SemiBoldItalic.ttf


BIN
app/assets/fonts/NunitoHeavy-Italic.ttf


BIN
app/assets/fonts/NunitoHeavy-Regular.ttf


+ 2 - 0
app/build.gradle

@@ -190,6 +190,8 @@ dependencies {
     implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
     implementation 'com.kevalpatel2106:emoticongifkeyboard:1.1'
 
+    compile 'uk.co.chrisjenx:calligraphy:2.3.0'
+
     testImplementation 'junit:junit:4.12'
     androidTestImplementation ('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
         exclude group: 'com.android.support', module: 'support-annotations'

+ 7 - 0
app/src/main/java/com/nextcloud/talk/activities/BaseActivity.java

@@ -21,6 +21,7 @@
 package com.nextcloud.talk.activities;
 
 import android.annotation.SuppressLint;
+import android.content.Context;
 import android.os.Bundle;
 import android.util.Log;
 import android.webkit.SslErrorHandler;
@@ -45,6 +46,7 @@ import javax.inject.Inject;
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AppCompatActivity;
 import autodagger.AutoInjector;
+import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
 
 @AutoInjector(NextcloudTalkApplication.class)
 public class BaseActivity extends AppCompatActivity {
@@ -59,6 +61,11 @@ public class BaseActivity extends AppCompatActivity {
         NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
     }
 
+    @Override
+    protected void attachBaseContext(Context newBase) {
+        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
+    }
+
     public void showCertificateDialog(X509Certificate cert, MagicTrustManager magicTrustManager,
                                       @Nullable SslErrorHandler sslErrorHandler) {
         DateFormat formatter = DateFormat.getDateInstance(DateFormat.LONG);

+ 7 - 0
app/src/main/java/com/nextcloud/talk/activities/MagicCallActivity.java

@@ -20,6 +20,7 @@
 
 package com.nextcloud.talk.activities;
 
+import android.content.Context;
 import android.content.res.Configuration;
 import android.os.Bundle;
 import android.view.View;
@@ -45,6 +46,7 @@ import javax.inject.Inject;
 import autodagger.AutoInjector;
 import butterknife.BindView;
 import butterknife.ButterKnife;
+import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
 
 @AutoInjector(NextcloudTalkApplication.class)
 public class MagicCallActivity extends BaseActivity {
@@ -64,6 +66,11 @@ public class MagicCallActivity extends BaseActivity {
         return flags;
     }
 
+    @Override
+    protected void attachBaseContext(Context newBase) {
+        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

+ 6 - 0
app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java

@@ -55,6 +55,7 @@ import androidx.work.PeriodicWorkRequest;
 import androidx.work.WorkManager;
 import autodagger.AutoComponent;
 import autodagger.AutoInjector;
+import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
 
 @AutoComponent(
         modules = {
@@ -109,6 +110,11 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
     public void onCreate() {
         super.onCreate();
 
+        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
+                .setDefaultFontPath("fonts/Nunito-Regular.ttf")
+                .build()
+        );
+
         sharedApplication = this;
 
         initializeWebRtc();

+ 8 - 11
app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java

@@ -36,7 +36,6 @@ import com.nextcloud.talk.models.json.websocket.EventOverallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.HelloResponseOverallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.JoinedRoomOverallWebSocketMessage;
 import com.nextcloud.talk.utils.MagicMap;
-import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
 
 import org.greenrobot.eventbus.EventBus;
 
@@ -93,16 +92,14 @@ public class MagicWebSocketInstance extends WebSocketListener {
 
     @Override
     public void onOpen(WebSocket webSocket, Response response) {
-        if (isConnected()) {
-            try {
-                if (TextUtils.isEmpty(resumeId)) {
-                    webSocket.send(LoganSquare.serialize(webSocketConnectionHelper.getAssembledHelloModel(conversationUser, webSocketTicket)));
-                } else {
-                    webSocket.send(LoganSquare.serialize(webSocketConnectionHelper.getAssembledHelloModelForResume(resumeId)));
-                }
-            } catch (IOException e) {
-                Log.e(TAG, "Failed to serialize hello model");
+        try {
+            if (TextUtils.isEmpty(resumeId)) {
+                webSocket.send(LoganSquare.serialize(webSocketConnectionHelper.getAssembledHelloModel(conversationUser, webSocketTicket)));
+            } else {
+                webSocket.send(LoganSquare.serialize(webSocketConnectionHelper.getAssembledHelloModelForResume(resumeId)));
             }
+        } catch (IOException e) {
+            Log.e(TAG, "Failed to serialize hello model");
         }
     }
 
@@ -280,7 +277,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
                 ByeWebSocketMessage byeWebSocketMessage = new ByeWebSocketMessage();
                 byeWebSocketMessage.setType("bye");
                 byeWebSocketMessage.setBye(new HashMap<>());
-                webSocket.send(LoganSquare.serialize(byeWebSocketMessage);
+                webSocket.send(LoganSquare.serialize(byeWebSocketMessage));
             } catch (IOException e) {
                 Log.e(TAG, "Failed to serialize bye message");
             }

+ 1 - 1
app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java

@@ -67,7 +67,7 @@ public class WebSocketConnectionHelper {
         }
 
         MagicWebSocketInstance magicWebSocketInstance;
-        if ((magicWebSocketInstance = magicWebSocketInstanceMap.get(userEntity.getId())) != null && !magicWebSocketInstance.isPermanentlyClosed()) {
+        if (magicWebSocketInstanceMap.containsKey(userEntity.getId())  && (magicWebSocketInstance = magicWebSocketInstanceMap.get(userEntity.getId())) != null && !magicWebSocketInstance.isPermanentlyClosed()) {
             return magicWebSocketInstance;
         } else {
             magicWebSocketInstance = new MagicWebSocketInstance(userEntity, generatedURL, webSocketTicket);