From d8a05ed3923f74b3b217ae0f5161422386021a3b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 21 Sep 2016 12:34:19 +0900 Subject: [PATCH] Fixed various lint issues --- build.gradle | 8 ++ .../syncthingandroid/test/MockContext.java | 4 +- .../syncthingandroid/test/MockRestApi.java | 3 +- .../test/MockSyncthingService.java | 2 +- .../test/activities/MainActivityTest.java | 2 +- .../test/syncthing/BatteryReceiverTest.java | 1 - .../test/syncthing/BootReceiverTest.java | 1 - .../test/syncthing/DeviceStateHolderTest.java | 1 - .../test/syncthing/GetTaskTest.java | 1 - .../test/syncthing/NetworkReceiverTest.java | 1 - .../test/syncthing/RestApiTest.java | 9 +- .../test/syncthing/SyncthingRunnableTest.java | 1 - .../syncthing/SyncthingServiceBinderTest.java | 1 - .../test/util/ConfigXmlTest.java | 6 -- .../test/util/FolderObserverTest.java | 1 - .../activities/FirstStartActivity.java | 2 - .../activities/FolderPickerActivity.java | 43 +++----- .../activities/LogActivity.java | 11 +- .../activities/MainActivity.java | 89 ++++++---------- .../activities/RestartActivity.java | 28 ++--- .../activities/SettingsActivity.java | 8 +- .../activities/SyncthingActivity.java | 2 +- .../fragments/DeviceFragment.java | 23 ++-- .../fragments/DeviceListFragment.java | 14 +-- .../fragments/DrawerFragment.java | 17 +-- .../fragments/FolderFragment.java | 27 ++--- .../fragments/FolderListFragment.java | 18 +--- .../fragments/SettingsFragment.java | 72 ++++--------- .../dialog/KeepVersionsDialogFragment.java | 14 +-- .../preferences/WifiSsidPreference.java | 16 ++- .../syncthing/DeviceStateHolder.java | 4 +- .../syncthing/EventProcessor.java | 6 +- .../syncthingandroid/syncthing/GetTask.java | 2 +- .../syncthing/PollWebGuiAvailableTask.java | 4 +- .../syncthing/PostConfigTask.java | 2 +- .../syncthing/PostScanTask.java | 2 +- .../syncthingandroid/syncthing/RestApi.java | 100 ++++++++---------- .../syncthing/SyncthingRunnable.java | 29 +++-- .../syncthing/SyncthingService.java | 32 ++---- .../syncthingandroid/util/ConfigXml.java | 2 +- .../util/CustomX509TrustManager.java | 4 +- .../syncthingandroid/util/FolderObserver.java | 10 +- .../syncthingandroid/util/FoldersAdapter.java | 4 +- .../widget/EnhancedEditText.java | 8 +- src/main/res/values-bg/strings.xml | 4 +- src/main/res/values-cs/strings.xml | 4 +- src/main/res/values-de/strings.xml | 4 +- src/main/res/values-es-rMX/strings.xml | 4 +- src/main/res/values-es/strings.xml | 4 +- src/main/res/values-fr/strings.xml | 4 +- src/main/res/values-hu/strings.xml | 3 +- src/main/res/values-it/strings.xml | 4 +- src/main/res/values-ja/strings.xml | 4 +- src/main/res/values-ko/strings.xml | 4 +- src/main/res/values-nb/strings.xml | 4 +- src/main/res/values-nl/strings.xml | 4 +- src/main/res/values-nn/strings.xml | 4 +- src/main/res/values-pl/strings.xml | 4 +- src/main/res/values-pt-rBR/strings.xml | 4 +- src/main/res/values-ru/strings.xml | 4 +- src/main/res/values-sv-rSE/strings.xml | 4 +- src/main/res/values-sv/strings.xml | 4 +- src/main/res/values-tr/strings.xml | 4 +- src/main/res/values-vi/strings.xml | 4 +- src/main/res/values-zh-rCN/strings.xml | 4 +- src/main/res/values/strings.xml | 6 +- .../syncthing/SyncthingServiceTest.java | 7 +- 67 files changed, 246 insertions(+), 485 deletions(-) diff --git a/build.gradle b/build.gradle index 2aeaf4e6..1d29114c 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,10 @@ android { testInstrumentationRunner 'android.test.InstrumentationTestRunner' testHandleProfiling true testFunctionalTest true + jackOptions { + enabled true + } + } // Without this parameter, all builds fail with error: // Execution failed for task ':mergeArmeabiDebugResources'. @@ -99,6 +103,10 @@ android { versionCode Integer.parseInt("0" + defaultConfig.versionCode) } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } task buildNative(type: Exec) { diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockContext.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockContext.java index f293b69a..08d1b1fe 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockContext.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockContext.java @@ -15,8 +15,8 @@ import java.util.List; */ public class MockContext extends ContextWrapper { - private ArrayList mReceivedIntents = new ArrayList<>(); - private ArrayList mStopServiceIntents = new ArrayList<>(); + private final ArrayList mReceivedIntents = new ArrayList<>(); + private final ArrayList mStopServiceIntents = new ArrayList<>(); /** * Use the actual context for calls that aren't easily mocked. May be null if those diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java index d21d5227..acfa1cec 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockRestApi.java @@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid.test; import android.app.Activity; import android.content.Context; +import android.support.annotation.NonNull; import com.nutomic.syncthingandroid.syncthing.RestApi; import java.util.ArrayList; @@ -65,7 +66,7 @@ public class MockRestApi extends RestApi { } @Override - public void editDevice(Device device, Activity activity, OnDeviceIdNormalizedListener listener) { + public void editDevice(@NonNull Device device, Activity activity, OnDeviceIdNormalizedListener listener) { throw new UnsupportedOperationException(); } diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java index da4fa1cc..329d9144 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/MockSyncthingService.java @@ -10,7 +10,7 @@ import java.util.LinkedList; public class MockSyncthingService extends SyncthingService { - private LinkedList mOnApiChangedListeners = new LinkedList<>(); + private final LinkedList mOnApiChangedListeners = new LinkedList<>(); @Override public int onStartCommand(Intent intent, int flags, int startId) { diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/activities/MainActivityTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/activities/MainActivityTest.java index 5d29ed43..7f8654a4 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/activities/MainActivityTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/activities/MainActivityTest.java @@ -10,7 +10,7 @@ import com.nutomic.syncthingandroid.test.MockSyncthingService; public class MainActivityTest extends ActivityInstrumentationTestCase2 { - private MockSyncthingService mService = new MockSyncthingService(); + private final MockSyncthingService mService = new MockSyncthingService(); public MainActivityTest() { super(MainActivity.class); diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BatteryReceiverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BatteryReceiverTest.java index 80f3cbb9..bf033817 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BatteryReceiverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BatteryReceiverTest.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.content.Intent; import android.preference.PreferenceManager; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.BatteryReceiver; import com.nutomic.syncthingandroid.syncthing.DeviceStateHolder; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BootReceiverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BootReceiverTest.java index 5d811b38..8aba410f 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BootReceiverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/BootReceiverTest.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.content.Intent; import android.preference.PreferenceManager; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.BootReceiver; import com.nutomic.syncthingandroid.syncthing.SyncthingService; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/DeviceStateHolderTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/DeviceStateHolderTest.java index 690b0d8a..bf7f1739 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/DeviceStateHolderTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/DeviceStateHolderTest.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.content.Intent; import android.os.BatteryManager; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.DeviceStateHolder; import com.nutomic.syncthingandroid.test.MockContext; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/GetTaskTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/GetTaskTest.java index a984adb4..b47133dd 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/GetTaskTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/GetTaskTest.java @@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.net.Uri; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.GetTask; import com.nutomic.syncthingandroid.syncthing.RestApi; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java index 7d3c90ec..3df0ca05 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.preference.PreferenceManager; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.DeviceStateHolder; import com.nutomic.syncthingandroid.syncthing.NetworkReceiver; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java index b9d95066..25a4debf 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java @@ -1,8 +1,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; import com.nutomic.syncthingandroid.syncthing.PollWebGuiAvailableTask; import com.nutomic.syncthingandroid.syncthing.RestApi; @@ -38,12 +36,7 @@ public class RestApiTest extends AndroidTestCase { } }.execute(config.getWebGuiUrl()); mApi = new RestApi(getContext(), config.getWebGuiUrl(), config.getApiKey(), - new RestApi.OnApiAvailableListener() { - @Override - public void onApiAvailable() { - latch.countDown(); - } - }, null); + latch::countDown, null); latch.await(1, TimeUnit.SECONDS); } diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingRunnableTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingRunnableTest.java index 8bcb79e3..b8df3cb9 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingRunnableTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingRunnableTest.java @@ -1,7 +1,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; import com.nutomic.syncthingandroid.syncthing.SyncthingRunnable; import com.nutomic.syncthingandroid.test.MockContext; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingServiceBinderTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingServiceBinderTest.java index 6499c331..f9b540f8 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingServiceBinderTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/SyncthingServiceBinderTest.java @@ -1,7 +1,6 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; import com.nutomic.syncthingandroid.syncthing.SyncthingService; import com.nutomic.syncthingandroid.syncthing.SyncthingServiceBinder; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/ConfigXmlTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/ConfigXmlTest.java index 0bbb6ab2..7eb20502 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/ConfigXmlTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/ConfigXmlTest.java @@ -1,16 +1,10 @@ package com.nutomic.syncthingandroid.test.util; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import com.nutomic.syncthingandroid.syncthing.SyncthingService; import com.nutomic.syncthingandroid.test.MockContext; import com.nutomic.syncthingandroid.util.ConfigXml; -import java.io.File; -import java.io.IOException; - public class ConfigXmlTest extends AndroidTestCase { private MockContext mContext; diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java index d13bd9d7..554cd5d8 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/util/FolderObserverTest.java @@ -1,7 +1,6 @@ package com.nutomic.syncthingandroid.test.util; import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; import com.nutomic.syncthingandroid.syncthing.RestApi; import com.nutomic.syncthingandroid.test.MockContext; diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java index 0535a2c5..672305c1 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java @@ -17,8 +17,6 @@ import com.nutomic.syncthingandroid.R; public class FirstStartActivity extends Activity implements Button.OnClickListener { - private static final String TAG = "FirstStartActivity"; - private static final int REQUEST_WRITE_STORAGE = 142; private SharedPreferences mPreferences; diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java index 7ce2d4fd..c6abbe7c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/FolderPickerActivity.java @@ -5,7 +5,6 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; @@ -31,7 +30,6 @@ import com.nutomic.syncthingandroid.syncthing.SyncthingService; import java.io.File; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.TreeSet; /** @@ -90,13 +88,10 @@ public class FolderPickerActivity extends SyncthingActivity @SuppressLint("NewApi") private void populateRoots() { // Use own comparator to handle null values. - TreeSet roots = new TreeSet<>(new Comparator() { - @Override - public int compare(File lhs, File rhs) { - if (lhs == null | rhs == null) - return 0; - return lhs.compareTo(rhs); - } + TreeSet roots = new TreeSet<>((lhs, rhs) -> { + if (lhs == null | rhs == null) + return 0; + return lhs.compareTo(rhs); }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { @@ -152,22 +147,12 @@ public class FolderPickerActivity extends SyncthingActivity .setTitle(R.string.create_folder) .setView(et) .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - createFolder(et.getText().toString()); - } - } + (dialogInterface, i) -> createFolder(et.getText().toString()) ) .setNegativeButton(android.R.string.cancel, null) .create(); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialogInterface) { - ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) - .showSoftInput(et, InputMethodManager.SHOW_IMPLICIT); - } - }); + dialog.setOnShowListener(dialogInterface -> ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) + .showSoftInput(et, InputMethodManager.SHOW_IMPLICIT)); dialog.show(); return true; case R.id.select: @@ -207,14 +192,12 @@ public class FolderPickerActivity extends SyncthingActivity if (contents == null) contents = new File[]{}; - Arrays.sort(contents, new Comparator() { - public int compare(File f1, File f2) { - if (f1.isDirectory() && f2.isFile()) - return -1; - if (f1.isFile() && f2.isDirectory()) - return 1; - return f1.getName().compareTo(f2.getName()); - } + Arrays.sort(contents, (f1, f2) -> { + if (f1.isDirectory() && f2.isFile()) + return -1; + if (f1.isFile() && f2.isDirectory()) + return 1; + return f1.getName().compareTo(f2.getName()); }); for (File f : contents) { diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/LogActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/LogActivity.java index f0818318..0dba99ae 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/LogActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/LogActivity.java @@ -91,18 +91,13 @@ public class LogActivity extends SyncthingActivity { } private void scrollToBottom() { - mScrollView.post(new Runnable() { - @Override - public void run() { - mScrollView.scrollTo(0, mLog.getBottom()); - } - }); + mScrollView.post(() -> mScrollView.scrollTo(0, mLog.getBottom())); } private void updateLog() { if (mFetchLogTask != null) mFetchLogTask.cancel(true); - mLog.setText("Retrieving logs..."); + mLog.setText(R.string.retrieving_logs); mFetchLogTask = new AsyncTask() { @Override protected String doInBackground(Void... params) { @@ -137,7 +132,7 @@ public class LogActivity extends SyncthingActivity { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream(), "UTF-8"), 8192); StringBuilder log = new StringBuilder(); - String line = ""; + String line; String sep = System.getProperty("line.separator"); while ((line = bufferedReader.readLine()) != null) { log.append(line); diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index db5f5909..72ebd922 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -286,30 +286,17 @@ public class MainActivity extends SyncthingActivity .setTitle(R.string.syncthing_disabled_title) .setMessage(R.string.syncthing_disabled_message) .setPositiveButton(R.string.syncthing_disabled_change_settings, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - finish(); - Intent intent = new Intent(MainActivity.this, SettingsActivity.class) - .setAction(SettingsActivity.ACTION_APP_SETTINGS); - startActivity(intent); - } + (dialogInterface, i) -> { + finish(); + Intent intent = new Intent(MainActivity.this, SettingsActivity.class) + .setAction(SettingsActivity.ACTION_APP_SETTINGS); + startActivity(intent); } ) .setNegativeButton(R.string.exit, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - finish(); - } - } + (dialogInterface, i) -> finish() ) - .setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialogInterface) { - finish(); - } - }) + .setOnCancelListener(dialogInterface -> finish()) .show(); mDisabledDialog.setCanceledOnTouchOutside(false); } @@ -402,43 +389,37 @@ public class MainActivity extends SyncthingActivity * Displays dialog asking user to accept/deny usage reporting. */ private void showUsageReportingDialog() { - final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_ACCEPTED, - MainActivity.this); - break; - case DialogInterface.BUTTON_NEGATIVE: - getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_DENIED, - MainActivity.this); - break; - case DialogInterface.BUTTON_NEUTRAL: - Uri uri = Uri.parse("https://data.syncthing.net"); - startActivity(new Intent(Intent.ACTION_VIEW, uri)); - break; - } - + final DialogInterface.OnClickListener listener = (dialog, which) -> { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_ACCEPTED, + MainActivity.this); + break; + case DialogInterface.BUTTON_NEGATIVE: + getApi().setUsageReportAccepted(RestApi.USAGE_REPORTING_DENIED, + MainActivity.this); + break; + case DialogInterface.BUTTON_NEUTRAL: + Uri uri = Uri.parse("https://data.syncthing.net"); + startActivity(new Intent(Intent.ACTION_VIEW, uri)); + break; } + }; - getApi().getUsageReport(new RestApi.OnReceiveUsageReportListener() { - @Override - public void onReceiveUsageReport(String report) { - @SuppressLint("InflateParams") - View v = LayoutInflater.from(MainActivity.this) - .inflate(R.layout.dialog_usage_reporting, null); - TextView tv = (TextView) v.findViewById(R.id.example); - tv.setText(report); - new AlertDialog.Builder(MainActivity.this) - .setTitle(R.string.usage_reporting_dialog_title) - .setView(v) - .setPositiveButton(R.string.yes, listener) - .setNegativeButton(R.string.no, listener) - .setNeutralButton(R.string.open_website, listener) - .show(); - } + getApi().getUsageReport(report -> { + @SuppressLint("InflateParams") + View v = LayoutInflater.from(MainActivity.this) + .inflate(R.layout.dialog_usage_reporting, null); + TextView tv = (TextView) v.findViewById(R.id.example); + tv.setText(report); + new AlertDialog.Builder(MainActivity.this) + .setTitle(R.string.usage_reporting_dialog_title) + .setView(v) + .setPositiveButton(R.string.yes, listener) + .setNegativeButton(R.string.no, listener) + .setNeutralButton(R.string.open_website, listener) + .show(); }); } diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/RestartActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/RestartActivity.java index 7cb1bf21..0a73548e 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/RestartActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/RestartActivity.java @@ -5,7 +5,6 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NotificationCompat; @@ -30,26 +29,17 @@ public class RestartActivity extends SyncthingActivity { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.restart_title) - .setPositiveButton(R.string.restart_now, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - getService().getApi().updateConfig(); - finish(); - } + .setPositiveButton(R.string.restart_now, (dialogInterface, i) -> { + getService().getApi().updateConfig(); + finish(); }) - .setNegativeButton(R.string.restart_later, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - createRestartNotification(); - finish(); - } + .setNegativeButton(R.string.restart_later, (dialogInterface, i) -> { + createRestartNotification(); + finish(); }) - .setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - createRestartNotification(); - finish(); - } + .setOnCancelListener(dialog -> { + createRestartNotification(); + finish(); }) .show(); } diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index 34aedc52..0984401d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.activities; import android.app.Fragment; import android.app.FragmentManager; -import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AlertDialog; import com.nutomic.syncthingandroid.R; @@ -96,12 +95,7 @@ public class SettingsActivity extends SyncthingActivity { if (getIsCreate() && (mFragment instanceof DeviceFragment || mFragment instanceof FolderFragment)) { new AlertDialog.Builder(this) .setMessage(R.string.dialog_discard_changes) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - finish(); - } - }) + .setPositiveButton(android.R.string.ok, (dialog, which) -> finish()) .setNegativeButton(android.R.string.cancel, null) .show(); } diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java index 99abdbfc..a3c71d1c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/SyncthingActivity.java @@ -20,7 +20,7 @@ public abstract class SyncthingActivity extends ToolbarBindingActivity implement private SyncthingService mSyncthingService; - private LinkedList mServiceConnectedListeners = new LinkedList<>(); + private final LinkedList mServiceConnectedListeners = new LinkedList<>(); /** * To be used for Fragments. diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceFragment.java index 69f824c0..978a17a5 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceFragment.java @@ -83,7 +83,7 @@ public class DeviceFragment extends Fragment implements private boolean mDeviceNeedsToUpdate; - private DialogInterface.OnClickListener mCompressionEntrySelectedListener = new DialogInterface.OnClickListener() { + private final DialogInterface.OnClickListener mCompressionEntrySelectedListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); @@ -99,7 +99,7 @@ public class DeviceFragment extends Fragment implements } }; - private TextWatcher mIdTextWatcher = new TextWatcherAdapter() { + private final TextWatcher mIdTextWatcher = new TextWatcherAdapter() { @Override public void afterTextChanged(Editable s) { if (!s.toString().equals(mDevice.deviceID)) { @@ -110,7 +110,7 @@ public class DeviceFragment extends Fragment implements } }; - private TextWatcher mNameTextWatcher = new TextWatcherAdapter() { + private final TextWatcher mNameTextWatcher = new TextWatcherAdapter() { @Override public void afterTextChanged(Editable s) { if (!s.toString().equals(mDevice.name)) { @@ -121,7 +121,7 @@ public class DeviceFragment extends Fragment implements } }; - private TextWatcher mAddressesTextWatcher = new TextWatcherAdapter() { + private final TextWatcher mAddressesTextWatcher = new TextWatcherAdapter() { @Override public void afterTextChanged(Editable s) { if (!s.toString().equals(displayableAddresses())) { @@ -132,7 +132,7 @@ public class DeviceFragment extends Fragment implements } }; - private CompoundButton.OnCheckedChangeListener mIntroducerCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { + private final CompoundButton.OnCheckedChangeListener mIntroducerCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (mDevice.introducer != isChecked) { @@ -262,10 +262,10 @@ public class DeviceFragment extends Fragment implements if (!mIsCreateMode) { List devices = mSyncthingService.getApi().getDevices(false); mDevice = null; - for (int i = 0; i < devices.size(); i++) { - if (devices.get(i).deviceID.equals( + for (RestApi.Device device : devices) { + if (device.deviceID.equals( getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID))) { - mDevice = devices.get(i); + mDevice = device; break; } } @@ -327,12 +327,7 @@ public class DeviceFragment extends Fragment implements case R.id.remove: new AlertDialog.Builder(getActivity()) .setMessage(R.string.remove_device_confirm) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - mSyncthingService.getApi().deleteDevice(mDevice, getActivity()); - } - }) + .setPositiveButton(android.R.string.yes, (dialogInterface, i) -> mSyncthingService.getApi().deleteDevice(mDevice, getActivity())) .setNegativeButton(android.R.string.no, null) .show(); return true; diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java index d0eeab27..b560d3fd 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceListFragment.java @@ -29,12 +29,7 @@ import java.util.TimerTask; public class DeviceListFragment extends ListFragment implements SyncthingService.OnApiChangeListener, ListView.OnItemClickListener { - private final static Comparator DEVICES_COMPARATOR = new Comparator() { - @Override - public int compare(RestApi.Device lhs, RestApi.Device rhs) { - return lhs.name.compareTo(rhs.name); - } - }; + private final static Comparator DEVICES_COMPARATOR = (lhs, rhs) -> lhs.name.compareTo(rhs.name); private DevicesAdapter mAdapter; @@ -47,12 +42,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService mTimer.schedule(new TimerTask() { @Override public void run() { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateList(); - } - }); + getActivity().runOnUiThread(DeviceListFragment.this::updateList); } }, 0, SyncthingService.GUI_UPDATE_INTERVAL); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java index 9041484b..2e4b2ade 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DrawerFragment.java @@ -1,7 +1,6 @@ package com.nutomic.syncthingandroid.fragments; import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -156,12 +155,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI return; mDeviceId.setText(info.myID); - mDeviceId.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mActivity.getApi().copyDeviceId(mDeviceId.getText().toString()); - } - }); + mDeviceId.setOnClickListener(v -> mActivity.getApi().copyDeviceId(mDeviceId.getText().toString())); mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%"); mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys)); mAnnounceServer.setText(Integer.toString(info.extAnnounceConnected) + "/" + @@ -217,13 +211,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI mActivity.closeDrawer(); new AlertDialog.Builder(getContext()) .setMessage(R.string.dialog_confirm_restart) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - getContext().startService(new Intent(getContext(), SyncthingService.class) - .setAction(SyncthingService.ACTION_RESTART)); - } - }) + .setPositiveButton(android.R.string.yes, (dialogInterface, i1) -> getContext().startService(new Intent(getContext(), SyncthingService.class) + .setAction(SyncthingService.ACTION_RESTART))) .setNegativeButton(android.R.string.no, null) .show(); break; diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java index ec12f521..6de4fcba 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderFragment.java @@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.fragments; import android.app.Activity; import android.app.AlertDialog; import android.app.Fragment; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; @@ -71,9 +70,9 @@ public class FolderFragment extends Fragment private boolean mIsCreateMode; private boolean mFolderNeedsToUpdate; - private KeepVersionsDialogFragment mKeepVersionsDialogFragment = new KeepVersionsDialogFragment(); + private final KeepVersionsDialogFragment mKeepVersionsDialogFragment = new KeepVersionsDialogFragment(); - private TextWatcher mTextWatcher = new TextWatcherAdapter() { + private final TextWatcher mTextWatcher = new TextWatcherAdapter() { @Override public void afterTextChanged(Editable s) { mFolder.label = mLabelView.getText().toString(); @@ -83,7 +82,7 @@ public class FolderFragment extends Fragment } }; - private CompoundButton.OnCheckedChangeListener mCheckedListener = + private final CompoundButton.OnCheckedChangeListener mCheckedListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton view, boolean isChecked) { @@ -105,7 +104,7 @@ public class FolderFragment extends Fragment } }; - private KeepVersionsDialogFragment.OnValueChangeListener mOnValueChangeListener = + private final KeepVersionsDialogFragment.OnValueChangeListener mOnValueChangeListener = new KeepVersionsDialogFragment.OnValueChangeListener() { @Override public void onValueChange(int intValue) { @@ -121,7 +120,7 @@ public class FolderFragment extends Fragment } }; - private View.OnClickListener mPathViewClickListener = new View.OnClickListener() { + private final View.OnClickListener mPathViewClickListener = new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FolderPickerActivity.class); @@ -197,12 +196,7 @@ public class FolderFragment extends Fragment mDevicesContainer = (ViewGroup) view.findViewById(R.id.devicesContainer); mPathView.setOnClickListener(mPathViewClickListener); - view.findViewById(R.id.versioningContainer).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mKeepVersionsDialogFragment.show(getFragmentManager(), KEEP_VERSIONS_DIALOG_TAG); - } - }); + view.findViewById(R.id.versioningContainer).setOnClickListener(v -> mKeepVersionsDialogFragment.show(getFragmentManager(), KEEP_VERSIONS_DIALOG_TAG)); if (mIsCreateMode) { // Open keyboard on label view in edit mode. @@ -326,12 +320,7 @@ public class FolderFragment extends Fragment case R.id.remove: new AlertDialog.Builder(getActivity()) .setMessage(R.string.remove_folder_confirm) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - mSyncthingService.getApi().deleteFolder(mFolder, getActivity()); - } - }) + .setPositiveButton(android.R.string.yes, (dialogInterface, i) -> mSyncthingService.getApi().deleteFolder(mFolder, getActivity())) .setNegativeButton(android.R.string.no, null) .show(); return true; @@ -355,7 +344,7 @@ public class FolderFragment extends Fragment private void initFolder() { mFolder = new RestApi.Folder(); mFolder.id = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_ID); - mFolder.label = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_LABEL);; + mFolder.label = getActivity().getIntent().getStringExtra(EXTRA_FOLDER_LABEL); mFolder.path = ""; mFolder.rescanIntervalS = 259200; // Scan every 3 days (in case inotify dropped some changes) mFolder.deviceIds = new ArrayList<>(); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java index c5236562..b7883aab 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderListFragment.java @@ -32,14 +32,11 @@ public class FolderListFragment extends ListFragment implements SyncthingService /** * Compares folders by labels, uses the folder ID as fallback if the label is empty */ - private final static Comparator FOLDERS_COMPARATOR = new Comparator() { - @Override - public int compare(RestApi.Folder lhs, RestApi.Folder rhs) { - String lhsLabel = lhs.label != null && !lhs.label.isEmpty() ? lhs.label : lhs.id; - String rhsLabel = rhs.label != null && !rhs.label.isEmpty() ? rhs.label : rhs.id; + private final static Comparator FOLDERS_COMPARATOR = (lhs, rhs) -> { + String lhsLabel = lhs.label != null && !lhs.label.isEmpty() ? lhs.label : lhs.id; + String rhsLabel = rhs.label != null && !rhs.label.isEmpty() ? rhs.label : rhs.id; - return lhsLabel.compareTo(rhsLabel); - } + return lhsLabel.compareTo(rhsLabel); }; private FoldersAdapter mAdapter; @@ -53,12 +50,7 @@ public class FolderListFragment extends ListFragment implements SyncthingService mTimer.schedule(new TimerTask() { @Override public void run() { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateList(); - } - }); + getActivity().runOnUiThread(FolderListFragment.this::updateList); } }, 0, SyncthingService.GUI_UPDATE_INTERVAL); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java index 3c8079dd..05470dea 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java @@ -1,9 +1,7 @@ package com.nutomic.syncthingandroid.fragments; import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Bundle; @@ -11,11 +9,8 @@ import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.support.v4.app.NavUtils; -import android.text.InputType; -import android.text.TextUtils; import android.util.Log; import android.view.MenuItem; import android.widget.Toast; @@ -27,7 +22,6 @@ import com.nutomic.syncthingandroid.syncthing.RestApi; import com.nutomic.syncthingandroid.syncthing.SyncthingService; import java.util.List; -import java.util.Set; import java.util.TreeSet; import eu.chainfire.libsuperuser.Shell; @@ -284,14 +278,6 @@ public class SettingsFragment extends PreferenceFragment return true; } - private String formatWifiNameList(Set ssids) { - Set formatted = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - for (String ssid : ssids) { - formatted.add(ssid.replaceFirst("^\"", "").replaceFirst("\"$", "")); - } - return TextUtils.join(", ", formatted); - } - /** * Changes the owner of syncthing files so they can be accessed without root. */ @@ -324,15 +310,12 @@ public class SettingsFragment extends PreferenceFragment new AlertDialog.Builder(getActivity()) .setMessage(R.string.dialog_confirm_export) .setPositiveButton(android.R.string.yes, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mSyncthingService.exportConfig(); - Toast.makeText(getActivity(), - getString(R.string.config_export_successful, - SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); - } - }) + (dialog, which) -> { + mSyncthingService.exportConfig(); + Toast.makeText(getActivity(), + getString(R.string.config_export_successful, + SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); + }) .setNegativeButton(android.R.string.no, null) .show(); return true; @@ -340,22 +323,19 @@ public class SettingsFragment extends PreferenceFragment new AlertDialog.Builder(getActivity()) .setMessage(R.string.dialog_confirm_import) .setPositiveButton(android.R.string.yes, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (mSyncthingService.importConfig()) { - Toast.makeText(getActivity(), - getString(R.string.config_imported_successful), - Toast.LENGTH_SHORT).show(); - // No need to restart, as we shutdown to import the config, and - // then have to start Syncthing again. - } else { - Toast.makeText(getActivity(), - getString(R.string.config_import_failed, - SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); - } - } - }) + (dialog, which) -> { + if (mSyncthingService.importConfig()) { + Toast.makeText(getActivity(), + getString(R.string.config_imported_successful), + Toast.LENGTH_SHORT).show(); + // No need to restart, as we shutdown to import the config, and + // then have to start Syncthing again. + } else { + Toast.makeText(getActivity(), + getString(R.string.config_import_failed, + SyncthingService.EXPORT_PATH), Toast.LENGTH_LONG).show(); + } + }) .setNegativeButton(android.R.string.no, null) .show(); return true; @@ -366,17 +346,11 @@ public class SettingsFragment extends PreferenceFragment new AlertDialog.Builder(getActivity()) .setTitle(R.string.streset_title) .setMessage(R.string.streset_question) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - getActivity().startService(intent); - Toast.makeText(getActivity(), R.string.streset_done, Toast.LENGTH_LONG).show(); - } + .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + getActivity().startService(intent); + Toast.makeText(getActivity(), R.string.streset_done, Toast.LENGTH_LONG).show(); }) - .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - } + .setNegativeButton(android.R.string.no, (dialogInterface, i) -> { }) .show(); return true; diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/dialog/KeepVersionsDialogFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/dialog/KeepVersionsDialogFragment.java index 53a151f5..dba37a81 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/dialog/KeepVersionsDialogFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/dialog/KeepVersionsDialogFragment.java @@ -16,7 +16,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; public class KeepVersionsDialogFragment extends DialogFragment { - private OnValueChangeListener mOnValueChangeListener = OnValueChangeListener.NO_OP; + private OnValueChangeListener mOnValueChangeListener; private NumberPicker mNumberPickerView; @@ -28,7 +28,8 @@ public class KeepVersionsDialogFragment extends DialogFragment { switch (which) { case DialogInterface.BUTTON_POSITIVE: mValue = mNumberPickerView.getValue(); - mOnValueChangeListener.onValueChange(mValue); + if (mOnValueChangeListener != null) + mOnValueChangeListener.onValueChange(mValue); break; } } @@ -47,10 +48,6 @@ public class KeepVersionsDialogFragment extends DialogFragment { } public void setOnValueChangeListener(OnValueChangeListener onValueChangeListener) { - if (onValueChangeListener == null) { - onValueChangeListener = OnValueChangeListener.NO_OP; - } - mOnValueChangeListener = onValueChangeListener; } @@ -73,11 +70,6 @@ public class KeepVersionsDialogFragment extends DialogFragment { } public interface OnValueChangeListener { - OnValueChangeListener NO_OP = new OnValueChangeListener() { - @Override - public void onValueChange(int value) {} - }; - void onValueChange(int value); } } diff --git a/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java b/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java index 91481bae..466fe22e 100644 --- a/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java +++ b/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java @@ -11,7 +11,6 @@ import android.widget.Toast; import com.nutomic.syncthingandroid.R; import java.util.Arrays; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -53,7 +52,7 @@ public class WifiSsidPreference extends MultiSelectListPreference { protected void showDialog(Bundle state) { WifiConfiguration[] networks = loadConfiguredNetworksSorted(); if (networks != null) { - Set selected = getSharedPreferences().getStringSet(getKey(), new HashSet()); + Set selected = getSharedPreferences().getStringSet(getKey(), new HashSet<>()); // from JavaDoc: Note that you must not modify the set instance returned by this call. // therefore required to make a defensive copy of the elements selected = new HashSet<>(selected); @@ -114,14 +113,11 @@ public class WifiSsidPreference extends MultiSelectListPreference { // if WiFi is turned off, getConfiguredNetworks returns null on many devices if (configuredNetworks != null) { WifiConfiguration[] result = configuredNetworks.toArray(new WifiConfiguration[configuredNetworks.size()]); - Arrays.sort(result, new Comparator() { - @Override - public int compare(WifiConfiguration lhs, WifiConfiguration rhs) { - // See #620: There may be null-SSIDs - String l = lhs.SSID != null ? lhs.SSID : ""; - String r = rhs.SSID != null ? rhs.SSID : ""; - return l.compareToIgnoreCase(r); - } + Arrays.sort(result, (lhs, rhs) -> { + // See #620: There may be null-SSIDs + String l = lhs.SSID != null ? lhs.SSID : ""; + String r = rhs.SSID != null ? rhs.SSID : ""; + return l.compareToIgnoreCase(r); }); return result; } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java index e0f76132..4157515e 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/DeviceStateHolder.java @@ -40,7 +40,7 @@ public class DeviceStateHolder extends BroadcastReceiver { public static final String EXTRA_IS_CHARGING = "com.nutomic.syncthingandroid.syncthing.DeviceStateHolder.IS_CHARGING"; - private Context mContext; + private final Context mContext; private boolean mIsWifiConnected = false; @@ -132,7 +132,7 @@ public class DeviceStateHolder extends BroadcastReceiver { boolean wifiConnected = isWifiConnected(); if (wifiConnected) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - Set ssids = sp.getStringSet(SyncthingService.PREF_SYNC_ONLY_WIFI_SSIDS, new HashSet()); + Set ssids = sp.getStringSet(SyncthingService.PREF_SYNC_ONLY_WIFI_SSIDS, new HashSet<>()); if (ssids.isEmpty()) { Log.d(TAG, "All SSIDs allowed for syncing"); return true; diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/EventProcessor.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/EventProcessor.java index 5ecc1034..1a6c4137 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/EventProcessor.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/EventProcessor.java @@ -70,7 +70,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene // If that's the case we've to start at zero because syncthing was restarted. mApi.getEvents(0, 1, new RestApi.OnReceiveEventListener() { @Override - public void onEvent(long id, String eventType, JSONObject data) throws JSONException { + public void onEvent(String eventType, JSONObject data) throws JSONException { } @@ -89,7 +89,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene * Performs the actual event handling. */ @Override - public void onEvent(long id, String type, JSONObject data) throws JSONException { + public void onEvent(String type, JSONObject data) throws JSONException { switch (type) { case "DeviceRejected": String deviceId = data.getString("device"); @@ -159,7 +159,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); //noinspection CommitPrefEdits - sp.edit().putLong(PREF_LAST_SYNC_ID, mLastEventId).commit(); + sp.edit().putLong(PREF_LAST_SYNC_ID, mLastEventId).apply(); } synchronized (mMainThreadHandler) { diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/GetTask.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/GetTask.java index e4f6822b..74bc6eb9 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/GetTask.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/GetTask.java @@ -38,7 +38,7 @@ public class GetTask extends AsyncTask { public static final String URI_REPORT = "/rest/svc/report"; public static final String URI_EVENTS = "/rest/events"; - private String mHttpsCertPath; + private final String mHttpsCertPath; public GetTask(String httpsCertPath) { mHttpsCertPath = httpsCertPath; diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java index 7f44c557..3d64b46b 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/PollWebGuiAvailableTask.java @@ -28,14 +28,14 @@ public abstract class PollWebGuiAvailableTask extends AsyncTask { public static final String URI_CONFIG = "/rest/system/config"; - private String mHttpsCertPath; + private final String mHttpsCertPath; public PostConfigTask(String httpsCertPath) { mHttpsCertPath = httpsCertPath; diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/PostScanTask.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/PostScanTask.java index 6e2e73c5..202b2302 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/PostScanTask.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/PostScanTask.java @@ -26,7 +26,7 @@ public class PostScanTask extends AsyncTask { public static final String URI_SCAN = "/rest/db/scan"; - private String mHttpsCertPath; + private final String mHttpsCertPath; public PostScanTask(String httpsCertPath) { mHttpsCertPath = httpsCertPath; diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 15968488..0895a5e9 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -13,7 +13,6 @@ import android.util.Log; import android.widget.Toast; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; import com.google.gson.annotations.SerializedName; import com.nutomic.syncthingandroid.BuildConfig; @@ -170,7 +169,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, private String mVersion; - private String mUrl; + private final String mUrl; private final String mApiKey; @@ -197,12 +196,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, * Stores the latest result of {@link #getModel(String, OnReceiveModelListener)} for each folder, * for calculating device percentage in {@link #getConnections(OnReceiveConnectionsListener)}. */ - private HashMap mCachedModelInfo = new HashMap<>(); + private final HashMap mCachedModelInfo = new HashMap<>(); /** * Stores a hash map to resolve folders to paths for events. */ - private final Map mCacheFolderPathLookup = new HashMap(); + private final Map mCacheFolderPathLookup = new HashMap<>(); public RestApi(Context context, String url, String apiKey, OnApiAvailableListener apiListener, OnConfigChangedListener configListener) { @@ -214,14 +213,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, mOnConfigChangedListener = configListener; } - public void setWebGuiUrl(String newUrl) { - mUrl = newUrl; - } - /** * Number of previous calls to {@link #tryIsAvailable()}. */ - private AtomicInteger mAvailableCount = new AtomicInteger(0); + private final AtomicInteger mAvailableCount = new AtomicInteger(0); /** * Number of asynchronous calls performed in {@link #onWebGuiAvailable()}. @@ -270,12 +265,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, } } }.execute(mUrl, GetTask.URI_CONFIG, mApiKey); - getSystemInfo(new OnReceiveSystemInfoListener() { - @Override - public void onReceiveSystemInfo(SystemInfo info) { - mLocalDeviceId = info.myID; - tryIsAvailable(); - } + getSystemInfo(info -> { + mLocalDeviceId = info.myID; + tryIsAvailable(); }); } @@ -712,12 +704,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, * Called for each event. * * Events with a "folder" field in the data have an extra "folderpath" element added. - * - * @param id ID of the event. Monotonously increasing. - * @param eventType Name of the event. (See Syncthing documentation) + * @param eventType Name of the event. (See Syncthing documentation) * @param data Contains the data fields of the event. */ - void onEvent(long id, String eventType, JSONObject data) throws JSONException; + void onEvent(String eventType, JSONObject data) throws JSONException; /** * Called after all available events have been processed. @@ -816,7 +806,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, data.put("folderpath", folderPath); } - listener.onEvent(id, type, data); + listener.onEvent(type, data); } listener.onDone(lastId); @@ -838,46 +828,43 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public void editDevice(@NonNull final Device device, final Activity activity, final OnDeviceIdNormalizedListener listener) { normalizeDeviceId(device.deviceID, - new RestApi.OnDeviceIdNormalizedListener() { - @Override - public void onDeviceIdNormalized(String normalizedId, String error) { - if (listener != null) listener.onDeviceIdNormalized(normalizedId, error); - if (normalizedId == null) - return; + (normalizedId, error) -> { + if (listener != null) listener.onDeviceIdNormalized(normalizedId, error); + if (normalizedId == null) + return; - device.deviceID = normalizedId; - // If the device already exists, just update it. - boolean create = true; - for (RestApi.Device n : getDevices(true)) { - if (n.deviceID.equals(device.deviceID)) { - create = false; - } + device.deviceID = normalizedId; + // If the device already exists, just update it. + boolean create = true; + for (Device n : getDevices(true)) { + if (n.deviceID.equals(device.deviceID)) { + create = false; } + } - try { - JSONArray devices = mConfig.getJSONArray("devices"); - JSONObject n = null; - if (create) { - n = new JSONObject(); - devices.put(n); - } else { - for (int i = 0; i < devices.length(); i++) { - JSONObject json = devices.getJSONObject(i); - if (device.deviceID.equals(json.getString("deviceID"))) { - n = devices.getJSONObject(i); - break; - } + try { + JSONArray devices = mConfig.getJSONArray("devices"); + JSONObject n = null; + if (create) { + n = new JSONObject(); + devices.put(n); + } else { + for (int i = 0; i < devices.length(); i++) { + JSONObject json = devices.getJSONObject(i); + if (device.deviceID.equals(json.getString("deviceID"))) { + n = devices.getJSONObject(i); + break; } } - n.put("deviceID", device.deviceID); - n.put("name", device.name); - n.put("addresses", new JSONArray(device.addresses)); - n.put("compression", device.compression); - n.put("introducer", device.introducer); - requireRestart(activity); - } catch (JSONException e) { - Log.w(TAG, "Failed to read devices", e); } + n.put("deviceID", device.deviceID); + n.put("name", device.name); + n.put("addresses", new JSONArray(device.addresses)); + n.put("compression", device.compression); + n.put("introducer", device.introducer); + requireRestart(activity); + } catch (JSONException e) { + Log.w(TAG, "Failed to read devices", e); } } ); @@ -909,7 +896,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, /** * Updates or creates the given device. */ - public boolean editFolder(Folder folder, boolean create, Activity activity) { + public void editFolder(Folder folder, boolean create, Activity activity) { try { JSONArray folders = mConfig.getJSONArray("folders"); JSONObject r = null; @@ -950,11 +937,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, requireRestart(activity); } catch (JSONException e) { Log.w(TAG, "Failed to edit folder " + folder.id + " at " + folder.path, e); - return false; + return; } clearFolderCache(); - return true; } /** diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java index 778c3a59..9fe8c59d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java @@ -42,7 +42,7 @@ public class SyncthingRunnable implements Runnable { private final Context mContext; - private String mSyncthingBinary; + private final String mSyncthingBinary; private String[] mCommand; @@ -91,7 +91,7 @@ public class SyncthingRunnable implements Runnable { @Override public void run() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - int ret = 1; + int ret; // Make sure Syncthing is executable try { ProcessBuilder pb = new ProcessBuilder("chmod", "500", mSyncthingBinary); @@ -313,22 +313,19 @@ public class SyncthingRunnable implements Runnable { * @param saveLog True if the log should be stored to {@link #mErrorLog}. */ private Thread log(final InputStream is, final int priority, final boolean saveLog) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - BufferedReader br = new BufferedReader(isr); - String line; - while ((line = br.readLine()) != null) { - Log.println(priority, TAG_NATIVE, line); + Thread t = new Thread(() -> { + try { + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + Log.println(priority, TAG_NATIVE, line); - if (saveLog) - mErrorLog += line + "\n"; - } - } catch (IOException e) { - Log.w(TAG, "Failed to read Syncthing's command line output", e); + if (saveLog) + mErrorLog += line + "\n"; } + } catch (IOException e) { + Log.w(TAG, "Failed to read Syncthing's command line output", e); } }); t.start(); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index 6c378edd..7b9b15b7 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -5,7 +5,6 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -32,11 +31,9 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; -import java.security.SecureRandom; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; -import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -107,7 +104,7 @@ public class SyncthingService extends Service implements private EventProcessor mEventProcessor; - private LinkedList mObservers = new LinkedList<>(); + private final LinkedList mObservers = new LinkedList<>(); private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this); @@ -347,14 +344,10 @@ public class SyncthingService extends Service implements } mApi = new RestApi(SyncthingService.this, urlAndKey.first, urlAndKey.second, - new RestApi.OnApiAvailableListener() { - @Override - public void onApiAvailable() { - mCurrentState = State.ACTIVE; - onApiChange(); - new Thread(new Runnable() { - @Override - public void run() { + () -> { + mCurrentState = State.ACTIVE; + onApiChange(); + new Thread(() -> { for (RestApi.Folder r : mApi.getFolders()) { try { mObservers.add(new FolderObserver(mApi, r)); @@ -368,15 +361,8 @@ public class SyncthingService extends Service implements .show(); } } - } - }).start(); - } - }, new RestApi.OnConfigChangedListener() { - @Override - public void onConfigChanged() { - onApiChange(); - } - }); + }).start(); + }, SyncthingService.this::onApiChange); mEventProcessor = new EventProcessor(SyncthingService.this, mApi); @@ -472,7 +458,7 @@ public class SyncthingService extends Service implements * The listener is called immediately with the current state, and again whenever the state * changes. The call is always from the GUI thread. * - * @see {@link #unregisterOnApiChangeListener} + * @see #unregisterOnApiChangeListener */ public void registerOnApiChangeListener(OnApiChangeListener listener) { // Make sure we don't send an invalid state or syncthing might show a "disabled" message @@ -484,7 +470,7 @@ public class SyncthingService extends Service implements /** * Unregisters a previously registered listener. * - * @see {@link #registerOnApiChangeListener} + * @see #registerOnApiChangeListener */ public void unregisterOnApiChangeListener(OnApiChangeListener listener) { mOnApiChangeListeners.remove(listener); diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index 4ef90dce..0e1d75e7 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -63,7 +63,7 @@ public class ConfigXml { private final Context mContext; - private File mConfigFile; + private final File mConfigFile; private Document mConfig; diff --git a/src/main/java/com/nutomic/syncthingandroid/util/CustomX509TrustManager.java b/src/main/java/com/nutomic/syncthingandroid/util/CustomX509TrustManager.java index 2266b4de..229fc76d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/CustomX509TrustManager.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/CustomX509TrustManager.java @@ -1,5 +1,6 @@ package com.nutomic.syncthingandroid.util; +import android.annotation.SuppressLint; import android.util.Log; import org.apache.http.conn.ssl.SSLSocketFactory; @@ -61,13 +62,14 @@ public class CustomX509TrustManager implements X509TrustManager { } } - private String mHttpsCertPath; + private final String mHttpsCertPath; public CustomX509TrustManager(String httpsCertPath) { mHttpsCertPath = httpsCertPath; } @Override + @SuppressLint("TrustAllX509TrustManager") public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FolderObserver.java b/src/main/java/com/nutomic/syncthingandroid/util/FolderObserver.java index 7903e93d..97498cfc 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FolderObserver.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FolderObserver.java @@ -6,7 +6,6 @@ import android.util.Log; import com.nutomic.syncthingandroid.syncthing.RestApi; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; /** @@ -35,7 +34,7 @@ public class FolderObserver extends FileObserver { public class FolderNotExistingException extends Exception { - private String mPath; + private final String mPath; public FolderNotExistingException(String path) { mPath = path; @@ -69,12 +68,7 @@ public class FolderObserver extends FileObserver { if (!currentFolder.exists()) { throw new FolderNotExistingException(currentFolder.getAbsolutePath()); } - File[] directories = currentFolder.listFiles(new FilenameFilter() { - @Override - public boolean accept(File current, String name) { - return new File(current, name).isDirectory(); - } - }); + File[] directories = currentFolder.listFiles((current, name) -> new File(current, name).isDirectory()); if (directories != null) { for (File f : directories) { diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java index 76a30cb5..b73699f3 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java @@ -24,8 +24,8 @@ import static com.nutomic.syncthingandroid.syncthing.RestApi.readableFileSize; public class FoldersAdapter extends ArrayAdapter implements RestApi.OnReceiveModelListener { - private HashMap mModels = new HashMap<>(); - private LayoutInflater mInflater; + private final HashMap mModels = new HashMap<>(); + private final LayoutInflater mInflater; public FoldersAdapter(Context context) { super(context, R.layout.item_folder_list); diff --git a/src/main/java/com/nutomic/syncthingandroid/widget/EnhancedEditText.java b/src/main/java/com/nutomic/syncthingandroid/widget/EnhancedEditText.java index 5df51557..fc77c06c 100644 --- a/src/main/java/com/nutomic/syncthingandroid/widget/EnhancedEditText.java +++ b/src/main/java/com/nutomic/syncthingandroid/widget/EnhancedEditText.java @@ -34,11 +34,9 @@ public class EnhancedEditText extends EditText { @Override public boolean onTouchEvent(MotionEvent event) { - if (isEnabled()) { - return super.onTouchEvent(event); - } else { - return false; - } + return (isEnabled()) + ? super.onTouchEvent(event) + : false; } @Override diff --git a/src/main/res/values-bg/strings.xml b/src/main/res/values-bg/strings.xml index 187bc4bc..fa71c93b 100644 --- a/src/main/res/values-bg/strings.xml +++ b/src/main/res/values-bg/strings.xml @@ -141,9 +141,7 @@ Само по време на зареждане Само чрез WiFi Ограничаване до определени WiFi мрежи - Синхронизиране чрез всяка WiFi мрежа - Синхронизиране само чрез: %1$s - За да изберете мрежа, моля включете WiFi + За да изберете мрежа, моля включете WiFi Избор на папка, за напреднали Изберете папка, от устройството, за синхронизиране Стартира Syncthing с права на Superuser diff --git a/src/main/res/values-cs/strings.xml b/src/main/res/values-cs/strings.xml index 19e43914..e029bdbc 100644 --- a/src/main/res/values-cs/strings.xml +++ b/src/main/res/values-cs/strings.xml @@ -144,9 +144,7 @@ Všechny problémy, se kterými se setkáte, nahlašte prosím přes Github.Synchronizovat pouze při nabíjení Synchronizovat pouze přes wifi Omezit na vybrané sítě wifi - Synchronizovat na všech wifi sítích - Synchronizovat pouze při připojení k: %1$s - Pro výběr sítí prosím zapněte WiFi. + Pro výběr sítí prosím zapněte WiFi. Použít rozšířený výběr adresáře Vyberte jakýkoliv adresář v přístroji pro synchronizaci Spustit syncthing jako superuživatel diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 4e14499b..68020cca 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -142,9 +142,7 @@ Bitte auftretenden Probleme via Github melden. Sync nur mit Ladegerät Sync nur im WLAN Nur in bestimmten WLAN Netzwerken - Synchronisiere in allen WLAN Netzwerken - Synchronisiere nur in folgendem WLAN: %1$s - Bitte WLAN aktivieren, um eines zu wählen. + Bitte WLAN aktivieren, um eines zu wählen. Erweiterte Verzeichnisauswahl benutzen Alle Verzeichnisse auf dem Gerät für Synchronisation auswählbar Syncthing mit Superuser Rechten ausführen diff --git a/src/main/res/values-es-rMX/strings.xml b/src/main/res/values-es-rMX/strings.xml index 8fa40fbc..a3e05154 100644 --- a/src/main/res/values-es-rMX/strings.xml +++ b/src/main/res/values-es-rMX/strings.xml @@ -142,9 +142,7 @@ Por favor reporte cualquier problema que encuentre por medio de Github. Sincronizar sólo cuando se está cargando Sincronizar sólo por wifi Restringir a ciertas redes wifi - Sincronizar en todas las redes wifi - Sincronizar sólo cuando esté conectado a: %1$s - Por favor encienda el WiFi para seleccionar redes. + Por favor encienda el WiFi para seleccionar redes. Usar el avanzado Seleccionador de Carpetas Seleccionar cualquier carpeta en el dispositivo para sincronizar Ejecutar Syncthing como Superusuario diff --git a/src/main/res/values-es/strings.xml b/src/main/res/values-es/strings.xml index 6682a1b9..526979c5 100644 --- a/src/main/res/values-es/strings.xml +++ b/src/main/res/values-es/strings.xml @@ -137,9 +137,7 @@ Por favor informe de qualquier problema que encuentres via Github. Sincronizar solo cuando esté cargando Sincronizar sólo en wifi Restringir a algunas redes wifi - Sincronizar en todas las redes wifi - Sincronizar solo cuando se está conectado a: %1$s - Por favor enciende el WIFI en las redes seleccionadas. + Por favor enciende el WIFI en las redes seleccionadas. Usar Selección Avanzada de carpeta Escoja una carpeta del dispositivo para sincronizar Ejecutar Syncthing como Superusuario diff --git a/src/main/res/values-fr/strings.xml b/src/main/res/values-fr/strings.xml index 1e8a3e9f..22c7f774 100644 --- a/src/main/res/values-fr/strings.xml +++ b/src/main/res/values-fr/strings.xml @@ -144,9 +144,7 @@ S\'il vous plait, signalez les problèmes que vous rencontrez via Gihub.Synchro uniquement sur chargeur Synchro uniquement en WiFi Limiter à certains réseaux WiFi - Synchroniser sur tous réseaux WiFi - Synchroniser seulement si connecté à: %1$s - S\'il vous plait, activer le WiFi pour sélectionner un réseau + S\'il vous plait, activer le WiFi pour sélectionner un réseau Choix étendu des dossiers Autorise la sélection n\'importe quel dossier de cette machine pour la synchronisation Faire fonctionner syncthing en super-utilisateur diff --git a/src/main/res/values-hu/strings.xml b/src/main/res/values-hu/strings.xml index 5367821b..e541d9c8 100644 --- a/src/main/res/values-hu/strings.xml +++ b/src/main/res/values-hu/strings.xml @@ -120,8 +120,7 @@ Csak töltés közbeni szinkronizálás Szinkronizálás csak WiFi-n keresztül Korlátozás bizonyos wifi hálózatokra - Szinkronizálás minden wifi hálózaton - Hálózat választásához kapcsold be a wifit. + Hálózat választásához kapcsold be a wifit. Syncthing futtatása Superuser-ként Értesítés Értesítés típusának kiválasztása diff --git a/src/main/res/values-it/strings.xml b/src/main/res/values-it/strings.xml index 39e7b628..e830c5b1 100644 --- a/src/main/res/values-it/strings.xml +++ b/src/main/res/values-it/strings.xml @@ -144,9 +144,7 @@ Riferisci tramite Github i problemi che incontri. Sincr. solo in Ricarica Sincr. solo in Wifi Solo determinate reti wifi - Sincronizzazione su tutte le reti wifi - Sincronizzazione solo quando connessi a: %1$s - Prego accendere wifi per selezionare reti. + Prego accendere wifi per selezionare reti. Selettore Cartella Avanzato Selezionare una cartella sul dispositivo per la sincronizzazione Esegui Syncthing come Superutente diff --git a/src/main/res/values-ja/strings.xml b/src/main/res/values-ja/strings.xml index fbde8a82..0c28dbb9 100644 --- a/src/main/res/values-ja/strings.xml +++ b/src/main/res/values-ja/strings.xml @@ -144,9 +144,7 @@ 充電中のみ同期 Wifi 時のみ同期 特定の WiFi ネットワークに制限する - すべての WiFi ネットワークで共有する - %1$s に接続時のみ同期する - ネットワークを選択するために WiFi をオンにしてください。 + ネットワークを選択するために WiFi をオンにしてください。 高度なフォルダー選択を使用する 同期するデバイスのフォルダーを選択してください スーパーユーザーとして同期を実行します diff --git a/src/main/res/values-ko/strings.xml b/src/main/res/values-ko/strings.xml index e0f55390..f0bcffea 100644 --- a/src/main/res/values-ko/strings.xml +++ b/src/main/res/values-ko/strings.xml @@ -144,9 +144,7 @@ 충전 중일 때만 동기화 Wi-Fi에서만 동기화 특정 WI-FI 네트워크로 제한하기 - 모든 WI-FI 네트워크에서 동기화 - %1$s에 연결되어 있을 때만 동기화 - WI-FI를 활성화하고 네트워크를 선택해주세요. + WI-FI를 활성화하고 네트워크를 선택해주세요. 고급 폴더 선택기 사용 기기에서 동기화에 사용할 폴더를 골라 주세요 Syncthing을 Superuser로 실행 diff --git a/src/main/res/values-nb/strings.xml b/src/main/res/values-nb/strings.xml index c75d7143..760c690a 100644 --- a/src/main/res/values-nb/strings.xml +++ b/src/main/res/values-nb/strings.xml @@ -144,9 +144,7 @@ Vennligst rapporter eventuelle problemer som oppstår via GitHub. Synkroniser kun ved lading Synkroniser kun over WiFi Begrens til visse wifi-nettverk - Synkroniser på alle wifi-nettverk - Synkroniser bare når koblet til: %1$s - Vennligst skru på WiFi for å velge nettverk. + Vennligst skru på WiFi for å velge nettverk. Bruk avansert mappevelger Velg en mappe på enheten for synkronisering Kjør Syncthing som superbruker diff --git a/src/main/res/values-nl/strings.xml b/src/main/res/values-nl/strings.xml index fcaf341d..4a8df6f5 100644 --- a/src/main/res/values-nl/strings.xml +++ b/src/main/res/values-nl/strings.xml @@ -144,9 +144,7 @@ Gelieve alle problemen die je tegenkomt via GitHub te melden. Synchroniseer alleen tijdens opladen Synchroniseer alleen via Wi-Fi Tot bepaalde Wi-Fi-netwerken beperken - Synchroniseer op alle Wi-Fi-netwerken - Louter synchroniseren terwijl verbonden met: %1$s - Wi-Fi aanzetten t.b.v. netwerkselectie. + Wi-Fi aanzetten t.b.v. netwerkselectie. Gebruik geavanceerd map-kiezer Selecteer een map op het toestel om te synchroniseren Syncthing uitvoeren als superuser diff --git a/src/main/res/values-nn/strings.xml b/src/main/res/values-nn/strings.xml index d78a69ae..1c66494b 100644 --- a/src/main/res/values-nn/strings.xml +++ b/src/main/res/values-nn/strings.xml @@ -144,9 +144,7 @@ Om du skulle støyte på problem, ver snill å rapportere dei via Github.Synkroniser berre mens eg laddar Synkroniser berre over WiFi Avgrens til visse WiFi-nettverk - Synkroniser på alle WiFi-nettverk - Synkroniser berre på: %1$s - Skru på WiFi for å velje nettverk. + Skru på WiFi for å velje nettverk. Bruk avansert mappeveljar Vel kva mappe som helst for synkronisering Køyr Syncthing som superbrukar diff --git a/src/main/res/values-pl/strings.xml b/src/main/res/values-pl/strings.xml index aca6641b..d756d4ed 100644 --- a/src/main/res/values-pl/strings.xml +++ b/src/main/res/values-pl/strings.xml @@ -143,9 +143,7 @@ Proszę zgłaszać błędy programu w serwisie Github. Synchronizowanie tylko podczas ładowania Synchronizowanie tylko przy użyciu Wi-Fi Ogranicz do określonych sieci WiFi - Synchronizowanie przy użyciu wszystkich sieci wifi - Synchronizuj jedynie gdy połączono z: %1$s - Proszę włącz WiFi dla wybranych sieci + Proszę włącz WiFi dla wybranych sieci Zaawansowane wybieranie katalogów Wskazuje dowolny katalog na urządzeniu do zsynchronizowania Synchronizuje zawartość z uprawnieniami użytkownika Superuser diff --git a/src/main/res/values-pt-rBR/strings.xml b/src/main/res/values-pt-rBR/strings.xml index a68e6914..72594421 100644 --- a/src/main/res/values-pt-rBR/strings.xml +++ b/src/main/res/values-pt-rBR/strings.xml @@ -144,9 +144,7 @@ Por favor, informe-nos sobre quaisquer problemas via Github. Somente durante o carregamento Somente conectado ao WiFi Limitar a certas redes WiFi - Sincronizar em todas as redes WiFi - Sincronizar somente quando conectado a %1$s - Ligue o WiFi para selecionar as redes + Ligue o WiFi para selecionar as redes Usar seletor de pasta avançado Selecione qualquer pasta do dispositivo para sincronização Executar como Superusuário diff --git a/src/main/res/values-ru/strings.xml b/src/main/res/values-ru/strings.xml index b8424856..22e2d409 100644 --- a/src/main/res/values-ru/strings.xml +++ b/src/main/res/values-ru/strings.xml @@ -143,9 +143,7 @@ Синхронизация только во время зарядки Синхронизация только по WIFI Ограничить определёнными wifi сетями - Синхронизировать в любых wifi сетях - Синхронизировать только в: %1$s - Включите WiFi, чтобы выбрать сети + Включите WiFi, чтобы выбрать сети Использовать продвинутый выбор папок Выберите любую папку на устройстве для синхронизации Запуск Syncthing с рут-правами diff --git a/src/main/res/values-sv-rSE/strings.xml b/src/main/res/values-sv-rSE/strings.xml index 43554462..e6dad4bc 100644 --- a/src/main/res/values-sv-rSE/strings.xml +++ b/src/main/res/values-sv-rSE/strings.xml @@ -144,9 +144,7 @@ Vänligen rapportera eventuella problem du stöter på via Github. Synkronisera endast vid laddning Synkronisera endast trådlöst Begränsa till vissa WiFi-nätverk - Synkronisera på alla WiFi-nätverk - Synkronisera endast när den är ansluten till: %1$s - Sätt på WiFi för att välja nätverk. + Sätt på WiFi för att välja nätverk. Använd avancerad katalogväljare Välj någon katalog på enheten för synkronisering Kör Syncthing som superanvändare diff --git a/src/main/res/values-sv/strings.xml b/src/main/res/values-sv/strings.xml index 528a5e2d..0b5fb690 100644 --- a/src/main/res/values-sv/strings.xml +++ b/src/main/res/values-sv/strings.xml @@ -144,9 +144,7 @@ Vänligen rapportera eventuella problem du stöter på via Github. Synkronisera endast vid laddning Synkronisera endast trådlöst Begränsa till vissa WiFi-nätverk - Synkronisera på alla WiFi-nätverk - Synkronisera endast när den är ansluten till: %1$s - Slå på WiFi för att välja nätverk. + Slå på WiFi för att välja nätverk. Använd avancerade katalogväljaren Välj någon katalog på enheten för synkronisering Kör Syncthing som superanvändare diff --git a/src/main/res/values-tr/strings.xml b/src/main/res/values-tr/strings.xml index cadd211a..ccd25757 100644 --- a/src/main/res/values-tr/strings.xml +++ b/src/main/res/values-tr/strings.xml @@ -137,9 +137,7 @@ Lütfen, herhangi bir sorunla karşılaştığınızda Github üzerinden bildiri Sadece şarj edilirken eşzamanlama yap Sadece kablosuz ağ üzerindeyken eşzamanlama yap Belirlenmiş kablosuz ağlarla sınırlandır. - Herhangi bir kablosuz ağ üzerindeyken eşzamanlama yap - Sadece %1$s\'e bağlıyken eşzamanlama yap - Ağ seçmek için lütfen kablosuz bağlantınızı açın. + Ağ seçmek için lütfen kablosuz bağlantınızı açın. Gelişmiş Klasör Seçici Kullan Eşzamanlama yapmak için cihazdan herhangi bir klasör seçin Syncthing\'i Superuser/Ayrıcalıklı Kullanıcı olarak Çalıştır diff --git a/src/main/res/values-vi/strings.xml b/src/main/res/values-vi/strings.xml index ab3570ad..d67579a4 100644 --- a/src/main/res/values-vi/strings.xml +++ b/src/main/res/values-vi/strings.xml @@ -142,9 +142,7 @@ Xin báo cáo mọi vấn đề phát sinh thông qua Github. Chỉ đ.bộ khi sạc pin Chỉ đ.bộ khi dùng wifi Hạn chế với vài mạng wifi nhất định - Đồng bộ trên t.cả mạng wifi - Chỉ đồng bộ khi kết nối đến: %1$s - Hãy bật WiFi để lựa chọn mạng. + Hãy bật WiFi để lựa chọn mạng. S.dụng trình chọn th.mục nâng cao Chọn bất kỳ th.mục nào trên th.bị để đồng bộ Chạy Syncthing với quyền Superuser diff --git a/src/main/res/values-zh-rCN/strings.xml b/src/main/res/values-zh-rCN/strings.xml index 198fe7d5..b5921462 100644 --- a/src/main/res/values-zh-rCN/strings.xml +++ b/src/main/res/values-zh-rCN/strings.xml @@ -144,9 +144,7 @@ 仅在充电时同步 仅在无线网络下同步 对某些无线网络下限制同步 - 在所有网络环境下同步 - 仅当连接到 %1$s 网络中才进行同步 - 请打开无线网络连接并选择网络 + 请打开无线网络连接并选择网络 使用高级文件夹选择器 可以选择设备上任何文件夹 Syncthing 运行于超级用户 diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index a60e30e0..a9d28e5a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -237,10 +237,6 @@ Please report any problems you encounter via Github. Restrict to certain wifi networks - Sync on all wifi networks - - Sync only while connected to: %1$s - Please turn on WiFi to select networks. Use advanced Folder Picker @@ -406,6 +402,8 @@ Please report any problems you encounter via Github. View Syncthing Log + Retrieving logs… + Share diff --git a/src/test/java/com/nutomic/syncthingandroid/syncthing/SyncthingServiceTest.java b/src/test/java/com/nutomic/syncthingandroid/syncthing/SyncthingServiceTest.java index 42d7cf2c..80fdf9e6 100644 --- a/src/test/java/com/nutomic/syncthingandroid/syncthing/SyncthingServiceTest.java +++ b/src/test/java/com/nutomic/syncthingandroid/syncthing/SyncthingServiceTest.java @@ -49,12 +49,7 @@ public class SyncthingServiceTest { @Test public void testBindService() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(2); - mService.registerOnWebGuiAvailableListener(new SyncthingService.OnWebGuiAvailableListener() { - @Override - public void onWebGuiAvailable() { - latch.countDown(); - } - }); + mService.registerOnWebGuiAvailableListener(latch::countDown); mService.registerOnApiChangeListener(new SyncthingService.OnApiChangeListener() { @Override public void onApiChange(SyncthingService.State currentState) {