Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #293 from rilling/group_11
Browse files Browse the repository at this point in the history
Group 11
  • Loading branch information
yashvadaria authored Nov 27, 2023
2 parents a0b6c47 + 661c30f commit 61cc5fe
Show file tree
Hide file tree
Showing 19 changed files with 304 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
Binary file added src/main/java/de/.DS_Store
Binary file not shown.
Binary file added src/main/java/de/dennisguse/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<RecyclerView.ViewHolder> {

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand All @@ -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<String, String> 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<String, String> 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<String, String> 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);

Expand Down
Binary file added src/main/res/.DS_Store
Binary file not shown.
35 changes: 34 additions & 1 deletion src/main/res/layout/aggregated_stats_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
app:layout_constraintTop_toTopOf="@+id/aggregated_stats_type_label"
tools:text="(1)" />


<!-- Distance -->
<TextView
android:id="@+id/aggregated_stats_distance"
Expand Down Expand Up @@ -166,12 +167,44 @@
app:layout_constraintTop_toBottomOf="@+id/aggregated_stats_max_rate"
tools:text="@string/stats_max_speed" />

<!-- Elevation Gain -->
<TextView
android:id="@+id/aggregated_stats_elevation_gain"
style="@style/TextAppearance.OpenTracks.SecondaryValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="@id/guideline2"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintTop_toBottomOf="@+id/aggregated_stats_avg_rate_label"
tools:text="500" />

<TextView
android:id="@+id/aggregated_stats_elevation_gain_label"
style="@style/TextAppearance.OpenTracks.SecondaryHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="@id/guideline2"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintTop_toBottomOf="@+id/aggregated_stats_elevation_gain"
tools:text="Elevation Gain" />

<TextView
android:id="@+id/aggregated_stats_elevation_gain_unit"
style="@style/TextAppearance.OpenTracks.PrimaryUnit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/aggregated_stats_elevation_gain"
app:layout_constraintStart_toEndOf="@+id/aggregated_stats_elevation_gain"
tools:text="ft" />

<View
android:id="@+id/aggregated_stats_horizontal_line"
style="@style/HorizontalLine"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintEnd_toStartOf="@id/guideline3"
app:layout_constraintTop_toBottomOf="@id/aggregated_stats_max_rate_label" />
app:layout_constraintTop_toBottomOf="@id/aggregated_stats_elevation_gain_label" />

</androidx.constraintlayout.widget.ConstraintLayout>
12 changes: 12 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

<string name="settings_import_export_key" translatable="false">settingsImportExport</string>

<string name="settings_aggregated_stats_key" translatable="false">settingsAggregatedStats</string>

<!-- Setting's categories -->

<string name="settings_reset_key" translatable="false">settingsReset</string>
Expand Down Expand Up @@ -294,6 +296,16 @@
<string name="settings_api_key" translatable="false">settingsAPI</string>
<string name="publicapi_package_key" translatable="false">apiPackageKey</string>
<string name="publicapi_enabled_key" translatable="false">apiEnabledKey</string>
<string name="aggregated_stats_package_key" translatable="false">AggregatedStatsPackageKey</string>
<bool name="aggregated_stats_enabled_default">false</bool>
<string name="distance_preference_key" translatable="false">DistancePreferenceKey</string>
<string name="max_speed_preference_key" translatable="false">MaxSpeedPreferenceKey</string>
<string name="moving_speed_preference_key" translatable="false">MovingSpeedPreferenceKey</string>
<string name="stats_moving_speed" translatable="false">Moving Speed</string>
<string name="moving_time_preference_key" translatable="false">MovingTimePreferenceKey</string>
<string name="stats_time_speed" translatable="false">Average Moving Time</string>


<bool name="publicapi_enabled_default">false</bool>
<string name="publicapi_dashboard_enabled_key" translatable="false">apiDashboardEnabledKey</string>
<bool name="publicapi_dashboard_enabled_default">false</bool>
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ limitations under the License.
<string name="settings_stats_units_nautical">Nautical (NM, ft)</string>
<string name="settings_stats_units_title">Preferred units</string>

<!-- Settings Aggregated stats -->
<string name="settings_aggregated_stats">Aggregated Stats</string>
<string name="settings_aggregated_stats_summary">Choose your own stats</string>
<string name="settings_elevation_gain">Elevation Gain</string>

<!-- Settings public api -->
<string name="settings_api_title">Public API</string>
<string name="settings_api_summary">Remote control and statistics API for other apps</string>
Expand Down
6 changes: 6 additions & 0 deletions src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
android:summary="@string/settings_api_summary"
android:title="@string/settings_api_title" />

<Preference
android:icon="@drawable/ic_statistics_24dp"
android:key="@string/settings_aggregated_stats_key"
android:summary="@string/settings_aggregated_stats_summary"
android:title="@string/settings_aggregated_stats" />

<Preference
android:icon="@drawable/ic_baseline_info_24"
android:summary="@string/settings_open_tracks_summary"
Expand Down
Loading

0 comments on commit 61cc5fe

Please sign in to comment.