Commit 86ca95ee authored by Leonardo Aramaki's avatar Leonardo Aramaki

Retry connection if socket thread looper not yet prepared

parent 95e1741f
...@@ -251,6 +251,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -251,6 +251,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
@Override @Override
public synchronized void showConnectionError() { public synchronized void showConnectionError() {
System.out.println("ERROR");
dismissStatusTickerIfShowing(); dismissStatusTickerIfShowing();
statusTicker = Snackbar.make(findViewById(getLayoutContainerForFragment()), statusTicker = Snackbar.make(findViewById(getLayoutContainerForFragment()),
R.string.fragment_retry_login_error_title, Snackbar.LENGTH_INDEFINITE) R.string.fragment_retry_login_error_title, Snackbar.LENGTH_INDEFINITE)
......
...@@ -230,8 +230,6 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -230,8 +230,6 @@ public class MainPresenter extends BasePresenter<MainContract.View>
} else if (connectivity.state == ServerConnectivity.STATE_DISCONNECTED) { } else if (connectivity.state == ServerConnectivity.STATE_DISCONNECTED) {
if (connectivity.code == DDPClient.REASON_NETWORK_ERROR) { if (connectivity.code == DDPClient.REASON_NETWORK_ERROR) {
view.showConnectionError(); view.showConnectionError();
} else {
view.showConnectionOk();
} }
} else { } else {
view.showConnecting(); view.showConnecting();
......
...@@ -8,10 +8,6 @@ import chat.rocket.core.models.ServerInfo; ...@@ -8,10 +8,6 @@ import chat.rocket.core.models.ServerInfo;
* interfaces used for RocketChatService and RocketChatwebSocketThread. * interfaces used for RocketChatService and RocketChatwebSocketThread.
*/ */
/*package*/ interface ConnectivityManagerInternal { /*package*/ interface ConnectivityManagerInternal {
int REASON_CLOSED_BY_USER = 101;
int REASON_NETWORK_ERROR = 102;
int REASON_SERVER_ERROR = 103;
int REASON_UNKNOWN = 104;
void resetConnectivityStateList(); void resetConnectivityStateList();
......
...@@ -195,6 +195,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -195,6 +195,7 @@ import io.reactivex.subjects.BehaviorSubject;
} }
return connectToServer(hostname) return connectToServer(hostname)
.retry(exception -> exception instanceof ThreadLooperNotPreparedException)
.onErrorResumeNext(Single.just(false)); .onErrorResumeNext(Single.just(false));
}); });
} }
...@@ -264,7 +265,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -264,7 +265,7 @@ import io.reactivex.subjects.BehaviorSubject;
if (serviceInterface != null) { if (serviceInterface != null) {
return serviceInterface.ensureConnectionToServer(hostname); return serviceInterface.ensureConnectionToServer(hostname);
} else { } else {
return Single.error(new IllegalStateException("not prepared")); return Single.error(new ThreadLooperNotPreparedException("not prepared"));
} }
}); });
} }
...@@ -285,4 +286,10 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -285,4 +286,10 @@ import io.reactivex.subjects.BehaviorSubject;
} }
}); });
} }
private static class ThreadLooperNotPreparedException extends IllegalStateException {
ThreadLooperNotPreparedException(String message) {
super(message);
}
}
} }
\ 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