Code cleanup.

This commit is contained in:
Dennis Guse
2020-11-01 08:38:47 +01:00
parent 0f92a37146
commit 0209a90e01
6 changed files with 19 additions and 62 deletions
@@ -209,7 +209,7 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
@Override
public void onNewTrackPointsDone() {
if (isResumed()) {
runOnUiThread(() -> loadIntervals());
runOnUiThread(this::loadIntervals);
}
}
@@ -64,17 +64,14 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
return new StatisticsRecordingFragment();
}
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
if (isResumed()) {
getActivity().runOnUiThread(() -> {
if (isResumed()) {
updateUI();
}
});
}
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
if (isResumed()) {
getActivity().runOnUiThread(() -> {
if (isResumed()) {
updateUI();
}
});
}
}
};
@@ -21,10 +21,10 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
private static final String TAG = ImportViewModel.class.getSimpleName();
private MutableLiveData<Summary> importData;
private ImportServiceResultReceiver resultReceiver;
private Summary summary;
private final ImportServiceResultReceiver resultReceiver;
private final Summary summary;
private boolean cancel = false;
private List<DocumentFile> filesToImport = new ArrayList<>();
private final List<DocumentFile> filesToImport = new ArrayList<>();
public ImportViewModel(@NonNull Application application) {
super(application);
@@ -47,9 +47,7 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
private void loadData(DocumentFile documentFile) {
List<DocumentFile> fileList = FileUtils.getFiles(documentFile);
summary.totalCount = fileList.size();
for (DocumentFile df : fileList) {
filesToImport.add(df);
}
filesToImport.addAll(fileList);
importNextFile();
}
@@ -89,12 +87,12 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
importNextFile();
}
public class Summary {
public static class Summary {
private int totalCount;
private int successCount;
private int existsCount;
private int errorCount;
private ArrayList<String> fileErrors = new ArrayList<>();
private final ArrayList<String> fileErrors = new ArrayList<>();
public int getTotalCount() {
return totalCount;
@@ -190,10 +190,7 @@ public class KmzTrackImporter implements TrackImporter {
zipInputStream.closeEntry();
}
return trackId;
} catch (ImportParserException e) {
Log.e(TAG, "Unable to import file", e);
throw e;
} catch (ImportAlreadyExistsException e) {
} catch (ImportParserException | ImportAlreadyExistsException e) {
Log.e(TAG, "Unable to import file", e);
throw e;
} catch (IOException e) {
@@ -259,9 +256,7 @@ public class KmzTrackImporter implements TrackImporter {
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getKml(zipInputStream))) {
return kmlFileTrackImporter.importFile(byteArrayInputStream);
} catch (ImportParserException e) {
throw e;
} catch (ImportAlreadyExistsException e) {
} catch (ImportParserException | ImportAlreadyExistsException e) {
throw e;
} catch (Exception e) {
throw new ImportParserException(e);
@@ -17,7 +17,6 @@
package de.dennisguse.opentracks.util;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -53,36 +52,4 @@ public class DialogUtils {
.setTitle(titleId).create();
}
/**
* Creates a horizontal progress dialog.
*
* @param context the context
* @param messageId the progress message id
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the messageId
*/
public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
return createProgressDialog(context, messageId, onCancelListener, formatArgs);
}
/**
* Creates a progress dialog.
*
* @param context the context
* @param messageId the progress message id
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the message id
*/
private static ProgressDialog createProgressDialog(final Context context, int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
final ProgressDialog progressDialog = new ProgressDialog(context, R.style.ThemeCustomNotTransparentDialog);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setIcon(R.drawable.ic_dialog_info_24dp);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(context.getString(messageId, formatArgs));
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
}
}
@@ -15,7 +15,7 @@ import de.dennisguse.opentracks.util.UnitConversions;
public class IntervalStatisticsModel {
private IntervalStatistics intervalStats;
private List<TrackPoint> trackPoints = new ArrayList<>();
private final List<TrackPoint> trackPoints = new ArrayList<>();
public IntervalStatistics getIntervalStats(boolean metricUnits, @Nullable IntervalOption interval) {
synchronized (trackPoints) {
@@ -55,7 +55,7 @@ public class IntervalStatisticsModel {
OPTION_20(20),
OPTION_50(50);
private int value;
private final int value;
IntervalOption(int value) {
this.value = value;