Commit 2b009fff authored by Leonardo Aramaki's avatar Leonardo Aramaki

Schedule KeepAliveJob when online

parent ad4bab2f
...@@ -16,6 +16,7 @@ import chat.rocket.android.helper.LogIfError; ...@@ -16,6 +16,7 @@ import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger; import chat.rocket.android.helper.Logger;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.android.service.ConnectivityManagerApi; import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.service.KeepAliveJob;
import chat.rocket.android.service.ServerConnectivity; import chat.rocket.android.service.ServerConnectivity;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.android_ddp.DDPClient; import chat.rocket.android_ddp.DDPClient;
...@@ -211,8 +212,8 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -211,8 +212,8 @@ public class MainPresenter extends BasePresenter<MainContract.View>
view.showConnecting(); view.showConnecting();
return; return;
} }
// TODO: Should we remove below and above calls to view?
// view.showConnectionOk(); // view.showConnectionOk();
}, },
Logger::report Logger::report
); );
...@@ -227,10 +228,13 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -227,10 +228,13 @@ public class MainPresenter extends BasePresenter<MainContract.View>
.subscribe( .subscribe(
connectivity -> { connectivity -> {
if (connectivity.state == ServerConnectivity.STATE_CONNECTED) { if (connectivity.state == ServerConnectivity.STATE_CONNECTED) {
KeepAliveJob.Companion.cancel();
//TODO: notify almost connected or something like that. //TODO: notify almost connected or something like that.
// view.showConnectionOk(); // view.showConnectionOk();
} else if (connectivity.state == ServerConnectivity.STATE_DISCONNECTED) { } else if (connectivity.state == ServerConnectivity.STATE_DISCONNECTED) {
KeepAliveJob.Companion.cancel();
if (connectivity.code == DDPClient.REASON_NETWORK_ERROR) { if (connectivity.code == DDPClient.REASON_NETWORK_ERROR) {
KeepAliveJob.Companion.schedule();
view.showConnectionError(); view.showConnectionError();
} }
} else if (connectivity.state == ServerConnectivity.STATE_SESSION_ESTABLISHED) { } else if (connectivity.state == ServerConnectivity.STATE_SESSION_ESTABLISHED) {
...@@ -240,7 +244,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -240,7 +244,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
view.showConnecting(); view.showConnecting();
} }
}, },
Logger::report RCLog::e
); );
addSubscription(disposable); addSubscription(disposable);
......
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