Commit e30e946e authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Merge branch 'iss321' of github.com:filipedelimabrito/Rocket.Chat.Android into iss321

parents d575ffb6 1260037d
package chat.rocket.android.fragment.add_server;
import chat.rocket.android.BackgroundLooper;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.DefaultServerPolicyApi;
......@@ -13,14 +13,11 @@ import chat.rocket.android.helper.ServerPolicyHelper;
import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter;
public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.View>
implements InputHostnameContract.Presenter {
public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.View> implements InputHostnameContract.Presenter {
private final RocketChatCache rocketChatCache;
private final ConnectivityManagerApi connectivityManager;
public InputHostnamePresenter(RocketChatCache rocketChatCache,
ConnectivityManagerApi connectivityManager) {
public InputHostnamePresenter(RocketChatCache rocketChatCache, ConnectivityManagerApi connectivityManager) {
this.rocketChatCache = rocketChatCache;
this.connectivityManager = connectivityManager;
}
......@@ -28,21 +25,17 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
@Override
public void connectTo(final String hostname) {
view.showLoader();
connectToEnforced(ServerPolicyHelper.enforceHostname(hostname));
}
public void connectToEnforced(final String hostname) {
final ServerPolicyApi serverPolicyApi =
new DefaultServerPolicyApi(OkHttpHelper.getClientForUploadFile(), hostname);
final ServerPolicyApiValidationHelper validationHelper =
new ServerPolicyApiValidationHelper(serverPolicyApi);
final ServerPolicyApi serverPolicyApi = new DefaultServerPolicyApi(OkHttpHelper.getClientForUploadFile(), hostname);
final ServerPolicyApiValidationHelper validationHelper = new ServerPolicyApiValidationHelper(serverPolicyApi);
clearSubscriptions();
final Disposable subscription = ServerPolicyHelper.isApiVersionValid(validationHelper)
.subscribeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.doOnTerminate(() -> view.hideLoader())
.subscribe(
......@@ -54,16 +47,16 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
}
},
throwable -> view.showConnectionError());
addSubscription(subscription);
}
private void onServerValid(final String hostname, boolean usesSecureConnection) {
private void onServerValid(String hostname, boolean usesSecureConnection) {
rocketChatCache.setSelectedServerHostname(hostname);
connectivityManager.addOrUpdateServer(hostname, hostname, !usesSecureConnection);
String server = hostname.replace("/", ".");
connectivityManager.addOrUpdateServer(server, server, !usesSecureConnection);
connectivityManager.keepAliveServer();
view.showHome();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment