Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group-8 : SonarQube suggested changes for Fragments folder #47

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8d919e1
GH-1 : Added override to the function as suggested by SonarQube
kevwad Feb 11, 2024
36cf23f
Merge pull request #2 from dneha1210/kevwad/40261875-Issue-1
kevwad Feb 12, 2024
27b7598
Add 'since' and/or 'forRemoval' arguments to the @Depracated annotation
RushiDonga Feb 12, 2024
cd4f4b1
Merge pull request #4 from dneha1210/issues_Rushi
RushiDonga Feb 12, 2024
63a4478
Remove this unused TAG private field
mehtavandit Feb 12, 2024
352d0b5
Merge pull request #6 from dneha1210/issues_Vandit
mehtavandit Feb 12, 2024
5db949d
Remove this unused method parameter context.
RushiDonga Feb 12, 2024
01d7b2c
Merge branch 'main' into issues_Rushi
RushiDonga Feb 12, 2024
5a0d203
Merge pull request #8 from dneha1210/issues_Rushi
RushiDonga Feb 12, 2024
93d38e3
Renamed "track" to "trackWithId"
Blesslin40266442 Feb 13, 2024
a4478d2
Merge pull request #10 from dneha1210/blesslin
Blesslin40266442 Feb 13, 2024
88123f4
Renamed "track" to "trackWithId". Issue - GH#9
Blesslin40266442 Feb 13, 2024
a2f0609
Merge pull request #11 from dneha1210/blesslin
Blesslin40266442 Feb 13, 2024
b29d3d2
GH-12: Renamed altitudeGain_n to altitudeGain to match the expected c…
kevwad Feb 13, 2024
753f202
Merge pull request #13 from dneha1210/kevwad/rename-local-var
kevwad Feb 13, 2024
4e35fb6
Extract nested code block into a method (#15)
romit-gitcode Feb 13, 2024
881f895
GH-16
dneha1210 Feb 13, 2024
0d586d5
Merge pull request #17 from dneha1210/neha
dneha1210 Feb 13, 2024
70a0482
Update StatisticsRecordedFragment.java
SrujithaYeruva Feb 14, 2024
9aecbc1
Merge pull request #19 from SrujithaYeruva/main
SrujithaYeruva Feb 14, 2024
1b17061
Made change in src/main/java/de/dennisguse/opentracks/fragments/Choos…
dneha1210 Feb 15, 2024
c9b1e2a
GH-21 Changed the altitudeLoss_m to altitudeLoss.
adharsh2608 Feb 16, 2024
177772a
Merge pull request #22 from dneha1210/adharsh/GH-21
adharsh2608 Feb 16, 2024
dd2c37c
Merge branch 'main' into main
kevwad Feb 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
apply plugin: 'com.android.application'

buildscript {
repositories {
google()
Expand All @@ -10,6 +8,12 @@ buildscript {
}
}

plugins {
id "org.sonarqube" version "4.4.1.3373"
}

apply plugin: 'com.android.application'

allprojects {
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment implements

private static final String CHOOSE_ACTIVITY_TYPE_DIALOG_TAG = "chooseActivityType";

@Deprecated
/**
* @deprecated
*/
@Deprecated(since="4.2", forRemoval=true)
public static void showDialog(FragmentManager fragmentManager, Context context, String activityTypeLocalized) {
ActivityType activityType = ActivityType.findByLocalizedString(context, activityTypeLocalized);
showDialog(fragmentManager, activityType);
}

/**
* @deprecated
*/
@Deprecated(since="4.2", forRemoval=true)
public static void showDialog(FragmentManager fragmentManager, ActivityType activityType) {
new ChooseActivityTypeDialogFragment(activityType).show(fragmentManager, ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
}
Expand Down Expand Up @@ -57,7 +64,7 @@ public static void showDialog(FragmentManager fragmentManager, ActivityType acti
ActivityType.WORKOUT
);

private static int getPosition(Context context, ActivityType activityType) {
private static int getPosition(ActivityType activityType) {
if (activityType == null) {
return -1;
}
Expand Down Expand Up @@ -93,7 +100,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}

final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(iconDrawableIds);
int position = getPosition(getContext(), preselectedActivityType);
int position = getPosition(preselectedActivityType);
if (position != -1) {
imageAdapter.setSelected(position);
}
Expand All @@ -103,6 +110,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
return viewBinding.getRoot();
}

@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.DistanceFormatter;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.SpeedFormatter;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.databinding.StatisticsRecordedBinding;
Expand All @@ -45,7 +46,8 @@
import de.dennisguse.opentracks.util.StringUtils;

/**
* A fragment to display track statistics to the user for a recorded {@link Track}.
* A fragment to display track statistics to the user for a recorded
* {@link Track}.
*
* @author Sandor Dornbush
* @author Rodrigo Damazio
Expand Down Expand Up @@ -78,7 +80,8 @@ public static StatisticsRecordedFragment newInstance(Track.Id trackId) {
private UnitSystem unitSystem = UnitSystem.defaultUnitSystem();
private boolean preferenceReportSpeed;

private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (sharedPreferences, key) -> {
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (
sharedPreferences, key) -> {
boolean updateUInecessary = false;

if (PreferencesUtils.isKey(R.string.stats_units_key, key)) {
Expand Down Expand Up @@ -141,26 +144,29 @@ public void loadStatistics() {
if (isResumed()) {
getActivity().runOnUiThread(() -> {
if (isResumed()) {
Track track = contentProviderUtils.getTrack(trackId);
if (track == null) {
Log.e(TAG, "track cannot be null");
Track trackWithIds = contentProviderUtils.getTrack(trackId);
if (trackWithIds == null) {
Log.e(TAG, "trackWithIds cannot be null");
getActivity().finish();
return;
}

sensorStatistics = contentProviderUtils.getSensorStats(trackId);

boolean prefsChanged = this.track == null || (!this.track.getActivityTypeLocalized().equals(track.getActivityTypeLocalized()));
this.track = track;
boolean prefsChanged = this.track == null
|| (!this.track.getActivityTypeLocalized().equals(trackWithIds.getActivityTypeLocalized()));
this.track = trackWithIds;
if (prefsChanged) {
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, getString(R.string.stats_rate_key));
sharedPreferenceChangeListener.onSharedPreferenceChanged(null,
getString(R.string.stats_rate_key));
}

loadTrackDescription(track);
loadTrackDescription(trackWithIds);
updateUI();
updateSensorUI();

((TrackRecordedActivity) getActivity()).startPostponedEnterTransitionWith(viewBinding.statsActivityTypeIcon);
((TrackRecordedActivity) getActivity())
.startPostponedEnterTransitionWith(viewBinding.statsActivityTypeIcon);
}
});
}
Expand All @@ -169,82 +175,102 @@ public void loadStatistics() {
private void loadTrackDescription(@NonNull Track track) {
viewBinding.statsNameValue.setText(track.getName());
viewBinding.statsDescriptionValue.setText(track.getDescription());
viewBinding.statsStartDatetimeValue.setText(StringUtils.formatDateTimeWithOffsetIfDifferent(track.getStartTime()));
viewBinding.statsStartDatetimeValue
.setText(StringUtils.formatDateTimeWithOffsetIfDifferent(track.getStartTime()));
}

private void updateUISetTotalDistance(TrackStatistics trackStatistics) {
Pair<String, String> parts = DistanceFormatter.Builder()
.setUnit(unitSystem)
.build(getContext()).getDistanceParts(trackStatistics.getTotalDistance());

viewBinding.statsDistanceValue.setText(parts.first);
viewBinding.statsDistanceUnit.setText(parts.second);

}

private void updateUISetActivityType() {
Context context = getContext();
String localizedActivityType = track.getActivityTypeLocalized();
int iconDrawableId = ActivityType.findByLocalizedString(context, localizedActivityType)
.getIconDrawableId();
viewBinding.statsActivityTypeIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), iconDrawableId));
}

private void updatedUISetTimeAndStartDatetime(TrackStatistics trackStatistics) {
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getMovingTime()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getTotalTime()));
}

private void updatedAverageSpeed(TrackStatistics trackStatistics, SpeedFormatter formatter) {
viewBinding.statsAverageSpeedLabel
.setText(preferenceReportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getAverageSpeed());
viewBinding.statsAverageSpeedValue.setText(parts.first);
viewBinding.statsAverageSpeedUnit.setText(parts.second);
}

private void updatedMaxSpeed(TrackStatistics trackStatistics, SpeedFormatter formatter) {
viewBinding.statsMaxSpeedLabel
.setText(preferenceReportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getMaxSpeed());
viewBinding.statsMaxSpeedValue.setText(parts.first);
viewBinding.statsMaxSpeedUnit.setText(parts.second);
}

private void updatedSetMovingSpeed(TrackStatistics trackStatistics, SpeedFormatter formatter) {
viewBinding.statsMovingSpeedLabel.setText(
preferenceReportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getAverageMovingSpeed());
viewBinding.statsMovingSpeedValue.setText(parts.first);
viewBinding.statsMovingSpeedUnit.setText(parts.second);
}

private void updatedSetAltitudeGainAndLoss(TrackStatistics trackStatistics) {
Float altitudeGain = trackStatistics.getTotalAltitudeGain();
Float altitudeLoss = trackStatistics.getTotalAltitudeLoss();

Pair<String, String> parts;

parts = StringUtils.getAltitudeParts(getContext(), altitudeGain, unitSystem);
viewBinding.statsAltitudeGainValue.setText(parts.first);
viewBinding.statsAltitudeGainUnit.setText(parts.second);

parts = StringUtils.getAltitudeParts(getContext(), altitudeLoss, unitSystem);
viewBinding.statsAltitudeLossValue.setText(parts.first);
viewBinding.statsAltitudeLossUnit.setText(parts.second);

boolean show = altitudeGain != null && altitudeLoss != null;
viewBinding.statsAltitudeGroup.setVisibility(show ? View.VISIBLE : View.GONE);
}

private void updateUI() {
TrackStatistics trackStatistics = track.getTrackStatistics();
// Set total distance
{
Pair<String, String> parts = DistanceFormatter.Builder()
.setUnit(unitSystem)
.build(getContext()).getDistanceParts(trackStatistics.getTotalDistance());

viewBinding.statsDistanceValue.setText(parts.first);
viewBinding.statsDistanceUnit.setText(parts.second);
}
updateUISetTotalDistance(trackStatistics);

// Set activity type
{
Context context = getContext();
String localizedActivityType = track.getActivityTypeLocalized();
int iconDrawableId = ActivityType.findByLocalizedString(context, localizedActivityType)
.getIconDrawableId();
viewBinding.statsActivityTypeIcon.setImageDrawable(ContextCompat.getDrawable(getContext(), iconDrawableId));
}
updateUISetActivityType();

// Set time and start datetime
{
viewBinding.statsMovingTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getMovingTime()));
viewBinding.statsTotalTimeValue.setText(StringUtils.formatElapsedTime(trackStatistics.getTotalTime()));
}
updatedUISetTimeAndStartDatetime(trackStatistics);

SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(preferenceReportSpeed).build(getContext());
SpeedFormatter formatter = SpeedFormatter.Builder().setUnit(unitSystem)
.setReportSpeedOrPace(preferenceReportSpeed).build(getContext());
// Set average speed/pace
{
viewBinding.statsAverageSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getAverageSpeed());
viewBinding.statsAverageSpeedValue.setText(parts.first);
viewBinding.statsAverageSpeedUnit.setText(parts.second);
}
updatedAverageSpeed(trackStatistics, formatter);

// Set max speed/pace
{
viewBinding.statsMaxSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_max_speed : R.string.stats_fastest_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getMaxSpeed());
viewBinding.statsMaxSpeedValue.setText(parts.first);
viewBinding.statsMaxSpeedUnit.setText(parts.second);
}
updatedMaxSpeed(trackStatistics, formatter);

// Set moving speed/pace
{
viewBinding.statsMovingSpeedLabel.setText(preferenceReportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);

Pair<String, String> parts = formatter.getSpeedParts(trackStatistics.getAverageMovingSpeed());
viewBinding.statsMovingSpeedValue.setText(parts.first);
viewBinding.statsMovingSpeedUnit.setText(parts.second);
}
updatedSetMovingSpeed(trackStatistics, formatter);

// Set altitude gain and loss
{
Float altitudeGain_m = trackStatistics.getTotalAltitudeGain();
Float altitudeLoss_m = trackStatistics.getTotalAltitudeLoss();

Pair<String, String> parts;

parts = StringUtils.getAltitudeParts(getContext(), altitudeGain_m, unitSystem);
viewBinding.statsAltitudeGainValue.setText(parts.first);
viewBinding.statsAltitudeGainUnit.setText(parts.second);

parts = StringUtils.getAltitudeParts(getContext(), altitudeLoss_m, unitSystem);
viewBinding.statsAltitudeLossValue.setText(parts.first);
viewBinding.statsAltitudeLossUnit.setText(parts.second);

boolean show = altitudeGain_m != null && altitudeLoss_m != null;
viewBinding.statsAltitudeGroup.setVisibility(show ? View.VISIBLE : View.GONE);
}
updatedSetAltitudeGainAndLoss(trackStatistics);
}

private void updateSensorUI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
*/
public class StatisticsRecordingFragment extends Fragment {

private static final String TAG = StatisticsRecordingFragment.class.getSimpleName();

public static Fragment newInstance() {
return new StatisticsRecordingFragment();
}
Expand Down