forked from upstream-mirrors/OpenTracks
Code cleanup.
This commit is contained in:
@@ -209,7 +209,7 @@ public class IntervalsFragment extends Fragment implements TrackDataListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
runOnUiThread(() -> loadIntervals());
|
runOnUiThread(this::loadIntervals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,17 +64,14 @@ public class StatisticsRecordingFragment extends Fragment implements TrackDataLi
|
|||||||
return new StatisticsRecordingFragment();
|
return new StatisticsRecordingFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (preferences, key) -> {
|
||||||
@Override
|
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
if (isResumed()) {
|
||||||
if (PreferencesUtils.isKey(getContext(), R.string.stats_units_key, key) || PreferencesUtils.isKey(getContext(), R.string.stats_rate_key, key)) {
|
getActivity().runOnUiThread(() -> {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
getActivity().runOnUiThread(() -> {
|
updateUI();
|
||||||
if (isResumed()) {
|
}
|
||||||
updateUI();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
|
|||||||
private static final String TAG = ImportViewModel.class.getSimpleName();
|
private static final String TAG = ImportViewModel.class.getSimpleName();
|
||||||
|
|
||||||
private MutableLiveData<Summary> importData;
|
private MutableLiveData<Summary> importData;
|
||||||
private ImportServiceResultReceiver resultReceiver;
|
private final ImportServiceResultReceiver resultReceiver;
|
||||||
private Summary summary;
|
private final Summary summary;
|
||||||
private boolean cancel = false;
|
private boolean cancel = false;
|
||||||
private List<DocumentFile> filesToImport = new ArrayList<>();
|
private final List<DocumentFile> filesToImport = new ArrayList<>();
|
||||||
|
|
||||||
public ImportViewModel(@NonNull Application application) {
|
public ImportViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
@@ -47,9 +47,7 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
|
|||||||
private void loadData(DocumentFile documentFile) {
|
private void loadData(DocumentFile documentFile) {
|
||||||
List<DocumentFile> fileList = FileUtils.getFiles(documentFile);
|
List<DocumentFile> fileList = FileUtils.getFiles(documentFile);
|
||||||
summary.totalCount = fileList.size();
|
summary.totalCount = fileList.size();
|
||||||
for (DocumentFile df : fileList) {
|
filesToImport.addAll(fileList);
|
||||||
filesToImport.add(df);
|
|
||||||
}
|
|
||||||
importNextFile();
|
importNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,12 +87,12 @@ public class ImportViewModel extends AndroidViewModel implements ImportServiceRe
|
|||||||
importNextFile();
|
importNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Summary {
|
public static class Summary {
|
||||||
private int totalCount;
|
private int totalCount;
|
||||||
private int successCount;
|
private int successCount;
|
||||||
private int existsCount;
|
private int existsCount;
|
||||||
private int errorCount;
|
private int errorCount;
|
||||||
private ArrayList<String> fileErrors = new ArrayList<>();
|
private final ArrayList<String> fileErrors = new ArrayList<>();
|
||||||
|
|
||||||
public int getTotalCount() {
|
public int getTotalCount() {
|
||||||
return totalCount;
|
return totalCount;
|
||||||
|
|||||||
@@ -190,10 +190,7 @@ public class KmzTrackImporter implements TrackImporter {
|
|||||||
zipInputStream.closeEntry();
|
zipInputStream.closeEntry();
|
||||||
}
|
}
|
||||||
return trackId;
|
return trackId;
|
||||||
} catch (ImportParserException e) {
|
} catch (ImportParserException | ImportAlreadyExistsException e) {
|
||||||
Log.e(TAG, "Unable to import file", e);
|
|
||||||
throw e;
|
|
||||||
} catch (ImportAlreadyExistsException e) {
|
|
||||||
Log.e(TAG, "Unable to import file", e);
|
Log.e(TAG, "Unable to import file", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -259,9 +256,7 @@ public class KmzTrackImporter implements TrackImporter {
|
|||||||
|
|
||||||
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getKml(zipInputStream))) {
|
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getKml(zipInputStream))) {
|
||||||
return kmlFileTrackImporter.importFile(byteArrayInputStream);
|
return kmlFileTrackImporter.importFile(byteArrayInputStream);
|
||||||
} catch (ImportParserException e) {
|
} catch (ImportParserException | ImportAlreadyExistsException e) {
|
||||||
throw e;
|
|
||||||
} catch (ImportAlreadyExistsException e) {
|
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ImportParserException(e);
|
throw new ImportParserException(e);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package de.dennisguse.opentracks.util;
|
package de.dennisguse.opentracks.util;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
|
||||||
@@ -53,36 +52,4 @@ public class DialogUtils {
|
|||||||
.setTitle(titleId).create();
|
.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 {
|
public class IntervalStatisticsModel {
|
||||||
|
|
||||||
private IntervalStatistics intervalStats;
|
private IntervalStatistics intervalStats;
|
||||||
private List<TrackPoint> trackPoints = new ArrayList<>();
|
private final List<TrackPoint> trackPoints = new ArrayList<>();
|
||||||
|
|
||||||
public IntervalStatistics getIntervalStats(boolean metricUnits, @Nullable IntervalOption interval) {
|
public IntervalStatistics getIntervalStats(boolean metricUnits, @Nullable IntervalOption interval) {
|
||||||
synchronized (trackPoints) {
|
synchronized (trackPoints) {
|
||||||
@@ -55,7 +55,7 @@ public class IntervalStatisticsModel {
|
|||||||
OPTION_20(20),
|
OPTION_20(20),
|
||||||
OPTION_50(50);
|
OPTION_50(50);
|
||||||
|
|
||||||
private int value;
|
private final int value;
|
||||||
|
|
||||||
IntervalOption(int value) {
|
IntervalOption(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user