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
@Override
public synchronized void showConnectionError() {
System.out.println("ERROR");
dismissStatusTickerIfShowing();
statusTicker = Snackbar.make(findViewById(getLayoutContainerForFragment()),
R.string.fragment_retry_login_error_title, Snackbar.LENGTH_INDEFINITE)
......
......@@ -230,8 +230,6 @@ public class MainPresenter extends BasePresenter<MainContract.View>
} else if (connectivity.state == ServerConnectivity.STATE_DISCONNECTED) {
if (connectivity.code == DDPClient.REASON_NETWORK_ERROR) {
view.showConnectionError();
} else {
view.showConnectionOk();
}
} else {
view.showConnecting();
......
......@@ -8,10 +8,6 @@ import chat.rocket.core.models.ServerInfo;
* interfaces used for RocketChatService and RocketChatwebSocketThread.
*/
/*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();
......
......@@ -195,6 +195,7 @@ import io.reactivex.subjects.BehaviorSubject;
}
return connectToServer(hostname)
.retry(exception -> exception instanceof ThreadLooperNotPreparedException)
.onErrorResumeNext(Single.just(false));
});
}
......@@ -264,7 +265,7 @@ import io.reactivex.subjects.BehaviorSubject;
if (serviceInterface != null) {
return serviceInterface.ensureConnectionToServer(hostname);
} else {
return Single.error(new IllegalStateException("not prepared"));
return Single.error(new ThreadLooperNotPreparedException("not prepared"));
}
});
}
......@@ -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