Commit feb65d69 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix code style

parent ffd30513
......@@ -14,7 +14,7 @@ public class LaunchUtil {
public static void showServerConfigActivity(Context context, String serverCondigId) {
Intent intent = new Intent(context, ServerConfigActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("id", serverCondigId);
intent.putExtra("serverConfigId", serverCondigId);
context.startActivity(intent);
}
}
......@@ -11,7 +11,7 @@ import chat.rocket.android.fragment.chatroom.HomeFragment;
import chat.rocket.android.fragment.chatroom.RoomFragment;
import chat.rocket.android.helper.Avatar;
import chat.rocket.android.layouthelper.chatroom.RoomListManager;
import chat.rocket.android.model.RoomSubscription;
import chat.rocket.android.model.ddp.RoomSubscription;
import com.jakewharton.rxbinding.view.RxView;
import com.jakewharton.rxbinding.widget.RxCompoundButton;
import io.realm.Realm;
......
......@@ -27,7 +27,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
private RealmObjectObserver<ServerConfig> serverConfigObserver =
new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", serverConfigId);
return realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId);
}
@Override protected void onChange(ServerConfig config) {
......@@ -69,7 +69,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
private static boolean launchFor(Context context, ServerConfig config) {
LaunchUtil.showServerConfigActivity(context, config.getId());
LaunchUtil.showServerConfigActivity(context, config.getServerConfigId());
return true;
}
......@@ -86,7 +86,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return;
}
serverConfigId = intent.getStringExtra("id");
serverConfigId = intent.getStringExtra("serverConfigId");
if (TextUtils.isEmpty(serverConfigId)) {
finish();
return;
......@@ -154,7 +154,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
if (args == null) {
args = new Bundle();
}
args.putString("id", serverConfigId);
args.putString("serverConfigId", serverConfigId);
fragment.setArguments(args);
}
......
......@@ -3,7 +3,7 @@ package chat.rocket.android.fragment.chatroom;
import android.os.Bundle;
import android.support.annotation.Nullable;
import chat.rocket.android.R;
import chat.rocket.android.model.RoomSubscription;
import chat.rocket.android.model.ddp.RoomSubscription;
import io.realm.Realm;
import io.realm.RealmQuery;
import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
......
......@@ -9,7 +9,7 @@ import android.webkit.WebView;
import chat.rocket.android.fragment.AbstractWebViewFragment;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.model.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ServerConfig;
import java.nio.charset.Charset;
import jp.co.crowdworks.realm_java_helpers.RealmHelper;
......@@ -51,7 +51,7 @@ public class GitHubOAuthFragment extends AbstractWebViewFragment {
serverConfigId = args.getString("serverConfigId");
ServerConfig serverConfig = RealmHelper.executeTransactionForRead(realm ->
realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst());
realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId).findFirst());
MeteorLoginServiceConfiguration oauthConfig = RealmHelper.executeTransactionForRead(realm ->
realm.where(MeteorLoginServiceConfiguration.class)
.equalTo("service", "github")
......
......@@ -21,7 +21,7 @@ abstract class AbstractServerConfigFragment extends AbstractFragment
return;
}
serverConfigId = args.getString("id");
serverConfigId = args.getString("serverConfigId");
if (TextUtils.isEmpty(serverConfigId)) {
finish();
return;
......
......@@ -25,7 +25,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
};
RealmObjectObserver<ServerConfig> serverConfigObserver = new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", serverConfigId);
return realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId);
}
@Override protected void onChange(ServerConfig config) {
......@@ -54,7 +54,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", serverConfigId)
new JSONObject().put("serverConfigId", serverConfigId)
.put("hostname", hostname)
.put("connectionError", JSONObject.NULL)
.put("session", JSONObject.NULL))).continueWith(new LogcatIfError());
......@@ -91,7 +91,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
private void clearConnectionErrorAndHostname() {
RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", serverConfigId)
new JSONObject().put("serverConfigId", serverConfigId)
.put("hostname", JSONObject.NULL)
.put("connectionError", JSONObject.NULL))).continueWith(new LogcatIfError());
}
......
......@@ -7,7 +7,7 @@ import chat.rocket.android.R;
import chat.rocket.android.fragment.oauth.GitHubOAuthFragment;
import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import io.realm.Realm;
import io.realm.RealmResults;
import java.util.List;
......
......@@ -4,7 +4,7 @@ import android.util.Patterns;
import bolts.Continuation;
import bolts.Task;
import chat.rocket.android.model.MethodCall;
import chat.rocket.android.model.RoomSubscription;
import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.ws.RocketChatWebSocketAPI;
import java.util.UUID;
......@@ -96,7 +96,7 @@ public class MethodCallHelper {
private Task<Void> saveToken(Task<String> task) {
return RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", serverConfigId)
.put("serverConfigId", serverConfigId)
.put("token", task.getResult())
.put("tokenVerified", true)));
}
......
......@@ -3,7 +3,7 @@ package chat.rocket.android.layouthelper.chatroom;
import android.view.View;
import android.view.ViewGroup;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.RoomSubscription;
import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.widget.internal.RoomListItemView;
import java.util.List;
......
......@@ -14,22 +14,21 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import org.json.JSONException;
import org.json.JSONObject;
@SuppressWarnings("PMD.ShortVariable")
public class MethodCall extends RealmObject {
@PrimaryKey private String id;
@PrimaryKey private String methodCallId;
private String serverConfigId; //not ServerConfig!(not to be notified the change of ServerConfig)
private int syncstate;
private String name;
private String paramsJson;
private String resultJson;
public String getId() {
return id;
public String getMethodCallId() {
return methodCallId;
}
public void setId(String id) {
this.id = id;
public void setMethodCallId(String methodCallId) {
this.methodCallId = methodCallId;
}
public String getServerConfigId() {
......@@ -82,12 +81,15 @@ public class MethodCall extends RealmObject {
}
}
/**
* insert a new record to request a method call.
*/
public static Task<JSONObject> execute(String serverConfigId, String name, String paramsJson) {
final String newId = UUID.randomUUID().toString();
TaskCompletionSource<JSONObject> task = new TaskCompletionSource<>();
RealmHelperBolts.executeTransaction(realm -> {
MethodCall call = realm.createObjectFromJson(MethodCall.class, new JSONObject()
.put("id", newId)
.put("methodCallId", newId)
.put("serverConfigId", serverConfigId)
.put("syncstate", SyncState.NOT_SYNCED)
.put("name", name));
......@@ -99,7 +101,7 @@ public class MethodCall extends RealmObject {
} else {
new RealmObjectObserver<MethodCall>() {
@Override protected RealmQuery<MethodCall> query(Realm realm) {
return realm.where(MethodCall.class).equalTo("id", newId);
return realm.where(MethodCall.class).equalTo("methodCallId", newId);
}
@Override protected void onChange(MethodCall methodCall) {
......@@ -111,10 +113,10 @@ public class MethodCall extends RealmObject {
} catch (JSONException exception) {
task.setError(new Error(exception));
}
exit(methodCall.getId());
exit(methodCall.getMethodCallId());
} else if (syncstate == SyncState.FAILED) {
task.setError(new Error(methodCall.getResultJson()));
exit(methodCall.getId());
exit(methodCall.getMethodCallId());
}
}
......@@ -129,8 +131,14 @@ public class MethodCall extends RealmObject {
return task.getTask();
}
public static final Task<Void> remove(String id) {
/**
* remove the request.
*/
public static final Task<Void> remove(String methodCallId) {
return RealmHelperBolts.executeTransaction(realm ->
realm.where(MethodCall.class).equalTo("id", id).findAll().deleteAllFromRealm());
realm.where(MethodCall.class)
.equalTo("methodCallId", methodCallId)
.findAll()
.deleteAllFromRealm());
}
}
......@@ -15,9 +15,8 @@ import org.json.JSONObject;
/**
* Server configuration.
*/
@SuppressWarnings("PMD.ShortVariable")
public class ServerConfig extends RealmObject {
@PrimaryKey private String id;
@PrimaryKey private String serverConfigId;
private String hostname;
private String connectionError;
private String session;
......@@ -28,6 +27,9 @@ public class ServerConfig extends RealmObject {
return realm.where(ServerConfig.class).equalTo("tokenVerified", false);
}
/**
* Check if connection login required exists.
*/
public static boolean hasLoginRequiredConnection() {
ServerConfig config =
RealmHelper.executeTransactionForRead(realm ->
......@@ -36,6 +38,9 @@ public class ServerConfig extends RealmObject {
return config != null;
}
/**
* Request token refresh.
*/
public static Task<Void> forceInvalidateToken() {
return RealmHelperBolts.executeTransaction(realm -> {
RealmResults<ServerConfig> targetConfigs = realm.where(ServerConfig.class)
......@@ -49,21 +54,24 @@ public class ServerConfig extends RealmObject {
});
}
@DebugLog public static void logConnectionError(String id, Exception exception) {
/**
* Log the server connection is lost due to soem exception.
*/
@DebugLog public static void logConnectionError(String serverConfigId, Exception exception) {
RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", id)
.put("serverConfigId", serverConfigId)
.put("connectionError", exception.getMessage())
.put("session", JSONObject.NULL)))
.continueWith(new LogcatIfError());
}
public String getId() {
return id;
public String getServerConfigId() {
return serverConfigId;
}
public void setId(String id) {
this.id = id;
public void setServerConfigId(String serverConfigId) {
this.serverConfigId = serverConfigId;
}
public String getHostname() {
......
package chat.rocket.android.model;
package chat.rocket.android.model.ddp;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
/**
* Login-User's email
* Login-User's email.
*/
public class Email extends RealmObject {
@PrimaryKey private String address;
......
package chat.rocket.android.model;
package chat.rocket.android.model.ddp;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
......
package chat.rocket.android.model;
package chat.rocket.android.model.ddp;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
......
package chat.rocket.android.model;
package chat.rocket.android.model.ddp;
import io.realm.RealmList;
import io.realm.RealmObject;
......
......@@ -88,7 +88,7 @@ public class RocketChatService extends Service {
String serverConfigId = entry.getKey();
boolean found = false;
for (ServerConfig config : configList) {
if (serverConfigId.equals(config.getId())) {
if (serverConfigId.equals(config.getServerConfigId())) {
found = true;
break;
}
......@@ -111,7 +111,7 @@ public class RocketChatService extends Service {
}
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String serverConfigId = config.getId();
final String serverConfigId = config.getServerConfigId();
if (webSocketThreads.containsKey(serverConfigId)) {
return Task.forResult(webSocketThreads.get(serverConfigId));
} else {
......
......@@ -9,8 +9,8 @@ import bolts.TaskCompletionSource;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.service.ddp_subscriber.ActiveUsersSubscriber;
import chat.rocket.android.service.ddp_subscriber.LoginServiceConfigurationSubscriber;
import chat.rocket.android.service.ddp.ActiveUsersSubscriber;
import chat.rocket.android.service.ddp.LoginServiceConfigurationSubscriber;
import chat.rocket.android.service.observer.MethodCallObserver;
import chat.rocket.android.service.observer.SessionObserver;
import chat.rocket.android.service.observer.TokenLoginObserver;
......@@ -55,7 +55,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
@DebugLog public static Task<RocketChatWebSocketThread> getStarted(Context appContext,
ServerConfig config) {
TaskCompletionSource<RocketChatWebSocketThread> task = new TaskCompletionSource<>();
new RocketChatWebSocketThread(appContext, config.getId()) {
new RocketChatWebSocketThread(appContext, config.getServerConfigId()) {
@Override protected void onLooperPrepared() {
try {
super.onLooperPrepared();
......@@ -136,14 +136,14 @@ public class RocketChatWebSocketThread extends HandlerThread {
socketExists = true;
final ServerConfig config = RealmHelper.executeTransactionForRead(realm ->
realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst());
realm.where(ServerConfig.class).equalTo("serverConfigId", serverConfigId).findFirst());
prepareWebSocket(config);
return webSocketAPI.connect(config.getSession()).onSuccessTask(task -> {
final String session = task.getResult().session;
RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", serverConfigId)
.put("serverConfigId", serverConfigId)
.put("session", session))
).continueWith(new LogcatIfError());
return task;
......
package chat.rocket.android.service.ddp_subscriber;
package chat.rocket.android.service.ddp;
import android.content.Context;
import android.text.TextUtils;
......
package chat.rocket.android.service.ddp_subscriber;
package chat.rocket.android.service.ddp;
import android.content.Context;
import chat.rocket.android.model.User;
import chat.rocket.android.model.ddp.User;
import chat.rocket.android.ws.RocketChatWebSocketAPI;
import io.realm.RealmObject;
/**
* "activeUsers" subscriber.
*/
public class ActiveUsersSubscriber extends AbstractDDPDocEventSubscriber {
public ActiveUsersSubscriber(Context context, String serverConfigId,
......
package chat.rocket.android.service.ddp_subscriber;
package chat.rocket.android.service.ddp;
import android.content.Context;
import chat.rocket.android.model.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration;
import chat.rocket.android.ws.RocketChatWebSocketAPI;
import io.realm.RealmObject;
......
......@@ -58,19 +58,19 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
}
MethodCall call = list.get(0);
final String methodCallId = call.getId();
final String methodCallId = call.getMethodCallId();
final String methodName = call.getName();
final String params = call.getParamsJson();
RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId)
.put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCING))
).onSuccessTask(task ->
webSocketAPI.rpc(methodCallId, methodName, params).onSuccessTask(_task ->
RealmHelperBolts.executeTransaction(realm -> {
JSONObject result = _task.getResult().result;
return realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId)
.put("methodCallId", methodCallId)
.put("syncstate", SyncState.SYNCED)
.put("resultJson", result == null ? null : result.toString()));
})
......@@ -83,7 +83,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
? ((DDPClientCallback.RPC.Error) exception).error.toString()
: exception.getMessage();
realm.createOrUpdateObjectFromJson(MethodCall.class, new JSONObject()
.put("id", methodCallId)
.put("methodCallId", methodCallId)
.put("syncstate", SyncState.FAILED)
.put("resultJson", errMessage));
return null;
......
......@@ -3,7 +3,7 @@ package chat.rocket.android.service.observer;
import android.content.Context;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.MethodCallHelper;
import chat.rocket.android.model.RoomSubscription;
import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.ws.RocketChatWebSocketAPI;
import hugo.weaving.DebugLog;
......@@ -25,7 +25,7 @@ public class SessionObserver extends AbstractModelObserver<ServerConfig> {
@Override protected RealmResults<ServerConfig> queryItems(Realm realm) {
return realm.where(ServerConfig.class)
.equalTo("id", serverConfigId)
.equalTo("serverConfigId", serverConfigId)
.isNotNull("hostname")
.isNull("connectionError")
.isNotNull("session")
......
......@@ -6,5 +6,5 @@
<!-- suppress some checks for classes extending RealmObject -->
<suppress
checks="JavadocMethod|MemberName|ParameterName"
files="chat[\\/]rocket[\\/]android[\\/]model"/>
files="chat[\\/]rocket[\\/]android[\\/]model[\\/]ddp"/>
</suppressions>
\ 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