Commit 596d1035 authored by Tiago Cunha's avatar Tiago Cunha

Forgot this one

parent 772b55bd
package chat.rocket.android.fragment.add_server;
import android.support.annotation.NonNull;
import chat.rocket.android.shared.BaseContract;
public interface InputHostnameContract {
interface View {
interface View extends BaseContract.View {
void showLoader();
void hideLoader();
......@@ -16,11 +16,7 @@ public interface InputHostnameContract {
void showHome();
}
interface Presenter {
void bindView(@NonNull View view);
void release();
interface Presenter extends BaseContract.Presenter<View> {
void connectTo(String hostname);
}
......
package chat.rocket.android.fragment.add_server;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.DefaultServerPolicyApi;
......@@ -10,11 +9,13 @@ import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.ServerPolicyApiValidationHelper;
import chat.rocket.android.helper.ServerPolicyHelper;
import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class InputHostnamePresenter implements InputHostnameContract.Presenter {
public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.View>
implements InputHostnameContract.Presenter {
private final SharedPreferences rocketChatCache;
private final ConnectivityManagerApi connectivityManager;
......@@ -25,24 +26,6 @@ public class InputHostnamePresenter implements InputHostnameContract.Presenter {
this.connectivityManager = connectivityManager;
}
private InputHostnameContract.View view;
private Subscription serverPolicySubscription;
@Override
public void bindView(@NonNull InputHostnameContract.View view) {
this.view = view;
}
@Override
public void release() {
if (serverPolicySubscription != null) {
serverPolicySubscription.unsubscribe();
}
view = null;
}
@Override
public void connectTo(final String hostname) {
view.showLoader();
......@@ -57,11 +40,9 @@ public class InputHostnamePresenter implements InputHostnameContract.Presenter {
final ServerPolicyApiValidationHelper validationHelper =
new ServerPolicyApiValidationHelper(serverPolicyApi);
if (serverPolicySubscription != null) {
serverPolicySubscription.unsubscribe();
}
clearSubscripions();
serverPolicySubscription = ServerPolicyHelper.isApiVersionValid(validationHelper)
final Subscription subscription = ServerPolicyHelper.isApiVersionValid(validationHelper)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnTerminate(() -> view.hideLoader())
......@@ -76,6 +57,8 @@ public class InputHostnamePresenter implements InputHostnameContract.Presenter {
throwable -> {
view.showConnectionError();
});
addSubscription(subscription);
}
private void onServerValid(final String hostname, boolean usesSecureConnection) {
......
......@@ -25,4 +25,8 @@ public abstract class BasePresenter<T extends BaseContract.View>
protected void addSubscription(Subscription subscription) {
compositeSubscription.add(subscription);
}
protected void clearSubscripions() {
compositeSubscription.clear();
}
}
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