瀏覽代碼

Dispose everything properly

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 年之前
父節點
當前提交
08efe40d28

+ 4 - 11
app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java

@@ -30,7 +30,6 @@ import android.support.multidex.MultiDex;
 import android.support.multidex.MultiDexApplication;
 import android.util.Log;
 
-import com.nextcloud.talk.BuildConfig;
 import com.nextcloud.talk.dagger.modules.BusModule;
 import com.nextcloud.talk.dagger.modules.ContextModule;
 import com.nextcloud.talk.dagger.modules.DatabaseModule;
@@ -51,11 +50,11 @@ import org.webrtc.PeerConnectionFactory;
 import org.webrtc.voiceengine.WebRtcAudioManager;
 import org.webrtc.voiceengine.WebRtcAudioUtils;
 
-import java.security.GeneralSecurityException;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Singleton;
 
+import androidx.work.Configuration;
 import androidx.work.ExistingPeriodicWorkPolicy;
 import androidx.work.OneTimeWorkRequest;
 import androidx.work.PeriodicWorkRequest;
@@ -124,14 +123,7 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
 
         initializeWebRtc();
         DisplayUtils.useCompatVectorIfNeeded();
-
-        try {
-            buildComponent();
-        } catch (final GeneralSecurityException exception) {
-            if (BuildConfig.DEBUG) {
-                exception.printStackTrace();
-            }
-        }
+        buildComponent();
 
         componentApplication.inject(this);
         refWatcher = LeakCanary.install(this);
@@ -144,6 +136,7 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
         PeriodicWorkRequest periodicCapabilitiesUpdateWork = new PeriodicWorkRequest.Builder(CapabilitiesWorker.class,
                 1, TimeUnit.DAYS).build();
 
+        WorkManager.initialize(getApplicationContext(), new Configuration.Builder().build());
         WorkManager.getInstance().enqueue(pushRegistrationWork);
         WorkManager.getInstance().enqueue(accountRemovalWork);
         WorkManager.getInstance().enqueueUniquePeriodicWork("DailyCapabilitiesUpdateWork",
@@ -166,7 +159,7 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
     //endregion
 
     //region Protected methods
-    protected void buildComponent() throws GeneralSecurityException {
+    protected void buildComponent() {
         componentApplication = DaggerNextcloudTalkApplicationComponent.builder()
                 .busModule(new BusModule())
                 .contextModule(new ContextModule(getApplicationContext()))

+ 8 - 2
app/src/main/java/com/nextcloud/talk/controllers/ChatController.java

@@ -468,8 +468,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
 
     @Override
     public void onDestroy() {
+        super.onDestroy();
         inChat = false;
-        dispose();
         ApplicationWideCurrentRoomHolder.getInstance().clear();
         leaveRoom();
     }
@@ -477,7 +477,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
     private void dispose() {
         Disposable disposable;
         for (int i = 0; i < disposableList.size(); i++) {
-            if ((disposable = disposableList.get(i)).isDisposed()) {
+            if (!(disposable = disposableList.get(i)).isDisposed()) {
                 disposable.dispose();
             }
         }
@@ -575,6 +575,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
 
                     @Override
                     public void onNext(GenericOverall genericOverall) {
+                        dispose();
                         getRouter().popToRoot();
                     }
 
@@ -655,6 +656,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
     }
 
     private void pullChatMessages(int lookIntoFuture) {
+        if (!inChat) {
+            return;
+        }
+
         if (!lookingIntoFuture && lookIntoFuture == 1) {
             lookingIntoFuture = true;
         }
@@ -708,6 +713,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
                     .subscribeOn(Schedulers.newThread())
                     .observeOn(AndroidSchedulers.mainThread())
                     .retry(3, observable -> inChat)
+                    .takeWhile(observable -> inChat)
                     .subscribe(new Observer<Response>() {
                         @Override
                         public void onSubscribe(Disposable d) {

+ 0 - 5
app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java

@@ -73,7 +73,6 @@ import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.IOException;
-import java.net.CookieManager;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -167,9 +166,6 @@ public class SettingsController extends BaseController {
     @Inject
     UserUtils userUtils;
 
-    @Inject
-    CookieManager cookieManager;
-
     private UserEntity currentUser;
     private String credentials;
 
@@ -424,7 +420,6 @@ public class SettingsController extends BaseController {
 
 
             removeAccountButton.addPreferenceClickListener(view1 -> {
-                cookieManager.getCookieStore().removeAll();
                 boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(currentUser.getId());
 
                 OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build();

+ 1 - 6
app/src/main/java/com/nextcloud/talk/controllers/SwitchAccountController.java

@@ -107,12 +107,7 @@ public class SwitchAccountController extends BaseController {
                             public void onNext(UserEntity userEntity) {
                                 userUtils.disableAllUsersWithoutId(userEntity.getId());
                                 if (getActivity() != null) {
-                                    getActivity().runOnUiThread(new Runnable() {
-                                        @Override
-                                        public void run() {
-                                            getRouter().popCurrentController();
-                                        }
-                                    });
+                                    getActivity().runOnUiThread(() -> getRouter().popCurrentController());
                                 }
                             }