Add activity icon next to calorie in stats page

This commit is contained in:
Jimmy Shih
2013-11-12 15:43:22 -08:00
parent ea626847d6
commit e3d7856e1c
16 changed files with 259 additions and 110 deletions
@@ -0,0 +1,76 @@
/*
* Copyright 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.maps.mytracks.R;
import android.content.Context;
/**
* Utilities for updating track.
*
* @author Jimmy Shih
*/
public class TrackUtils {
private TrackUtils() {}
public static void updateTrack(Context context, Track track, String name, String category,
String description, MyTracksProviderUtils myTracksProviderUtils,
TrackRecordingServiceConnection trackRecordingServiceConnection) {
if (name != null) {
track.setName(name);
}
boolean newCategory = false;
boolean isRecording = false;
if (category != null) {
newCategory = !category.equals(track.getCategory());
track.setCategory(category);
track.setIcon(TrackIconUtils.getIconValue(context, category));
if (newCategory) {
isRecording = track.getId()
== PreferencesUtils.getLong(context, R.string.recording_track_id_key);
if (!isRecording) {
// Update calorie
double calorie = CalorieUtils.getTrackCalorie(context, track, -1L);
track.getTripStatistics().setCalorie(calorie);
}
}
}
if (description != null) {
track.setDescription(description);
}
track.setModifiedTime(System.currentTimeMillis());
myTracksProviderUtils.updateTrack(track);
if (newCategory && isRecording) {
// Update calorie through track recording service
TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection);
}
boolean driveSync = PreferencesUtils.getBoolean(
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
if (driveSync) {
PreferencesUtils.addToList(context, R.string.drive_edited_list_key,
PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId()));
}
}
}