mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-18 06:32:08 +03:00
Clean up MerlinTheWizard
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
01bcc6ffe8
commit
14efe5992a
6 changed files with 4 additions and 129 deletions
|
@ -55,7 +55,6 @@ import com.nextcloud.talk.utils.DisplayUtils;
|
|||
import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache;
|
||||
import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule;
|
||||
import com.nextcloud.talk.utils.database.user.UserModule;
|
||||
import com.nextcloud.talk.utils.singletons.MerlinTheWizard;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
|
||||
import com.vanniktech.emoji.EmojiManager;
|
||||
|
@ -170,8 +169,6 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
|
|||
OneTimeWorkRequest capabilitiesUpdateWork = new OneTimeWorkRequest.Builder(CapabilitiesWorker.class).build();
|
||||
OneTimeWorkRequest signalingSettingsWork = new OneTimeWorkRequest.Builder(SignalingSettingsWorker.class).build();
|
||||
|
||||
new MerlinTheWizard().initMerlin();
|
||||
|
||||
WorkManager.getInstance().enqueue(pushRegistrationWork);
|
||||
WorkManager.getInstance().enqueue(accountRemovalWork);
|
||||
WorkManager.getInstance().enqueue(capabilitiesUpdateWork);
|
||||
|
|
|
@ -54,7 +54,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys;
|
|||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.singletons.MerlinTheWizard;
|
||||
|
||||
import io.reactivex.CompletableObserver;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
@ -268,7 +268,6 @@ public class AccountVerificationController extends BaseController {
|
|||
@Override
|
||||
public void onNext(UserEntity userEntity) {
|
||||
internalAccountId = userEntity.getId();
|
||||
new MerlinTheWizard().initMerlin();
|
||||
|
||||
if (new ClosedInterfaceImpl().isGooglePlayServicesAvailable()) {
|
||||
registerForPush();
|
||||
|
|
|
@ -77,7 +77,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
|||
import com.nextcloud.talk.utils.power.PowerManagerUtils;
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
||||
import com.nextcloud.talk.utils.singletons.MerlinTheWizard;
|
||||
import com.nextcloud.talk.webrtc.*;
|
||||
import com.wooplr.spotlight.SpotlightView;
|
||||
import io.reactivex.Observable;
|
||||
|
@ -1384,7 +1383,6 @@ public class CallController extends BaseController {
|
|||
}
|
||||
|
||||
private void hangupNetworkCalls(boolean shutDownView) {
|
||||
if (MerlinTheWizard.isConnectedToInternet()) {
|
||||
ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(baseUrl, roomToken))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -1421,9 +1419,6 @@ public class CallController extends BaseController {
|
|||
|
||||
}
|
||||
});
|
||||
} else if (shutDownView && getActivity() != null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void leaveRoom(boolean shutDownView) {
|
||||
|
@ -1706,9 +1701,7 @@ public class CallController extends BaseController {
|
|||
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType.PUBLISHER_FAILED)) {
|
||||
currentCallStatus = CallStatus.PUBLISHER_FAILED;
|
||||
webSocketClient.clearResumeId();
|
||||
if (MerlinTheWizard.isConnectedToInternet()) {
|
||||
hangup(false);
|
||||
}
|
||||
hangup(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1725,7 +1718,7 @@ public class CallController extends BaseController {
|
|||
magicPeerConnectionWrapper = magicPeerConnectionWrapperList.get(i);
|
||||
Observable
|
||||
.interval(1, TimeUnit.SECONDS)
|
||||
.repeatUntil(() -> (!isConnectionEstablished() || isBeingDestroyed() || isDestroyed() || !MerlinTheWizard.isConnectedToInternet()))
|
||||
.repeatUntil(() -> (!isConnectionEstablished() || isBeingDestroyed() || isDestroyed()))
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Observer<Long>() {
|
||||
@Override
|
||||
|
|
|
@ -66,7 +66,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
|||
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
||||
import com.nextcloud.talk.utils.preferences.MagicUserInputModule;
|
||||
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
||||
import com.nextcloud.talk.utils.singletons.MerlinTheWizard;
|
||||
import com.yarolegovich.lovelydialog.LovelySaveStateHandler;
|
||||
import com.yarolegovich.lovelydialog.LovelyStandardDialog;
|
||||
import com.yarolegovich.mp.*;
|
||||
|
@ -371,12 +370,6 @@ public class SettingsController extends BaseController {
|
|||
private void removeCurrentAccount() {
|
||||
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(currentUser.getId());
|
||||
|
||||
if (otherUserExists) {
|
||||
new MerlinTheWizard().initMerlin();
|
||||
} else {
|
||||
new MerlinTheWizard().getMerlin().unbind();
|
||||
}
|
||||
|
||||
OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build();
|
||||
WorkManager.getInstance().enqueue(accountRemovalWork);
|
||||
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2019 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.utils.singletons;
|
||||
|
||||
import android.content.Context;
|
||||
import autodagger.AutoInjector;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.events.NetworkEvent;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
import com.novoda.merlin.*;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class MerlinTheWizard {
|
||||
private static Merlin merlin;
|
||||
|
||||
private UserEntity currentUserEntity;
|
||||
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
Context context;
|
||||
|
||||
@Inject
|
||||
UserUtils userUtils;
|
||||
|
||||
private static boolean isConnectedToInternet;
|
||||
|
||||
public MerlinTheWizard() {
|
||||
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
|
||||
}
|
||||
|
||||
public static boolean isConnectedToInternet() {
|
||||
return isConnectedToInternet;
|
||||
}
|
||||
|
||||
public void initMerlin() {
|
||||
if (userUtils.anyUserExists() && (currentUserEntity == null ||
|
||||
(userUtils.getCurrentUser().getId() != currentUserEntity.getId()))) {
|
||||
currentUserEntity = userUtils.getCurrentUser();
|
||||
setupMerlinForCurrentUserEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public Merlin getMerlin() {
|
||||
if (merlin == null) {
|
||||
initMerlin();
|
||||
}
|
||||
|
||||
return merlin;
|
||||
}
|
||||
|
||||
private void setupMerlinForCurrentUserEntity() {
|
||||
Endpoint endpoint = Endpoint.from(currentUserEntity.getBaseUrl() + "/index.php/204");
|
||||
ResponseCodeValidator responseCodeValidator =
|
||||
new ResponseCodeValidator.CaptivePortalResponseCodeValidator();
|
||||
|
||||
if (merlin != null) {
|
||||
merlin.unbind();
|
||||
}
|
||||
|
||||
merlin = new Merlin.Builder().withAllCallbacks().withEndpoint(endpoint).withResponseCodeValidator(responseCodeValidator).build(context);
|
||||
|
||||
merlin.bind();
|
||||
|
||||
merlin.registerConnectable(new Connectable() {
|
||||
@Override
|
||||
public void onConnect() {
|
||||
isConnectedToInternet = true;
|
||||
eventBus.post(new NetworkEvent(NetworkEvent.NetworkConnectionEvent.NETWORK_CONNECTED));
|
||||
}
|
||||
});
|
||||
|
||||
merlin.registerDisconnectable(new Disconnectable() {
|
||||
@Override
|
||||
public void onDisconnect() {
|
||||
isConnectedToInternet = false;
|
||||
eventBus.post(new NetworkEvent(NetworkEvent.NetworkConnectionEvent.NETWORK_DISCONNECTED));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -37,7 +37,7 @@ import com.nextcloud.talk.models.json.websocket.*;
|
|||
import com.nextcloud.talk.utils.LoggingUtils;
|
||||
import com.nextcloud.talk.utils.MagicMap;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.singletons.MerlinTheWizard;
|
||||
|
||||
import okhttp3.*;
|
||||
import okio.ByteString;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
@ -136,11 +136,9 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|||
public void restartWebSocket() {
|
||||
reconnecting = true;
|
||||
|
||||
if (MerlinTheWizard.isConnectedToInternet()) {
|
||||
Request request = new Request.Builder().url(connectionUrl).build();
|
||||
okHttpClient.newWebSocket(request, this);
|
||||
restartCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue