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