Commit baa6b13a authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix coding style bugs

parent 48c08f41
...@@ -13,23 +13,26 @@ import chat.rocket.android.R; ...@@ -13,23 +13,26 @@ import chat.rocket.android.R;
import chat.rocket.android.helper.OnBackPressListener; import chat.rocket.android.helper.OnBackPressListener;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
public abstract class AbstractWebViewFragment extends AbstractFragment implements OnBackPressListener { public abstract class AbstractWebViewFragment extends AbstractFragment
implements OnBackPressListener {
private WebView webview; private WebView webview;
private WebViewClient mWebViewClient = new WebViewClient() { private WebViewClient webviewClient = new WebViewClient() {
private boolean mError; private boolean error;
@Override public void onPageStarted(WebView webview, String url, Bitmap favicon) { @Override public void onPageStarted(WebView webview, String url, Bitmap favicon) {
mError = false; error = false;
} }
@Override public void onPageFinished(WebView webview, String url) { @Override public void onPageFinished(WebView webview, String url) {
if (!mError) onPageLoaded(webview, url); if (!error) {
onPageLoaded(webview, url);
}
} }
@Override @Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error); super.onReceivedError(view, request, error);
mError = true; this.error = true;
} }
@Override public boolean shouldOverrideUrlLoading(WebView webview, String url) { @Override public boolean shouldOverrideUrlLoading(WebView webview, String url) {
...@@ -37,7 +40,8 @@ public abstract class AbstractWebViewFragment extends AbstractFragment implement ...@@ -37,7 +40,8 @@ public abstract class AbstractWebViewFragment extends AbstractFragment implement
|| super.shouldOverrideUrlLoading(webview, url); || super.shouldOverrideUrlLoading(webview, url);
} }
@DebugLog @Override @DebugLog
@Override
public void onFormResubmission(WebView view, Message dontResend, Message resend) { public void onFormResubmission(WebView view, Message dontResend, Message resend) {
//resend POST request without confirmation. //resend POST request without confirmation.
resend.sendToTarget(); resend.sendToTarget();
...@@ -61,7 +65,7 @@ public abstract class AbstractWebViewFragment extends AbstractFragment implement ...@@ -61,7 +65,7 @@ public abstract class AbstractWebViewFragment extends AbstractFragment implement
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
} }
webview.setHorizontalScrollBarEnabled(false); webview.setHorizontalScrollBarEnabled(false);
webview.setWebViewClient(mWebViewClient); webview.setWebViewClient(webviewClient);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true); WebView.setWebContentsDebuggingEnabled(true);
......
...@@ -11,6 +11,7 @@ import chat.rocket.android.fragment.AbstractWebViewFragment; ...@@ -11,6 +11,7 @@ import chat.rocket.android.fragment.AbstractWebViewFragment;
import chat.rocket.android.helper.LogcatIfError; import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.model.MeteorLoginServiceConfiguration; import chat.rocket.android.model.MeteorLoginServiceConfiguration;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import java.nio.charset.Charset;
import jp.co.crowdworks.realm_java_helpers.RealmHelper; import jp.co.crowdworks.realm_java_helpers.RealmHelper;
import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts; import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
...@@ -26,6 +27,9 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment { ...@@ -26,6 +27,9 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment {
private String url; private String url;
private boolean resultOK; private boolean resultOK;
/**
* create new Fragment with ServerConfig-ID.
*/
public static Fragment create(final String serverConfigId) { public static Fragment create(final String serverConfigId) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("server_config_id", serverConfigId); args.putString("server_config_id", serverConfigId);
...@@ -70,7 +74,7 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment { ...@@ -70,7 +74,7 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment {
.put("credentialToken", "github" + System.currentTimeMillis()) .put("credentialToken", "github" + System.currentTimeMillis())
.put("isCordova", true) .put("isCordova", true)
.toString() .toString()
.getBytes(), Base64.NO_WRAP); .getBytes(Charset.forName("UTF-8")), Base64.NO_WRAP);
return new HttpUrl.Builder().scheme("https") return new HttpUrl.Builder().scheme("https")
.host("github.com") .host("github.com")
...@@ -123,8 +127,9 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment { ...@@ -123,8 +127,9 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment {
if (url.contains(hostname) && url.contains("_oauth/github?close")) { if (url.contains(hostname) && url.contains("_oauth/github?close")) {
webview.loadUrl( final String jsHookUrl = "javascript:"
"javascript:window._rocketchet_hook.handleConfig(document.getElementById('config').innerText);"); + "window._rocketchet_hook.handleConfig(document.getElementById('config').innerText);";
webview.loadUrl(jsHookUrl);
} }
} }
...@@ -133,17 +138,17 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment { ...@@ -133,17 +138,17 @@ public class GitHubOAuthWebViewFragment extends AbstractWebViewFragment {
} }
private static final class JSInterface { private static final class JSInterface {
private final JSInterfaceCallback mCallback; private final JSInterfaceCallback jsInterfaceCallback;
public JSInterface(JSInterfaceCallback callback) { JSInterface(JSInterfaceCallback callback) {
mCallback = callback; jsInterfaceCallback = callback;
} }
@JavascriptInterface public void handleConfig(String config) { @JavascriptInterface public void handleConfig(String config) {
try { try {
mCallback.hanldeResult(new JSONObject(config)); jsInterfaceCallback.hanldeResult(new JSONObject(config));
} catch (Exception e) { } catch (Exception exception) {
mCallback.hanldeResult(null); jsInterfaceCallback.hanldeResult(null);
} }
} }
} }
......
...@@ -5,6 +5,7 @@ import android.widget.TextView; ...@@ -5,6 +5,7 @@ import android.widget.TextView;
import chat.rocket.android.R; import chat.rocket.android.R;
/** /**
* Just show "Authenticating..."
*/ */
public class AuthenticatingFragment extends AbstractServerConfigFragment { public class AuthenticatingFragment extends AbstractServerConfigFragment {
@Override protected int getLayout() { @Override protected int getLayout() {
...@@ -14,6 +15,6 @@ public class AuthenticatingFragment extends AbstractServerConfigFragment { ...@@ -14,6 +15,6 @@ public class AuthenticatingFragment extends AbstractServerConfigFragment {
@Override protected void onSetupView() { @Override protected void onSetupView() {
TextView caption = (TextView) rootView.findViewById(R.id.txt_caption); TextView caption = (TextView) rootView.findViewById(R.id.txt_caption);
caption.setVisibility(View.VISIBLE); caption.setVisibility(View.VISIBLE);
caption.setText("Authenticationg..."); caption.setText("Authenticating...");
} }
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ import chat.rocket.android.model.ServerConfigCredential; ...@@ -14,6 +14,7 @@ import chat.rocket.android.model.ServerConfigCredential;
import chat.rocket.android.renderer.ServerConfigCredentialRenderer; import chat.rocket.android.renderer.ServerConfigCredentialRenderer;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmResults; import io.realm.RealmResults;
import java.nio.charset.Charset;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.List; import java.util.List;
...@@ -56,7 +57,9 @@ public class LoginFragment extends AbstractServerConfigFragment { ...@@ -56,7 +57,9 @@ public class LoginFragment extends AbstractServerConfigFragment {
btnEmail.setOnClickListener(view -> { btnEmail.setOnClickListener(view -> {
final CharSequence username = txtUsername.getText(); final CharSequence username = txtUsername.getText();
final CharSequence passwd = txtPasswd.getText(); final CharSequence passwd = txtPasswd.getText();
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(passwd)) return; if (TextUtils.isEmpty(username) || TextUtils.isEmpty(passwd)) {
return;
}
RealmHelperBolts.executeTransaction(realm -> RealmHelperBolts.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject() realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
...@@ -75,7 +78,8 @@ public class LoginFragment extends AbstractServerConfigFragment { ...@@ -75,7 +78,8 @@ public class LoginFragment extends AbstractServerConfigFragment {
} }
private void showErrorIfNeeded() { private void showErrorIfNeeded() {
ServerConfig config = RealmHelper.executeTransactionForRead(realm -> realm.where(ServerConfig.class) ServerConfig config = RealmHelper.executeTransactionForRead(realm ->
realm.where(ServerConfig.class)
.equalTo("id", serverConfigId) .equalTo("id", serverConfigId)
.isNotNull("credential.errorMessage") .isNotNull("credential.errorMessage")
.findFirst()); .findFirst());
...@@ -105,14 +109,14 @@ public class LoginFragment extends AbstractServerConfigFragment { ...@@ -105,14 +109,14 @@ public class LoginFragment extends AbstractServerConfigFragment {
} catch (NoSuchAlgorithmException exception) { } catch (NoSuchAlgorithmException exception) {
return null; return null;
} }
messageDigest.update(orig.getBytes()); messageDigest.update(orig.getBytes(Charset.forName("UTF-8")));
StringBuilder sb = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (byte b : messageDigest.digest()) { for (byte b : messageDigest.digest()) {
sb.append(String.format("%02x", b & 0xff)); stringBuilder.append(String.format("%02x", b & 0xff));
} }
return sb.toString(); return stringBuilder.toString();
} }
private void onRenderAuthProviders(List<MeteorLoginServiceConfiguration> authProviders) { private void onRenderAuthProviders(List<MeteorLoginServiceConfiguration> authProviders) {
......
...@@ -9,6 +9,7 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts; ...@@ -9,6 +9,7 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@SuppressWarnings("PMD.ShortVariable")
public class ServerConfigCredential extends RealmObject { public class ServerConfigCredential extends RealmObject {
public static final String TYPE_EMAIL = "email"; public static final String TYPE_EMAIL = "email";
public static final String TYPE_TWITTER = "twitter"; public static final String TYPE_TWITTER = "twitter";
......
...@@ -21,7 +21,9 @@ abstract class AbstractRenderer<T> { ...@@ -21,7 +21,9 @@ abstract class AbstractRenderer<T> {
protected boolean shouldHandle(View target, Condition additionalCondition, Optional optional, protected boolean shouldHandle(View target, Condition additionalCondition, Optional optional,
String key) { String key) {
if (target == null || object == null) { if (target == null || object == null) {
if (optional != null) optional.onNoData(key); if (optional != null) {
optional.onNoData(key);
}
return false; return false;
} }
......
...@@ -5,11 +5,17 @@ import android.widget.TextView; ...@@ -5,11 +5,17 @@ import android.widget.TextView;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfigCredential; import chat.rocket.android.model.ServerConfigCredential;
/**
* renderer class for ServerConfigCredential.
*/
public class ServerConfigCredentialRenderer extends AbstractRenderer<ServerConfigCredential> { public class ServerConfigCredentialRenderer extends AbstractRenderer<ServerConfigCredential> {
public ServerConfigCredentialRenderer(Context context, ServerConfigCredential credential) { public ServerConfigCredentialRenderer(Context context, ServerConfigCredential credential) {
super(context, credential); super(context, credential);
} }
/**
* Inject username into TextView.
*/
public ServerConfigCredentialRenderer usernameInto(TextView textView) { public ServerConfigCredentialRenderer usernameInto(TextView textView) {
if (!shouldHandle(textView)) { if (!shouldHandle(textView)) {
return this; return this;
......
...@@ -129,8 +129,8 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -129,8 +129,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
} }
socketExists = true; socketExists = true;
final ServerConfig config = RealmHelper.executeTransactionForRead( final ServerConfig config = RealmHelper.executeTransactionForRead(realm ->
realm -> realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst()); realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst());
prepareWebSocket(config); prepareWebSocket(config);
return webSocketAPI.connect(config.getSession()).onSuccessTask(task -> { return webSocketAPI.connect(config.getSession()).onSuccessTask(task -> {
...@@ -180,7 +180,8 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -180,7 +180,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
for (Class clazz : REGISTERABLE_CLASSES) { for (Class clazz : REGISTERABLE_CLASSES) {
try { try {
Constructor ctor = clazz.getConstructor(Context.class, String.class, RocketChatWebSocketAPI.class); Constructor ctor = clazz.getConstructor(Context.class, String.class,
RocketChatWebSocketAPI.class);
Object obj = ctor.newInstance(appContext, serverConfigId, webSocketAPI); Object obj = ctor.newInstance(appContext, serverConfigId, webSocketAPI);
if (obj instanceof Registerable) { if (obj instanceof Registerable) {
......
...@@ -102,25 +102,30 @@ public class RocketChatWebSocketAPI { ...@@ -102,25 +102,30 @@ public class RocketChatWebSocketAPI {
.put("credentialToken", credential.getCredentialToken()) .put("credentialToken", credential.getCredentialToken())
.put("credentialSecret", credential.getCredentialSecret())); .put("credentialSecret", credential.getCredentialSecret()));
} }
} } catch (JSONException exception) {
catch (JSONException e) { return Task.forError(exception);
return Task.forError(e);
} }
return ddpClient.rpc("login", new JSONArray().put(param), generateId("login")); return ddpClient.rpc("login", new JSONArray().put(param), generateId("login"));
} }
/**
* Login with token.
*/
public Task<DDPClientCallback.RPC> loginWithToken(final String token) { public Task<DDPClientCallback.RPC> loginWithToken(final String token) {
JSONObject param = new JSONObject(); JSONObject param = new JSONObject();
try { try {
param.put("resume", token); param.put("resume", token);
} catch (JSONException e) { } catch (JSONException exception) {
return Task.forError(e); return Task.forError(exception);
} }
return ddpClient.rpc("login", new JSONArray().put(param), generateId("login-token")); return ddpClient.rpc("login", new JSONArray().put(param), generateId("login-token"));
} }
/**
* Logout.
*/
public Task<DDPClientCallback.RPC> logout() { public Task<DDPClientCallback.RPC> logout() {
return ddpClient.rpc("logout", null, generateId("logout")); return ddpClient.rpc("logout", null, generateId("logout"));
} }
......
...@@ -27,12 +27,6 @@ ...@@ -27,12 +27,6 @@
<property name="eachLine" value="true"/> <property name="eachLine" value="true"/>
</module> </module>
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE:OFF (\w+)"/>
<property name="onCommentFormat" value="CHECKSTYLE:ON (\w+)"/>
<property name="checkFormat" value="$1"/>
</module>
<module name="SuppressionFilter"> <module name="SuppressionFilter">
<property name="file" value="config/quality/checkstyle/checkstyle-suppressions.xml"/> <property name="file" value="config/quality/checkstyle/checkstyle-suppressions.xml"/>
</module> </module>
......
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