forked from upstream-mirrors/OpenTracks
Add an activity setup button in stat page when the activity type is not support to calculate calorie.
This commit is contained in:
@@ -142,5 +142,12 @@ limitations under the License.
|
||||
<include
|
||||
android:id="@+id/stats_calorie"
|
||||
layout="@layout/stats_small_item" />
|
||||
<!-- Setup activity type-->
|
||||
<Button
|
||||
android:id="@+id/stats_calorie_setup"
|
||||
android:layout_gravity="right"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/stats_calorie_setup" />
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
@@ -2146,11 +2146,11 @@ limitations under the License.
|
||||
Character limit: ~23 (1 line)">
|
||||
Calories
|
||||
</string>
|
||||
<string name="stats_calorie_invalid_type"
|
||||
translation_description="In the 'Stats' page, the calorie value label while pending.
|
||||
<string name="stats_calorie_setup"
|
||||
translation_description="In the 'Stats' page, the button to setup calorie.
|
||||
|
||||
Character limit: ~23 (1 line)">
|
||||
Calories(Invalid type)
|
||||
Setup Activity Type
|
||||
</string>
|
||||
<string name="stats_fastest_pace"
|
||||
translation_description="In the 'Stats' page, the fastest pace.">
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -36,7 +37,8 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
StatsUtils.setTripStatisticsValues(this, getTripStatistics());
|
||||
StatsUtils.setTripStatisticsValues(this, getTripStatistics(),
|
||||
PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
StatsUtils.setLocationValues(this, null, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,8 +181,10 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
public void onClick(View v) {
|
||||
track.setName(name.getText().toString());
|
||||
String category = activityType.getText().toString();
|
||||
if(!category.equals(track.getCategory())) {
|
||||
double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track, category);
|
||||
if (!category.equals(track.getCategory())) {
|
||||
// TODO Is there no race condition when setCalorie is called.
|
||||
double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track,
|
||||
category);
|
||||
track.getTripStatistics().setCalorie(calorie);
|
||||
}
|
||||
track.setCategory(category);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PhotoUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -192,7 +193,8 @@ public class MarkerDetailFragment extends Fragment {
|
||||
TextView name = (TextView) getView().findViewById(R.id.marker_detail_statistics_name);
|
||||
name.setText(getString(R.string.generic_name_line, waypoint.getName()));
|
||||
|
||||
StatsUtils.setTripStatisticsValues(getActivity(), waypoint.getTripStatistics());
|
||||
StatsUtils.setTripStatisticsValues(getActivity(), waypoint.getTripStatistics(),
|
||||
PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
StatsUtils.setLocationValues(getActivity(), waypoint.getLocation(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,11 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
* Updates the UI.
|
||||
*/
|
||||
private void updateUi(FragmentActivity activity) {
|
||||
StatsUtils.setTripStatisticsValues(activity, lastTripStatistics);
|
||||
StatsUtils.setTripStatisticsValues(
|
||||
activity,
|
||||
lastTripStatistics,
|
||||
trackDataHub == null ? PreferencesUtils.RECORDING_TRACK_ID_DEFAULT : trackDataHub
|
||||
.getSelectedTrackId());
|
||||
StatsUtils.setLocationValues(activity, lastLocation, isSelectedTrackRecording());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class TripStatistics implements Parcelable {
|
||||
* This value means the calorie value is invalid due to activity type is not
|
||||
* supported.
|
||||
*/
|
||||
public static final double INVALID_CALORIE = -1;
|
||||
public static final double INVALID_CALORIE = -1.0;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -129,7 +129,9 @@ public class TripStatistics implements Parcelable {
|
||||
gradeExtremities.update(other.gradeExtremities.getMin());
|
||||
gradeExtremities.update(other.gradeExtremities.getMax());
|
||||
}
|
||||
calorie += other.calorie;
|
||||
if (other.calorie != INVALID_CALORIE) {
|
||||
calorie += other.calorie;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,9 +587,9 @@ public class TripStatistics implements Parcelable {
|
||||
*/
|
||||
public void addCalorie(double calorieAdded) {
|
||||
if (calorieAdded != INVALID_CALORIE) {
|
||||
this.calorie += calorieAdded;
|
||||
calorie = calorie == INVALID_CALORIE ? calorieAdded : calorie + calorieAdded;
|
||||
} else {
|
||||
this.calorie = INVALID_CALORIE;
|
||||
calorie = INVALID_CALORIE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user