Commit 7ab8c5c9 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix coding style.

parent 32d380d4
......@@ -10,6 +10,9 @@ import chat.rocket.android.activity.ServerConfigActivity;
*/
public class LaunchUtil {
/**
* launch AddServerActivity with proper flags.
*/
public static void showAddServerActivity(Context context) {
Intent intent = new Intent(context, AddServerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
......
......@@ -8,6 +8,10 @@ import android.content.SharedPreferences;
*/
public class RocketChatCache {
public static final String KEY_SELECTED_SERVER_CONFIG_ID = "selectedServerConfigId";
/**
* get SharedPreference instance for RocketChat application cache.
*/
public static SharedPreferences get(Context context) {
return context.getSharedPreferences("cache", Context.MODE_PRIVATE);
}
......
......@@ -24,8 +24,8 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
protected String serverConfigId;
SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
(sharedPreferences, s) -> {
if (RocketChatCache.KEY_SELECTED_SERVER_CONFIG_ID.equals(s)) {
(sharedPreferences, key) -> {
if (RocketChatCache.KEY_SELECTED_SERVER_CONFIG_ID.equals(key)) {
updateServerConfigIdIfNeeded(sharedPreferences);
}
};
......
......@@ -75,7 +75,10 @@ public class ServerConfig extends RealmObject {
.continueWith(new LogcatIfError());
}
public static Task<Void> setState(final String serverConfigId, int state) {
/**
* Update the state of the ServerConfig with serverConfigId.
*/
public static Task<Void> updateState(final String serverConfigId, int state) {
return RealmStore.getDefault().executeTransaction(realm -> {
ServerConfig config =
realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId).findFirst();
......
......@@ -113,16 +113,16 @@ public class RocketChatService extends Service {
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String serverConfigId = config.getServerConfigId();
if (webSocketThreads.containsKey(serverConfigId)) {
return ServerConfig.setState(serverConfigId, ServerConfig.STATE_CONNECTED)
return ServerConfig.updateState(serverConfigId, ServerConfig.STATE_CONNECTED)
.onSuccessTask(_task -> Task.forResult(webSocketThreads.get(serverConfigId)));
} else {
return ServerConfig.setState(serverConfigId, ServerConfig.STATE_CONNECTING)
return ServerConfig.updateState(serverConfigId, ServerConfig.STATE_CONNECTING)
.onSuccessTask(_task -> {
webSocketThreads.put(serverConfigId, null);
return RocketChatWebSocketThread.getStarted(getApplicationContext(), config);
})
.onSuccessTask(task ->
ServerConfig.setState(serverConfigId, ServerConfig.STATE_CONNECTED)
ServerConfig.updateState(serverConfigId, ServerConfig.STATE_CONNECTED)
.onSuccessTask(_task -> task))
.onSuccessTask(task -> {
webSocketThreads.put(serverConfigId, task.getResult());
......
......@@ -84,7 +84,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
private void forceInvalidateTokens() {
serverConfigRealm.executeTransaction(realm -> {
Session session = realm.where(Session.class).equalTo("sessionId", Session.DEFAULT_ID).findFirst();
Session session = realm.where(Session.class)
.equalTo("sessionId", Session.DEFAULT_ID).findFirst();
if (session != null
&& !TextUtils.isEmpty(session.getToken())
&& (session.isTokenVerified() || !TextUtils.isEmpty(session.getError()))) {
......
......@@ -19,6 +19,7 @@ import org.json.JSONObject;
public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
private String prevHash;
/**
* constructor.
*/
......@@ -94,13 +95,12 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
).onSuccessTask(task ->
webSocketAPI.rpc(methodCallId, methodName, params, timeout)
.onSuccessTask(_task -> realmHelper.executeTransaction(realm -> {
String json = _task.getResult().result;
return realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCED)
.put("resultJson", json));
})
)
String json = _task.getResult().result;
return realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCED)
.put("resultJson", json));
}))
).continueWithTask(task -> {
if (task.isFaulted()) {
return realmHelper.executeTransaction(realm -> {
......
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