Use relative time display only on track list

This commit is contained in:
Jimmy Shih
2013-12-04 10:16:57 -08:00
parent 65bfa15553
commit c2e4381a50
4 changed files with 24 additions and 33 deletions
@@ -189,7 +189,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
String photoUrl = cursor.getString(photoUrlIndex); String photoUrl = cursor.getString(photoUrlIndex);
ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId,
R.string.icon_marker, name, null, null, null, 0, time, category, description, R.string.icon_marker, name, null, null, null, 0, time, false, category, description,
photoUrl); photoUrl);
} }
}; };
@@ -242,7 +242,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity implements
ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId, ListItemUtils.setListItem(SearchListActivity.this, view, isRecording, isPaused, iconId,
iconContentDescriptionId, name, sharedOwner, totalTime, totalDistance, markerCount, iconContentDescriptionId, name, sharedOwner, totalTime, totalDistance, markerCount,
startTime, category, description, photoUrl); startTime, false, category, description, photoUrl);
return view; return view;
} }
}; };
@@ -381,7 +381,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused,
iconId, R.string.icon_track, name, sharedOwner, totalTime, totalDistance, markerCount, iconId, R.string.icon_track, name, sharedOwner, totalTime, totalDistance, markerCount,
startTime, category, description, null); startTime, true, category, description, null);
} }
}; };
listView.setAdapter(sectionResourceCursorAdapter); listView.setAdapter(sectionResourceCursorAdapter);
@@ -29,8 +29,6 @@ import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.Calendar;
/** /**
* Utilities to display a list item. * Utilities to display a list item.
* *
@@ -57,6 +55,7 @@ public class ListItemUtils {
* @param totalDistance the total distance value * @param totalDistance the total distance value
* @param markerCount the marker count * @param markerCount the marker count
* @param startTime the start time value * @param startTime the start time value
* @param useRelativeTime true to display relative time if appropriate
* @param category the category value * @param category the category value
* @param description the description value * @param description the description value
* @param photoUrl the photo url * @param photoUrl the photo url
@@ -64,8 +63,8 @@ public class ListItemUtils {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void setListItem(Activity activity, View view, boolean isRecording, public static void setListItem(Activity activity, View view, boolean isRecording,
boolean isPaused, int iconId, int iconContentDescriptionId, String name, String sharedOwner, boolean isPaused, int iconId, int iconContentDescriptionId, String name, String sharedOwner,
String totalTime, String totalDistance, int markerCount, long startTime, String category, String totalTime, String totalDistance, int markerCount, long startTime,
String description, String photoUrl) { boolean useRelativeTime, String category, String description, String photoUrl) {
if (isRecording) { if (isRecording) {
iconId = isPaused ? R.drawable.ic_track_paused : R.drawable.ic_track_recording; iconId = isPaused ? R.drawable.ic_track_paused : R.drawable.ic_track_recording;
@@ -119,7 +118,7 @@ public class ListItemUtils {
} }
// Set date/time // Set date/time
String[] dateTime = getDateTime(isRecording, activity, startTime); String[] dateTime = getDateTime(isRecording, activity, startTime, useRelativeTime);
TextView dateTextView = (TextView) view.findViewById(R.id.list_item_date); TextView dateTextView = (TextView) view.findViewById(R.id.list_item_date);
setTextView(dateTextView, dateTime[0]); setTextView(dateTextView, dateTime[0]);
@@ -192,35 +191,27 @@ public class ListItemUtils {
* @param context the context * @param context the context
* @param time the start time * @param time the start time
*/ */
private static String[] getDateTime(boolean isRecording, Context context, long time) { private static String[] getDateTime(
boolean isRecording, Context context, long time, boolean useRelativeTime) {
if (isRecording || time == 0L) { if (isRecording || time == 0L) {
return new String[] { null, null }; return new String[] { null, null };
} }
if (DateUtils.isToday(time)) { boolean isToday = DateUtils.isToday(time);
return new String[] { DateUtils.getRelativeTimeSpanString( int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL;
time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE).toString(), null };
}
int dateFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL;
if (!isThisYear(time)) {
dateFlags |= DateUtils.FORMAT_NUMERIC_DATE;
}
int timeFlags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME;
return new String[] { DateUtils.formatDateTime(context, time, dateFlags),
DateUtils.formatDateTime(context, time, timeFlags) };
}
/** if (isToday) {
* True if the time is this year. if (useRelativeTime) {
* return new String[] { DateUtils.getRelativeTimeSpanString(
* @param time the time time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
*/ DateUtils.FORMAT_ABBREV_RELATIVE).toString(), null };
private static boolean isThisYear(long time) { } else {
Calendar now = Calendar.getInstance(); return new String[] { DateUtils.formatDateTime(context, time, timeFlags), null };
Calendar calendar = Calendar.getInstance(); }
now.setTimeInMillis(System.currentTimeMillis()); }
calendar.setTimeInMillis(time);
return now.get(Calendar.YEAR) == calendar.get(Calendar.YEAR); return new String[] { DateUtils.formatDateTime(
context, time, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL),
DateUtils.formatDateTime(context, time, timeFlags) };
} }
/** /**