From 40270f4da4e81aeba3b187311bda1ce222470069 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 5 Dec 2017 20:53:33 +0900 Subject: [PATCH] Update dependencies, clean code --- app/build.gradle | 25 +++++++++---------- .../activities/FolderPickerActivity.java | 7 +----- .../activities/ShareActivity.java | 6 ++--- .../activities/StateDialogActivity.java | 5 ++-- .../activities/SyncthingActivity.java | 4 +-- .../syncthingandroid/http/ApiRequest.java | 23 ++++++----------- .../receiver/AppConfigReceiver.java | 4 +-- .../PowerSaveModeChangedReceiver.java | 1 - .../syncthingandroid/service/Constants.java | 4 +-- .../service/NotificationHandler.java | 2 +- .../syncthingandroid/service/RestApi.java | 4 +-- .../service/SyncthingRunnable.java | 2 +- .../syncthingandroid/util/Languages.java | 1 - build.gradle | 3 +-- 14 files changed, 36 insertions(+), 55 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d8015b7d..4d263857 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,22 +1,21 @@ apply plugin: 'com.android.application' apply plugin: 'com.github.ben-manes.versions' apply plugin: 'com.github.triplet.play' -apply plugin: 'me.tatarka.retrolambda' dependencies { - compile 'eu.chainfire:libsuperuser:1.0.0.201704021214' - compile 'com.android.support:design:27.0.1' - compile 'com.google.zxing:android-integration:3.3.0' - compile 'com.google.code.gson:gson:2.8.2' - compile 'org.mindrot:jbcrypt:0.4' - compile 'com.google.guava:guava:20.0' - compile 'com.annimon:stream:1.1.9' - compile 'com.android.volley:volley:1.0.0' - compile 'com.android.support.constraint:constraint-layout:1.0.2' - compile "com.google.dagger:dagger:2.13" + implementation 'eu.chainfire:libsuperuser:1.0.0.201704021214' + implementation 'com.android.support:design:27.0.2' + implementation 'com.google.zxing:android-integration:3.3.0' + implementation 'com.google.code.gson:gson:2.8.2' + implementation 'org.mindrot:jbcrypt:0.4' + implementation 'com.google.guava:guava:20.0' + implementation 'com.annimon:stream:1.1.9' + implementation 'com.android.volley:volley:1.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation "com.google.dagger:dagger:2.13" annotationProcessor "com.google.dagger:dagger-compiler:2.13" - androidTestCompile 'com.android.support.test:rules:1.0.1' - androidTestCompile 'com.android.support:support-annotations:27.0.1' + androidTestImplementation 'com.android.support.test:rules:1.0.1' + androidTestImplementation 'com.android.support:support-annotations:27.0.2' } android { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java index 1f7a6dbb..26b0e387 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java @@ -16,7 +16,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.text.TextUtils; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -35,16 +34,12 @@ import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.util.Util; -import org.w3c.dom.Text; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; -import javax.inject.Inject; - /** * Activity that allows selecting a directory in the local file system. */ @@ -54,7 +49,7 @@ public class FolderPickerActivity extends SyncthingActivity private static final String EXTRA_INITIAL_DIRECTORY = "com.nutomic.syncthingandroid.activities.FolderPickerActivity.INITIAL_DIRECTORY"; - public static final String EXTRA_ROOT_DIRECTORY = + private static final String EXTRA_ROOT_DIRECTORY = "com.nutomic.syncthingandroid.activities.FolderPickerActivity.ROOT_DIRECTORY"; public static final String EXTRA_RESULT_DIRECTORY = diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java index c58ed20c..2fbf467f 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/ShareActivity.java @@ -274,9 +274,9 @@ public class ShareActivity extends StateDialogActivity private class CopyFilesTask extends AsyncTask { private ProgressDialog mProgress; - private Map mFiles; - private Folder mFolder; - private File mDirectory; + private final Map mFiles; + private final Folder mFolder; + private final File mDirectory; private int mCopied = 0, mIgnored = 0; CopyFilesTask(Map files, Folder folder, File directory) { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java index 17d2865e..9e247345 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/StateDialogActivity.java @@ -127,9 +127,8 @@ public abstract class StateDialogActivity extends SyncthingActivity { return; binding.loadingSlowMessage.setVisibility(View.VISIBLE); - binding.viewLogs.setOnClickListener(v -> { - startActivity(new Intent(this, LogActivity.class)); - }); + binding.viewLogs.setOnClickListener(v -> + startActivity(new Intent(this, LogActivity.class))); }, SLOW_LOADING_TIME); } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java index 8db8b828..6df1350d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java @@ -83,7 +83,7 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser /** * Used for Fragments to use the Activity's service connection. */ - public void registerOnServiceConnectedListener(OnServiceConnectedListener listener) { + void registerOnServiceConnectedListener(OnServiceConnectedListener listener) { if (mSyncthingService != null) { listener.onServiceConnected(); } else { @@ -94,7 +94,7 @@ public abstract class SyncthingActivity extends AppCompatActivity implements Ser /** * Returns service object (or null if not bound). */ - public SyncthingService getService() { + SyncthingService getService() { return mSyncthingService; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java b/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java index 56d04153..e7cad0a3 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/http/ApiRequest.java @@ -1,7 +1,6 @@ package com.nutomic.syncthingandroid.http; -import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; @@ -30,10 +29,8 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Map; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; @@ -73,14 +70,14 @@ public abstract class ApiRequest { private final String mPath; private final String mApiKey; - public ApiRequest(Context context, URL url, String path, String apiKey) { + ApiRequest(Context context, URL url, String path, String apiKey) { mContext = context; mUrl = url; mPath = path; mApiKey = apiKey; } - protected Uri buildUri(Map params) { + Uri buildUri(Map params) { Uri.Builder uriBuilder = Uri.parse(mUrl.toString()) .buildUpon() .path(mPath); @@ -93,8 +90,8 @@ public abstract class ApiRequest { /** * Opens the connection, then returns success status and response string. */ - protected void connect(int requestMethod, Uri uri, @Nullable String requestBody, - @Nullable OnSuccessListener listener, @Nullable OnErrorListener errorListener) { + void connect(int requestMethod, Uri uri, @Nullable String requestBody, + @Nullable OnSuccessListener listener, @Nullable OnErrorListener errorListener) { StringRequest request = new StringRequest(requestMethod, uri.toString(), reply -> { if (listener != null) listener.onSuccess(reply); @@ -125,8 +122,8 @@ public abstract class ApiRequest { /** * Opens the connection, then returns success status and response bitmap. */ - protected void makeImageRequest(Uri uri, @Nullable OnImageSuccessListener imageListener, - @Nullable OnErrorListener errorListener) { + void makeImageRequest(Uri uri, @Nullable OnImageSuccessListener imageListener, + @Nullable OnErrorListener errorListener) { ImageRequest imageRequest = new ImageRequest(uri.toString(), bitmap -> { if (imageListener != null) { imageListener.onImageSuccess(bitmap); @@ -158,13 +155,7 @@ public abstract class ApiRequest { @Override protected HttpURLConnection createConnection(URL url) throws IOException { HttpsURLConnection connection = (HttpsURLConnection) super.createConnection(url); - connection.setHostnameVerifier(new HostnameVerifier() { - @SuppressLint("BadHostnameVerifier") - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }); + connection.setHostnameVerifier((hostname, session) -> true); return connection; } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/receiver/AppConfigReceiver.java b/app/src/main/java/com/nutomic/syncthingandroid/receiver/AppConfigReceiver.java index f32972e9..e1766d4f 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/receiver/AppConfigReceiver.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/receiver/AppConfigReceiver.java @@ -19,14 +19,14 @@ public class AppConfigReceiver extends BroadcastReceiver { /** * Start the Syncthing-Service */ - public static final String ACTION_START = "com.nutomic.syncthingandroid.action.START"; + private static final String ACTION_START = "com.nutomic.syncthingandroid.action.START"; /** * Stop the Syncthing-Service * If alwaysRunInBackground is enabled the service must not be stopped. Instead a * notification is presented to the user. */ - public static final String ACTION_STOP = "com.nutomic.syncthingandroid.action.STOP"; + private static final String ACTION_STOP = "com.nutomic.syncthingandroid.action.STOP"; @Inject NotificationHandler mNotificationHandler; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/receiver/PowerSaveModeChangedReceiver.java b/app/src/main/java/com/nutomic/syncthingandroid/receiver/PowerSaveModeChangedReceiver.java index d17d96f3..5d66d230 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/receiver/PowerSaveModeChangedReceiver.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/receiver/PowerSaveModeChangedReceiver.java @@ -8,7 +8,6 @@ import android.os.PowerManager; import android.support.v4.content.LocalBroadcastManager; import com.nutomic.syncthingandroid.service.DeviceStateHolder; -import com.nutomic.syncthingandroid.service.SyncthingService; public class PowerSaveModeChangedReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java index 87cfd198..55591eed 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/Constants.java @@ -31,7 +31,7 @@ public class Constants { /** * File in the config folder that contains configuration. */ - static String CONFIG_FILE = "config.xml"; + static final String CONFIG_FILE = "config.xml"; public static File getConfigFile(Context context) { return new File(context.getFilesDir(), CONFIG_FILE); @@ -40,7 +40,7 @@ public class Constants { /** * Name of the public key file in the data directory. */ - static String PUBLIC_KEY_FILE = "cert.pem"; + static final String PUBLIC_KEY_FILE = "cert.pem"; static File getPublicKeyFile(Context context) { return new File(context.getFilesDir(), PUBLIC_KEY_FILE); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/NotificationHandler.java b/app/src/main/java/com/nutomic/syncthingandroid/service/NotificationHandler.java index 1168c96c..e846e867 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/NotificationHandler.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/NotificationHandler.java @@ -25,7 +25,7 @@ public class NotificationHandler { private static final int ID_RESTART = 2; private static final int ID_STOP_BACKGROUND_WARNING = 3; private static final int ID_CRASH = 9; - public static final String CHANNEL_PERSISTENT = "01_syncthing_persistent"; + private static final String CHANNEL_PERSISTENT = "01_syncthing_persistent"; private static final String CHANNEL_INFO = "02_syncthing_notifications"; private final Context mContext; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index c055b5c8..78864896 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -471,8 +471,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, /** * Normalizes a given device ID. */ - public void normalizeDeviceId(String id, OnResultListener1 listener, - OnResultListener1 errorListener) { + private void normalizeDeviceId(String id, OnResultListener1 listener, + OnResultListener1 errorListener) { new GetRequest(mContext, mUrl, GetRequest.URI_DEVICEID, mApiKey, ImmutableMap.of("id", id), result -> { JsonObject json = new JsonParser().parse(result).getAsJsonObject(); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java index 367c9b52..71e73870 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java @@ -355,7 +355,7 @@ public class SyncthingRunnable implements Runnable { } private HashMap buildEnvironment() { - HashMap targetEnv = new HashMap(); + HashMap targetEnv = new HashMap<>(); // Set home directory to data folder for web GUI folder picker. targetEnv.put("HOME", Environment.getExternalStorageDirectory().getAbsolutePath()); targetEnv.put("STTRACE", mPreferences.getString("sttrace", "")); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/Languages.java b/app/src/main/java/com/nutomic/syncthingandroid/util/Languages.java index 148b9d01..f3d60f5e 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/Languages.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/Languages.java @@ -9,7 +9,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; -import android.preference.PreferenceManager; import android.text.TextUtils; import com.nutomic.syncthingandroid.R; diff --git a/build.gradle b/build.gradle index 05a0ece3..18dae1e3 100644 --- a/build.gradle +++ b/build.gradle @@ -8,10 +8,9 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.github.triplet.gradle:play-publisher:1.2.0' classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0' - classpath 'me.tatarka:gradle-retrolambda:3.7.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files