Permalink
Browse files

Some code cleanup and updated libs

  • Loading branch information...
Miggets7 committed Nov 27, 2018
1 parent 1ab0d7d commit 7592edb430726c894f56e82c2eccdd5e4e8b5c7b
@@ -1,59 +1,10 @@
buildscript {
ext.kotlin_version = '1.2.51'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
maven {
url 'https://dl.bintray.com/kotlin/kotlin-dev/'
}
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "http://m2repo.openremote.com/content/groups/public/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "com.google.gms:google-services:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
apply plugin: "com.android.library"
apply plugin: 'kotlin-android'
version = projectVersion
dependencies {
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
api "com.android.support:support-compat:$androidSupportVersion"
api "com.android.support:appcompat-v7:$androidSupportVersion"
api "com.google.firebase:firebase-core:$fcmVersion"
implementation "com.google.firebase:firebase-messaging:$fcmVersion"
implementation "com.squareup.retrofit2:converter-jackson:$jacksonVersion"
implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
implementation "com.google.android.gms:play-services-location:$googlePlayVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
android {
compileSdkVersion Integer.valueOf(androidCompileVersion)
buildToolsVersion androidBuildToolsVersion
@@ -87,5 +38,18 @@ android {
buildTypes {
}
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.3'
}
dependencies {
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
api "com.android.support:support-compat:$androidSupportVersion"
api "com.android.support:appcompat-v7:$androidSupportVersion"
api "com.google.firebase:firebase-core:$fcmVersion"
implementation "com.google.firebase:firebase-messaging:$fcmVersion"
implementation "com.squareup.retrofit2:converter-jackson:$jacksonVersion"
implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
implementation "com.google.android.gms:play-services-location:$googlePlayVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
@@ -30,16 +30,6 @@
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/OR_CONSOLE_NAME"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service
android:name="org.openremote.android.ORFirebaseMessagingService">
@@ -119,10 +119,10 @@ protected String getClientUrl() {
}
return getString(R.string.OR_BASE_SERVER) + getString(R.string.OR_CONSOLE_URL)
+ "?consolePlatform=" + platform
+ "&consoleName=" + name
+ "&consoleVersion=" + version
+ "&consoleProviders=" + providers;
+ "?consolePlatform=" + platform
+ "&consoleName=" + name
+ "&consoleVersion=" + version
+ "&consoleProviders=" + providers;
}
@Override
@@ -150,7 +150,7 @@ protected void onCreate(Bundle savedInstanceState) {
try {
String timeoutStr = getString(R.string.OR_CONSOLE_LOAD_TIMEOUT);
webViewTimeout = Integer.parseInt(timeoutStr);
} catch(NumberFormatException nfe) {
} catch (NumberFormatException nfe) {
System.out.println("Could not parse console load timeout value: " + nfe);
}
@@ -283,17 +283,16 @@ public boolean onLongClick(View v) {
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
// When initialising Keycloak with an invalid offline refresh token (e.g. wrong nonce because
// server was reinstalled), we detect the failure and then don't show an error view. We clear the stored
// invalid token. The web app will then start a new login.
if (request.getUrl().getLastPathSegment() != null &&
request.getUrl().getLastPathSegment().equals("token") &&
request.getMethod().equals("POST") &&
errorResponse.getStatusCode() == 400) {
request.getUrl().getLastPathSegment().equals("token") &&
request.getMethod().equals("POST") &&
errorResponse.getStatusCode() == 400) {
webAppInterface.tokenService.clearToken();
return;
}
@@ -333,16 +332,16 @@ public void onReceivedError(WebView view, WebResourceRequest request, WebResourc
}
handleError(
error.getErrorCode(), error.getDescription().toString(),
request.getUrl().toString(), request.isForMainFrame());
error.getErrorCode(), error.getDescription().toString(),
request.getUrl().toString(), request.isForMainFrame());
}
@Override
public void onPageStarted(WebView view, final String url, Bitmap favicon) {
Runnable run = new Runnable() {
public void run() {
if(!webViewLoaded) {
if (!webViewLoaded) {
handleError(ERROR_TIMEOUT, "Connection timed out", url, true);
}
}
@@ -378,8 +377,8 @@ protected void handleError(int errorCode, String description, String failingUrl,
//TODO should we always ignore image errors?
if (failingUrl != null && (failingUrl.endsWith("png")
|| failingUrl.endsWith("jpg")
|| failingUrl.endsWith("ico"))) {
|| failingUrl.endsWith("jpg")
|| failingUrl.endsWith("ico"))) {
LOG.info("Ignoring error loading image resource");
return;
}
@@ -418,7 +417,7 @@ public void onDownloadStart(String url, String userAgent, String contentDisposit
ActivityCompat.requestPermissions((MainActivity) context, new String[]{writePermission}, WRITE_PERMISSION_FOR_DOWNLOAD);
} else {
DownloadManager.Request request = new
DownloadManager.Request(Uri.parse(url));
DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimetype);
//------------------------COOKIE!!------------------------
@@ -463,28 +462,28 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
geofenceProvider.enable(MainActivity.this,
String.format("%s/%s",
getString(R.string.OR_BASE_SERVER),
getString(R.string.OR_REALM)),
consoleId,
new GeofenceProvider.EnableCallback() {
@Override
public void accept(@NotNull Map<String, ?> responseData) {
try {
final String jsonString = new ObjectMapper().writeValueAsString(responseData);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.evaluateJavascript(String.format(
"openremote.INSTANCE.console.handleProviderResponse('%s')",
jsonString), null);
}
});
} catch (Exception e) {
e.printStackTrace();
}
String.format("%s/%s",
getString(R.string.OR_BASE_SERVER),
getString(R.string.OR_REALM)),
consoleId,
new GeofenceProvider.EnableCallback() {
@Override
public void accept(@NotNull Map<String, ?> responseData) {
try {
final String jsonString = new ObjectMapper().writeValueAsString(responseData);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.evaluateJavascript(String.format(
"openremote.INSTANCE.console.handleProviderResponse('%s')",
jsonString), null);
}
});
} catch (Exception e) {
e.printStackTrace();
}
});
}
});
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@@ -561,15 +560,15 @@ protected void handleGeofenceProviderMessage(String action, JSONObject data) thr
if (consoleId != null) {
((MainActivity) activity).consoleId = consoleId;
geofenceProvider.enable(MainActivity.this, String.format("%s/%s",
getString(R.string.OR_BASE_SERVER),
getString(R.string.OR_REALM)),
consoleId, new GeofenceProvider.EnableCallback() {
@Override
public void accept(@NotNull Map<String, ?> responseData) {
//noinspection unchecked
notifyClient((Map<String, Object>) responseData);
}
});
getString(R.string.OR_BASE_SERVER),
getString(R.string.OR_REALM)),
consoleId, new GeofenceProvider.EnableCallback() {
@Override
public void accept(@NotNull Map<String, ?> responseData) {
//noinspection unchecked
notifyClient((Map<String, Object>) responseData);
}
});
}
}
} else if (action.equalsIgnoreCase("PROVIDER_DISABLE")) {
@@ -662,7 +661,7 @@ protected void onConnectivityChanged(boolean connectivity) {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager cm
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
onConnectivityChanged(activeNetwork != null && activeNetwork.isConnectedOrConnecting());
@@ -1,16 +1,16 @@
package org.openremote.android.service;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import retrofit2.http.Path;
import java.util.Map;
public interface OAuth2Service {
@FormUrlEncoded
@POST("/auth/realms/{realm}/protocol/openid-connect/token")
Call<Map<String,String>> refreshToken(@Path("realm") String realm, @Field("grant_type") String grantType, @Field("client_id") String clientId, @Field("refresh_token") String refreshToken);
Call<Map<String, String>> refreshToken(@Path("realm") String realm, @Field("grant_type") String grantType, @Field("client_id") String clientId, @Field("refresh_token") String refreshToken);
}
@@ -1,9 +1,6 @@
package org.openremote.android.service;
import java.util.List;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.http.*;
@@ -2,7 +2,7 @@
import java.io.IOException;
interface TokenCallback {
public interface TokenCallback {
void onToken(String accessToken) throws IOException;
void onFailure(Throwable t);
Oops, something went wrong.

0 comments on commit 7592edb

Please sign in to comment.