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

Forgot this one

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