1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Various lint fixes

This commit is contained in:
Felix Ableitner 2017-09-04 13:43:27 +09:00
parent 2f195cec3b
commit 7e37c14a82
28 changed files with 51 additions and 104 deletions

View file

@ -11,7 +11,6 @@ import com.nutomic.syncthingandroid.service.RestApi;
import java.net.URL;
import java.util.List;
import java.util.Map;
public class MockRestApi extends RestApi {

View file

@ -4,7 +4,6 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ServiceTestRule;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.test.MockContext;
import com.nutomic.syncthingandroid.test.Util;
import com.nutomic.syncthingandroid.util.FolderObserver;

View file

@ -16,7 +16,6 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
@ -59,7 +58,7 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
private static final String IS_SHOWING_COMPRESSION_DIALOG = "COMPRESSION_FOLDER_DIALOG_STATE";
private static final String IS_SHOWING_DELETE_DIALOG = "DELETE_FOLDER_DIALOG_STATE";
public static final List<String> DYNAMIC_ADDRESS = Collections.singletonList("dynamic");
private static final List<String> DYNAMIC_ADDRESS = Collections.singletonList("dynamic");
private Device mDevice;
@ -252,7 +251,7 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
}
}
public void onServiceConnected() {
private void onServiceConnected() {
getService().registerOnApiChangeListener(this::onApiChange);
}
@ -262,7 +261,7 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
* NOTE: This is only called once on startup, should be called more often to properly display
* version/address changes.
*/
public void onReceiveConnections(Connections connections) {
private void onReceiveConnections(Connections connections) {
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
if (viewsExist && connections.connections.containsKey(mDevice.deviceID)) {
mCurrentAddressView.setVisibility(VISIBLE);
@ -272,7 +271,7 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
}
}
public void onApiChange(SyncthingService.State currentState) {
private void onApiChange(SyncthingService.State currentState) {
if (currentState != ACTIVE) {
finish();
return;

View file

@ -15,7 +15,6 @@ import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
@ -31,8 +30,6 @@ import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.util.TextWatcherAdapter;
import org.w3c.dom.Text;
import java.util.List;
import java.util.Random;
import java.util.Map;

View file

@ -43,9 +43,7 @@ import java.util.Iterator;
public class FolderPickerActivity extends SyncthingActivity
implements AdapterView.OnItemClickListener, SyncthingService.OnApiChangeListener {
private static final String TAG = "FolderPickerActivity";
public static final String EXTRA_INITIAL_DIRECTORY =
private static final String EXTRA_INITIAL_DIRECTORY =
"com.nutomic.syncthingandroid.activities.FolderPickerActivity.INITIAL_DIRECTORY";
public static final String EXTRA_RESULT_DIRECTORY =

View file

@ -13,10 +13,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -53,11 +50,6 @@ import com.nutomic.syncthingandroid.model.Options;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@ -160,9 +152,8 @@ public class MainActivity extends SyncthingActivity
}
})
.setNeutralButton(R.string.dialog_disable_battery_optimization_later, (d, i) -> mBatteryOptimizationDialogDismissed = true)
.setNegativeButton(R.string.dialog_disable_battery_optimization_dont_show_again, (d, i) -> {
sp.edit().putBoolean("battery_optimization_dont_show_again", true).apply();
})
.setNegativeButton(R.string.dialog_disable_battery_optimization_dont_show_again, (d, i) ->
sp.edit().putBoolean("battery_optimization_dont_show_again", true).apply())
.setOnCancelListener(d -> mBatteryOptimizationDialogDismissed = true)
.show();
}
@ -368,6 +359,7 @@ public class MainActivity extends SyncthingActivity
}
public void showQrCodeDialog(String deviceId, Bitmap qrCode) {
@SuppressLint("InflateParams")
View qrCodeDialogView = this.getLayoutInflater().inflate(R.layout.dialog_qrcode, null);
TextView deviceIdTextView = (TextView) qrCodeDialogView.findViewById(R.id.device_id);
TextView shareDeviceIdTextView = (TextView) qrCodeDialogView.findViewById(R.id.actionShareId);

View file

@ -210,8 +210,8 @@ public class ShareActivity extends SyncthingActivity
private class CopyFilesTask extends AsyncTask<Void, Void, Boolean> {
private ProgressDialog mProgress;
private Map<Uri, String> mFiles;
private Folder mFolder;
private final Map<Uri, String> mFiles;
private final Folder mFolder;
private int mCopied = 0, mIgnored = 0;
CopyFilesTask(Map<Uri, String> files, Folder folder) {

View file

@ -24,7 +24,7 @@ public class VersioningDialogActivity extends AppCompatActivity {
private Fragment mCurrentFragment;
private List<String> mTypes = Arrays.asList("none", "trashcan", "simple", "staggered", "external");
private static final List<String> mTypes = Arrays.asList("none", "trashcan", "simple", "staggered", "external");
private Bundle mArguments;

View file

@ -4,7 +4,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.ArrayMap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,7 +24,6 @@ import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService;
import com.nutomic.syncthingandroid.util.Util;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.util.Locale;
@ -157,7 +155,7 @@ public class DrawerFragment extends Fragment implements View.OnClickListener {
/**
* Populates views with status received via {@link RestApi#getSystemInfo}.
*/
public void onReceiveSystemInfo(SystemInfo info) {
private void onReceiveSystemInfo(SystemInfo info) {
if (getActivity() == null)
return;
mDeviceId = info.myID;
@ -179,7 +177,7 @@ public class DrawerFragment extends Fragment implements View.OnClickListener {
/**
* Populates views with status received via {@link RestApi#getSystemInfo}.
*/
public void onReceiveSystemVersion(SystemVersion info) {
private void onReceiveSystemVersion(SystemVersion info) {
if (getActivity() == null)
return;

View file

@ -3,12 +3,9 @@ package com.nutomic.syncthingandroid.fragments.dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.NumberPicker;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.fragments.NumberPickerFragment;
@ -19,18 +16,16 @@ import com.nutomic.syncthingandroid.fragments.NumberPickerFragment;
public class SimpleVersioningFragment extends Fragment {
private View mView;
private Bundle mArguments;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_simple_versioning, container, false);
View view = inflater.inflate(R.layout.fragment_simple_versioning, container, false);
mArguments = getArguments();
fillArguments();
updateNumberPicker();
return mView;
return view;
}
private void fillArguments() {

View file

@ -5,8 +5,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View file

@ -16,18 +16,16 @@ import com.nutomic.syncthingandroid.fragments.NumberPickerFragment;
public class TrashCanVersioningFragment extends Fragment {
private View mView;
private Bundle mArguments;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_trashcan_versioning, container, false);
View view = inflater.inflate(R.layout.fragment_trashcan_versioning, container, false);
mArguments = getArguments();
fillArguments();
updateNumberPicker();
return mView;
return view;
}
private void fillArguments() {

View file

@ -10,20 +10,15 @@ import android.util.Log;
import android.widget.ImageView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HurlStack;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import org.json.JSONObject;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@ -59,15 +54,15 @@ public abstract class ApiRequest {
private static final String HEADER_API_KEY = "X-API-Key";
public interface OnSuccessListener {
public void onSuccess(String result);
void onSuccess(String result);
}
public interface OnImageSuccessListener {
public void onImageSuccess(Bitmap result);
void onImageSuccess(Bitmap result);
}
public interface OnErrorListener {
public void onError(VolleyError error);
void onError(VolleyError error);
}
private static RequestQueue sVolleyQueue;
@ -82,7 +77,7 @@ public abstract class ApiRequest {
private final Context mContext;
private final URL mUrl;
protected final String mPath;
private final String mPath;
private final String mHttpsCertPath;
private final String mApiKey;
@ -168,6 +163,7 @@ public abstract class ApiRequest {
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;

View file

@ -4,20 +4,15 @@ import android.content.Context;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.android.volley.Request;
import com.google.common.base.Optional;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
/**
* Created by jmintb on 27-06-17.
*/
public class ImageGetRequest extends ApiRequest {
public static String QR_CODE_GENERATOR = "/qr/";
public static final String QR_CODE_GENERATOR = "/qr/";
public ImageGetRequest(Context context, URL url, String path, String httpsCertPath, String apiKey,
@Nullable Map<String, String> params, OnImageSuccessListener onSuccessListener, OnErrorListener onErrorListener) {

View file

@ -16,8 +16,6 @@ import java.util.Collections;
*/
public class PollWebGuiAvailableTask extends ApiRequest {
private static final String TAG = "PollWebGuiAvailableTask";
/**
* Interval in ms, at which connections to the web gui are performed on first start
* to find out if it's online.

View file

@ -2,7 +2,6 @@ package com.nutomic.syncthingandroid.model;
import android.text.TextUtils;
import java.io.Serializable;
import java.util.List;
public class Device {

View file

@ -15,7 +15,7 @@ public class Folder {
public String label;
public String path;
public String type;
public List<Device> devices = new ArrayList<>();
private List<Device> devices = new ArrayList<>();
public int rescanIntervalS;
public final boolean ignorePerms = true;
public boolean autoNormalize = true;

View file

@ -91,7 +91,7 @@ public class DeviceStateHolder extends BroadcastReceiver {
}
}
public void updateWifiSsid() {
private void updateWifiSsid() {
mWifiSsid = null;
WifiManager wifiManager =
(WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);

View file

@ -39,7 +39,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
* Minimum interval in seconds at which the events are polled from syncthing and processed.
* This intervall will not wake up the device to save battery power.
*/
public static final long EVENT_UPDATE_INTERVAL = TimeUnit.SECONDS.toMillis(15);
private static final long EVENT_UPDATE_INTERVAL = TimeUnit.SECONDS.toMillis(15);
/**
* Use the MainThread for all callbacks and message handling

View file

@ -65,11 +65,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
}
public interface OnResultListener1<T> {
public void onResult(T t);
void onResult(T t);
}
public interface OnResultListener2<T, R> {
public void onResult(T t, R r);
void onResult(T t, R r);
}
private final Context mContext;
@ -120,7 +120,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
private static final int TOTAL_STARTUP_CALLS = 3;
public interface OnApiAvailableListener {
public void onApiAvailable();
void onApiAvailable();
}
private final OnApiAvailableListener mOnApiAvailableListener;
@ -316,7 +316,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*
* This method uses Gson and only works with objects that can be converted with Gson.
*/
public <T> T deepCopy(T object, Type type) {
private <T> T deepCopy(T object, Type type) {
Gson gson = new Gson();
return gson.fromJson(gson.toJson(object, type), type);
}
@ -325,9 +325,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
* Requests and parses information about current system status and resource usage.
*/
public void getSystemInfo(OnResultListener1<SystemInfo> listener) {
new GetRequest(mContext, mUrl, GetRequest.URI_SYSTEM, mHttpsCertPath, mApiKey, null, result -> {
listener.onResult(new Gson().fromJson(result, SystemInfo.class));
});
new GetRequest(mContext, mUrl, GetRequest.URI_SYSTEM, mHttpsCertPath, mApiKey, null, result ->
listener.onResult(new Gson().fromJson(result, SystemInfo.class)));
}
public boolean isConfigLoaded() {

View file

@ -21,10 +21,10 @@ import android.util.Pair;
import android.widget.Toast;
import com.android.PRNGFixes;
import com.annimon.stream.Stream;
import com.google.common.io.Files;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.FirstStartActivity;
import com.nutomic.syncthingandroid.activities.MainActivity;
import com.nutomic.syncthingandroid.http.PollWebGuiAvailableTask;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.receiver.NetworkReceiver;
@ -113,14 +113,14 @@ public class SyncthingService extends Service implements
* Callback for when the Syncthing web interface becomes first available after service start.
*/
public interface OnWebGuiAvailableListener {
public void onWebGuiAvailable();
void onWebGuiAvailable();
}
private final HashSet<OnWebGuiAvailableListener> mOnWebGuiAvailableListeners =
new HashSet<>();
public interface OnApiChangeListener {
public void onApiChange(State currentState);
void onApiChange(State currentState);
}
private final HashSet<OnApiChangeListener> mOnApiChangeListeners =
@ -431,9 +431,7 @@ public class SyncthingService extends Service implements
stopForeground(false);
nm.cancel(NOTIFICATION_ACTIVE);
for (FolderObserver ro : mObservers) {
ro.stopWatching();
}
Stream.of(mObservers).forEach(FolderObserver::stopWatching);
mObservers.clear();
}
@ -511,9 +509,7 @@ public class SyncthingService extends Service implements
Log.i(TAG, "Web GUI has come online at " + mConfig.getWebGuiUrl());
mCurrentState = State.STARTING;
onApiChange();
for (OnWebGuiAvailableListener listener : mOnWebGuiAvailableListeners) {
listener.onWebGuiAvailable();
}
Stream.of(mOnWebGuiAvailableListeners).forEach(OnWebGuiAvailableListener::onWebGuiAvailable);
mOnWebGuiAvailableListeners.clear();
});
}

View file

@ -3,7 +3,6 @@ package com.nutomic.syncthingandroid.util;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
@ -21,7 +20,6 @@ import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.SecureRandom;
import java.util.Locale;
import javax.xml.parsers.DocumentBuilder;

View file

@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid.util;
import android.os.FileObserver;
import android.util.Log;
import com.annimon.stream.Stream;
import com.nutomic.syncthingandroid.model.Folder;
import java.io.File;
@ -24,7 +25,7 @@ public class FolderObserver extends FileObserver {
private final ArrayList<FolderObserver> mChilds = new ArrayList<>();
public interface OnFolderFileChangeListener {
public void onFolderFileChange(String folderId, String relativePath);
void onFolderFileChange(String folderId, String relativePath);
}
public FolderObserver(OnFolderFileChangeListener listener, Folder folder)
@ -129,8 +130,6 @@ public class FolderObserver extends FileObserver {
@Override
public void stopWatching() {
super.stopWatching();
for (FolderObserver ro : mChilds) {
ro.stopWatching();
}
Stream.of(mChilds).forEach(FolderObserver::stopWatching);
}
}

View file

@ -27,7 +27,7 @@ import java.util.TreeMap;
* Based on https://gitlab.com/fdroid/fdroidclient/blob/master/app/src/main/java/org/fdroid/fdroid/Languages.java
*/
public final class Languages {
public static final String TAG = "Languages";
private static final String TAG = "Languages";
public static final String USE_SYSTEM_DEFAULT = "";
@ -48,7 +48,7 @@ public final class Languages {
Collections.sort(locales, (l1, l2) -> l1.getDisplayLanguage().compareTo(l2.getDisplayLanguage()));
for (Locale locale : locales) {
String displayLanguage = locale.getDisplayLanguage(locale);
displayLanguage = displayLanguage.substring(0, 1).toUpperCase() + displayLanguage.substring(1);
displayLanguage = displayLanguage.substring(0, 1).toUpperCase(locale) + displayLanguage.substring(1);
tmpMap.put(locale.getLanguage(), displayLanguage);
}
@ -142,11 +142,7 @@ public final class Languages {
return keys.toArray(new String[keys.size()]);
}
private String capitalize(final String line) {
return Character.toUpperCase(line.charAt(0)) + line.substring(1);
}
public static final Locale[] LOCALES_TO_TEST = {
private static final Locale[] LOCALES_TO_TEST = {
Locale.ENGLISH,
Locale.FRENCH,
Locale.GERMAN,

View file

@ -79,7 +79,7 @@ public class DevicesAdapter extends ArrayAdapter<Device> {
}
}
public void onReceiveConnections(Connections connections) {
private void onReceiveConnections(Connections connections) {
mConnections = connections;
notifyDataSetChanged();
}

View file

@ -104,7 +104,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
/**
* Returns the folder's state as a localized string.
*/
public static String getLocalizedState(Context c, String state, int percentage) {
private static String getLocalizedState(Context c, String state, int percentage) {
switch (state) {
case "idle": return c.getString(R.string.state_idle);
case "scanning": return c.getString(R.string.state_scanning);
@ -129,7 +129,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
}
}
public void onReceiveModel(String folderId, Model model) {
private void onReceiveModel(String folderId, Model model) {
mModels.put(folderId, model);
notifyDataSetChanged();
}

View file

@ -3,8 +3,7 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="?dialogPreferredPadding"
style="@style/Theme.Syncthing.Dialog"
>
style="@style/Theme.Syncthing.Dialog">
<Spinner
@ -12,8 +11,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/versioning_types"
style="@style/Widget.AppCompat.Spinner.Underlined"
/>
style="@style/Widget.AppCompat.Spinner.Underlined" />
<ScrollView
android:layout_width="match_parent"
@ -34,7 +32,7 @@
style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="right"
android:layout_gravity="end"
android:text="@string/finish"
android:textColor="@color/primary_dark" />

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Syncthing</string>
@ -354,7 +354,7 @@ Please report any problems you encounter via Github.</string>
<string name="environment_variables">Environment variables</string>
<!-- Toast after entering invalid STTRACE params -->
<string name="toast_invalid_sttrace">Only 0-9, a-z and \',\' are allowed in STTRACE options</string>
<string name="toast_invalid_sttrace" tools:ignore="TypographyDashes">Only 0-9, a-z and \',\' are allowed in STTRACE options</string>
<string name="toast_invalid_environment_variables">Value is not a valid environment variable string</string>