mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-10 05:03:06 +02:00
Add an activity setup button in stat page when the activity type is not support to calculate calorie.
This commit is contained in:
@@ -285,7 +285,7 @@ public class CalorieUtils {
|
||||
return TripStatistics.INVALID_CALORIE;
|
||||
}
|
||||
|
||||
double calorie = 0;
|
||||
double calorie = 0.0;
|
||||
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
long trackId = track.getId();
|
||||
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false,
|
||||
|
||||
@@ -16,12 +16,16 @@
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.TrackEditActivity;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -110,7 +114,7 @@ public class StatsUtils {
|
||||
* @param tripStatistics the trip statistics
|
||||
* @param trackId the id of track
|
||||
*/
|
||||
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
|
||||
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics, long trackId) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
|
||||
|
||||
@@ -188,7 +192,7 @@ public class StatsUtils {
|
||||
if (tripStatistics != null) {
|
||||
calories = tripStatistics.getCalorie();
|
||||
}
|
||||
setCalorie(activity, R.id.stats_calorie, calories);
|
||||
setCalorie(activity, R.id.stats_calorie, calories, trackId);
|
||||
} else {
|
||||
calorieHorizontalLine.setVisibility(View.GONE);
|
||||
calorieContainer.setVisibility(View.GONE);
|
||||
@@ -341,15 +345,37 @@ public class StatsUtils {
|
||||
* @param activity the activity
|
||||
* @param itemId the item id
|
||||
* @param calorie the value of calorie
|
||||
* @param trackId the id of track
|
||||
* @param trackId the id of track which is used to start track edit activity
|
||||
* when user want to change the activity type
|
||||
*/
|
||||
private static void setCalorie(Activity activity, int itemId, double calorie) {
|
||||
String calorieString = String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
|
||||
private static void setCalorie(final Activity activity, int itemId, double calorie,
|
||||
final long trackId) {
|
||||
String calorieString;
|
||||
View view = activity.findViewById(itemId);
|
||||
Button button = (Button) activity.findViewById(R.id.stats_calorie_setup);
|
||||
// Current activity type is not supported.
|
||||
if (calorie == TripStatistics.INVALID_CALORIE) {
|
||||
calorieString = activity.getString(R.string.value_unknown);
|
||||
// Return when it is not a valid track, which may be aggregated stats or
|
||||
// marker.
|
||||
if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
||||
return;
|
||||
}
|
||||
button.setVisibility(View.VISIBLE);
|
||||
view.setVisibility(View.GONE);
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = IntentUtils.newIntent(activity, TrackEditActivity.class).putExtra(
|
||||
TrackEditActivity.EXTRA_TRACK_ID, trackId);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
button.setVisibility(View.GONE);
|
||||
view.setVisibility(View.VISIBLE);
|
||||
calorieString = String.format(Locale.getDefault(), CALORIES_FORMAT, calorie);
|
||||
setItem(activity, itemId, R.string.stats_calorie, calorieString,
|
||||
activity.getString(R.string.unit_calorie));
|
||||
}
|
||||
setItem(activity, itemId, R.string.stats_calorie, calorieString,
|
||||
activity.getString(R.string.unit_calorie));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user