diff --git a/build.gradle b/build.gradle index 8823dc5fd..01dc59700 100644 --- a/build.gradle +++ b/build.gradle @@ -21,8 +21,8 @@ apply plugin: 'org.sonarqube' sonarqube { properties { - property "sonar.projectName", "Group 8 SOEN 6431" - property "sonar.projectKey", "Group-8-SOEN-6431" + property "sonar.projectName", "Group 11 SOEN 6431" + property "sonar.projectKey", "Group-11-SOEN-6431" property "sonar.host.url", "http://localhost:9000" property "sonar.login", "sqp_7f8adc6706b839b752be96c5d687384252602ab5" } diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 000000000..125d765cc Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 000000000..eb93551af Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 000000000..eaf3024af Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/de/.DS_Store b/src/main/java/de/.DS_Store new file mode 100644 index 000000000..43ed06e61 Binary files /dev/null and b/src/main/java/de/.DS_Store differ diff --git a/src/main/java/de/dennisguse/.DS_Store b/src/main/java/de/dennisguse/.DS_Store new file mode 100644 index 000000000..cfe91c46e Binary files /dev/null and b/src/main/java/de/dennisguse/.DS_Store differ diff --git a/src/main/java/de/dennisguse/opentracks/.DS_Store b/src/main/java/de/dennisguse/opentracks/.DS_Store new file mode 100644 index 000000000..d78f26285 Binary files /dev/null and b/src/main/java/de/dennisguse/opentracks/.DS_Store differ diff --git a/src/main/java/de/dennisguse/opentracks/settings/AggregatedStatsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/AggregatedStatsSettingsFragment.java new file mode 100644 index 000000000..ede8f270e --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/settings/AggregatedStatsSettingsFragment.java @@ -0,0 +1,23 @@ +package de.dennisguse.opentracks.settings; + +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; + +import de.dennisguse.opentracks.BuildConfig; +import de.dennisguse.opentracks.R; + +public class AggregatedStatsSettingsFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.settings_aggregated_stats); + } + + @Override + public void onStart() { + super.onStart(); + ((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.settings_aggregated_stats); + findPreference(getString(R.string.settings_aggregated_stats_key)); + } +} diff --git a/src/main/java/de/dennisguse/opentracks/settings/MainSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/MainSettingsFragment.java index fb57c4cad..da1bf367f 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/MainSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/MainSettingsFragment.java @@ -50,6 +50,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { return true; }); + findPreference(getString(R.string.settings_aggregated_stats_key)).setOnPreferenceClickListener(preference -> { + ((SettingsActivity) getActivity()).openScreen(getString(R.string.settings_aggregated_stats_key)); + return true; + }); + findPreference(getString(R.string.user_profile)).setOnPreferenceClickListener(preference -> { ((SettingsActivity) getActivity()).openScreen(getString(R.string.user_profile)); return true; diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java index 9ed4ee1ab..cda505284 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java @@ -462,6 +462,46 @@ public static void setVoiceAnnounceAverageHeartRate(boolean value) { setBoolean(R.string.voice_announce_average_heart_rate_key, value); } + public static boolean shouldElevationGain() { + return getBoolean(R.string.aggregated_stats_package_key, false); + } + + @VisibleForTesting + public static void setElevationGain(boolean value) { + setBoolean(R.string.aggregated_stats_package_key, value); + } + + public static boolean shouldDistance() { + Log.d("myLogs", String.valueOf(R.string.distance_preference_key)); + return getBoolean(R.string.distance_preference_key, false); + } + + @VisibleForTesting + public static void setDistance(boolean value) { + setBoolean(R.string.distance_preference_key, value); + } + + public static boolean shouldMaxSpeed() { + return getBoolean(R.string.max_speed_preference_key, false); + } + + @VisibleForTesting + public static void setMaxSpeed(boolean value) { + setBoolean(R.string.distance_preference_key, value); + } + + public static boolean shouldMovingSpeed() { + return getBoolean(R.string.moving_speed_preference_key, false); + } + + @VisibleForTesting + public static void setMovingSpeed(boolean value) { + setBoolean(R.string.moving_speed_preference_key, value); + } + public static boolean shouldMovingTime() { + return getBoolean(R.string.moving_time_preference_key, false); + } + public static Distance getRecordingDistanceInterval() { return Distance.of(getInt(R.string.recording_distance_interval_key, getRecordingDistanceIntervalDefaultInternal())); } diff --git a/src/main/java/de/dennisguse/opentracks/settings/SettingsActivity.java b/src/main/java/de/dennisguse/opentracks/settings/SettingsActivity.java index 6a5c2de4a..b3ffd3880 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/SettingsActivity.java +++ b/src/main/java/de/dennisguse/opentracks/settings/SettingsActivity.java @@ -94,9 +94,12 @@ private PreferenceFragmentCompat getPreferenceScreen(String key) { fragment = new ImportExportSettingsFragment(); } else if (key.equals(getString(R.string.settings_api_key))) { fragment = new PublicAPISettingsFragment(); + } else if (key.equals(getString(R.string.settings_aggregated_stats_key))) { + fragment = new AggregatedStatsSettingsFragment(); } else if (key.equals(getString(R.string.user_profile))) { fragment = new UserProfileSettingsFragment(); } + return fragment; } diff --git a/src/main/java/de/dennisguse/opentracks/ui/.DS_Store b/src/main/java/de/dennisguse/opentracks/ui/.DS_Store new file mode 100644 index 000000000..28a20b109 Binary files /dev/null and b/src/main/java/de/dennisguse/opentracks/ui/.DS_Store differ diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java index 9cb2e7c8f..add67c6fc 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java @@ -1,6 +1,7 @@ package de.dennisguse.opentracks.ui.aggregatedStatistics; import android.content.Context; +import android.util.Log; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -20,7 +21,13 @@ import de.dennisguse.opentracks.data.models.SpeedFormatter; import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.UnitSystem; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.StringUtils; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldElevationGain; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldDistance; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMaxSpeed; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMovingSpeed; +import static de.dennisguse.opentracks.settings.PreferencesUtils.shouldMovingTime; public class AggregatedStatisticsAdapter extends RecyclerView.Adapter { @@ -48,6 +55,35 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi String type = aggregatedStatistic.getActivityTypeLocalized(); if (ActivityType.findByLocalizedString(context, type).isShowSpeedPreferred()) { viewHolder.setSpeed(aggregatedStatistic); + if(shouldElevationGain()) { + viewHolder.setElevation(aggregatedStatistic); + } + if(shouldDistance()) { + Log.d("myLogs", "ShouldDistance is called"); + viewHolder.setDistance(aggregatedStatistic, true); + } + else { + Log.d("myLogs", "Inside Else"); + viewHolder.setDistance(aggregatedStatistic, false); + } + if(shouldMaxSpeed()) { + viewHolder.setMaxSpeed(aggregatedStatistic, true); + } + else { + viewHolder.setMaxSpeed(aggregatedStatistic, false); + } + if(shouldMovingSpeed()){ + viewHolder.setMovingSpeed(aggregatedStatistic, true); + } + else { + viewHolder.setMovingSpeed(aggregatedStatistic, false); + } + if(shouldMovingTime()){ + viewHolder.setMovingTime(aggregatedStatistic, true); + } + else { + viewHolder.setMovingTime(aggregatedStatistic, false); + } } else { viewHolder.setPace(aggregatedStatistic); } @@ -89,6 +125,10 @@ private class ViewHolder extends RecyclerView.ViewHolder { private final TextView maxSpeedUnit; private final TextView maxSpeedLabel; + private TextView elevationGain = null; + private TextView elevationLabel = null; + private TextView elevationUnit = null; + private UnitSystem unitSystem = UnitSystem.defaultUnitSystem(); private boolean reportSpeed; @@ -100,15 +140,107 @@ public ViewHolder(View view) { distance = view.findViewById(R.id.aggregated_stats_distance); distanceUnit = view.findViewById(R.id.aggregated_stats_distance_unit); time = view.findViewById(R.id.aggregated_stats_time); - avgSpeed = view.findViewById(R.id.aggregated_stats_avg_rate); avgSpeedUnit = view.findViewById(R.id.aggregated_stats_avg_rate_unit); avgSpeedLabel = view.findViewById(R.id.aggregated_stats_avg_rate_label); maxSpeed = view.findViewById(R.id.aggregated_stats_max_rate); maxSpeedUnit = view.findViewById(R.id.aggregated_stats_max_rate_unit); maxSpeedLabel = view.findViewById(R.id.aggregated_stats_max_rate_label); + if(shouldElevationGain()) { + elevationGain = view.findViewById(R.id.aggregated_stats_elevation_gain); + elevationLabel = view.findViewById(R.id.aggregated_stats_elevation_gain_label); + elevationUnit = view.findViewById(R.id.aggregated_stats_elevation_gain_unit); + + elevationLabel.setText("Elevation Gain"); + elevationUnit.setText("ft"); + } + } + public void setElevation(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) { + if(aggregatedStatistic.getTrackStatistics().getTotalAltitudeGain()==null) + elevationGain.setText("0.0"); + else + elevationGain.setText(aggregatedStatistic.getTrackStatistics().getTotalAltitudeGain().toString()); + System.out.println(); + } + + public void setDistance(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + if(visibility) { + if (aggregatedStatistic.getTrackStatistics().getTotalDistance() == null) { + Log.d("myLogs", "aggregate value is null"); + distance.setText("0.0"); + } else { + Log.d("myLogs", "Visibility true, setting value in else"); + Pair parts = DistanceFormatter.Builder() + .setUnit(unitSystem) + .build(context).getDistanceParts(aggregatedStatistic.getTrackStatistics().getTotalDistance()); + distance.setText(parts.first); + distanceUnit.setText(parts.second); + } + } + else{ + Log.d("myLogs", "Visibility is false"); + distance.setText(""); + distanceUnit.setText(""); + } } + public void setMaxSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context); + if(visibility){ + if(aggregatedStatistic.getTrackStatistics().getMaxSpeed() ==null) + maxSpeed.setText("0.0"); + + else + { + Pair parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed()); + maxSpeed.setText(parts.first); + maxSpeedUnit.setText(parts.second); + maxSpeedLabel.setText(context.getString(R.string.stats_max_speed)); + } + } + else{ + maxSpeed.setText(""); + maxSpeedUnit.setText(""); + maxSpeedLabel.setText(""); + } + + } + + public void setMovingSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context); + if(visibility){ + if(aggregatedStatistic.getTrackStatistics().getMaxSpeed() ==null) + avgSpeed.setText("0.0"); + else + { + Pair parts = formatter.getSpeedParts(aggregatedStatistic.getTrackStatistics().getMaxSpeed()); + avgSpeed.setText(parts.first); + avgSpeedUnit.setText(parts.second); + avgSpeedLabel.setText(context.getString(R.string.stats_max_speed)); + } + } + else{ + avgSpeed.setText(""); + avgSpeedUnit.setText(""); + avgSpeedLabel.setText(""); + } + + } + public void setMovingTime(AggregatedStatistics.AggregatedStatistic aggregatedStatistic, Boolean visibility) { + SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(reportSpeed).build(context); + if(visibility){ + if(aggregatedStatistic.getTrackStatistics().getMaxSpeed() ==null) + time.setText("0.0"); + else + { + time.setText(StringUtils.formatElapsedTime(aggregatedStatistic.getTrackStatistics().getMovingTime())); + } + } + else{ + time.setText(""); + } + + } public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) { setCommonValues(aggregatedStatistic); diff --git a/src/main/res/.DS_Store b/src/main/res/.DS_Store new file mode 100644 index 000000000..f4ef853db Binary files /dev/null and b/src/main/res/.DS_Store differ diff --git a/src/main/res/layout/aggregated_stats_list_item.xml b/src/main/res/layout/aggregated_stats_list_item.xml index 7b148cb0f..99087e414 100644 --- a/src/main/res/layout/aggregated_stats_list_item.xml +++ b/src/main/res/layout/aggregated_stats_list_item.xml @@ -66,6 +66,7 @@ app:layout_constraintTop_toTopOf="@+id/aggregated_stats_type_label" tools:text="(1)" /> + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/aggregated_stats_elevation_gain_label" /> \ No newline at end of file diff --git a/src/main/res/values/settings.xml b/src/main/res/values/settings.xml index 570a38fe7..80095c4fa 100644 --- a/src/main/res/values/settings.xml +++ b/src/main/res/values/settings.xml @@ -24,6 +24,8 @@ settingsImportExport + settingsAggregatedStats + settingsReset @@ -294,6 +296,16 @@ settingsAPI apiPackageKey apiEnabledKey + AggregatedStatsPackageKey + false + DistancePreferenceKey + MaxSpeedPreferenceKey + MovingSpeedPreferenceKey + Moving Speed + MovingTimePreferenceKey + Average Moving Time + + false apiDashboardEnabledKey false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 344492de2..fbabcec7a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -478,6 +478,11 @@ limitations under the License. Nautical (NM, ft) Preferred units + + Aggregated Stats + Choose your own stats + Elevation Gain + Public API Remote control and statistics API for other apps diff --git a/src/main/res/xml/settings.xml b/src/main/res/xml/settings.xml index c7d713343..47463a4e4 100644 --- a/src/main/res/xml/settings.xml +++ b/src/main/res/xml/settings.xml @@ -62,6 +62,12 @@ android:summary="@string/settings_api_summary" android:title="@string/settings_api_title" /> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file