Several more history displays

pull/14/head
Sam Bosley 12 years ago
parent 54ad0d8512
commit 52d0ed4302

@ -924,6 +924,28 @@ public class AndroidUtilities {
}
}
/**
* Tries to parse an int from a string, returning the default value on failure
*/
public static int tryParseInt(String str, int defaultValue) {
try {
return Integer.parseInt(str);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Tries to parse an int from a string, returning the default value on failure
*/
public static long tryParseLong(String str, long defaultValue) {
try {
return Long.parseLong(str);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Returns the final word characters after the last '.'
* @param file

@ -97,11 +97,11 @@ public class DateUtilities {
* @return time, with hours and minutes
*/
@SuppressWarnings("nls")
public static String getTimeString(Context context, Date date) {
public static String getTimeString(Context context, Date date, boolean excludeZeroMinutes) {
String value;
if (is24HourFormat(context)) {
value = "H:mm";
} else if (date.getMinutes() == 0){
} else if (date.getMinutes() == 0 && excludeZeroMinutes){
value = "h a";
}
else {
@ -110,6 +110,10 @@ public class DateUtilities {
return new SimpleDateFormat(value).format(date);
}
public static String getTimeString(Context context, Date date) {
return getTimeString(context, date, true);
}
/* Returns true if search string is in sortedValues */
private static boolean arrayBinaryContains(String search, String... sortedValues) {
@ -122,7 +126,7 @@ public class DateUtilities {
* @return date, with month, day, and year
*/
@SuppressWarnings("nls")
public static String getDateString(Context context, Date date) {
public static String getDateString(Context context, Date date, boolean includeYear) {
String month = DateUtils.getMonthString(date.getMonth() +
Calendar.JANUARY, DateUtils.LENGTH_MEDIUM);
String value;
@ -131,9 +135,11 @@ public class DateUtilities {
Locale locale = Locale.getDefault();
if (arrayBinaryContains(locale.getLanguage(), "ja", "ko", "zh")
|| arrayBinaryContains(locale.getCountry(), "BZ", "CA", "KE", "MN" ,"US"))
value = "'#' d'$', yyyy";
value = "'#' d'$'";
else
value = "d'$' '#', yyyy";
value = "d'$' '#'";
if (includeYear)
value += ", yyyy";
if (arrayBinaryContains(locale.getLanguage(), "ja", "zh")){
standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("$", "\u65E5"); //$NON-NLS-1$
}else if ("ko".equals(Locale.getDefault().getLanguage())){
@ -143,6 +149,10 @@ public class DateUtilities {
}
return standardDate;}
public static String getDateString(Context context, Date date) {
return getDateString(context, date, true);
}
/**
* @param context android context
* @param date date to format
@ -263,7 +273,7 @@ public class DateUtilities {
}
public static boolean isoStringHasTime(String iso8601String) {
return iso8601String.length() > 12;
return iso8601String.length() > 10;
}
public static long parseIso8601(String iso8601String) throws ParseException {

@ -17,6 +17,10 @@
<string name="update_string_tag_comment">%1$s on %2$s: %3$s</string>
<string name="update_string_user_self">You</string>
<string name="history_yourself">yourself</string>
<string name="history_you">you</string>
<string name="history_a_deleted_user">(a deleted user)</string>
<string name="history_this_list">this list</string>
<string name="history_this_task">this task</string>
<string name="history_deleted">deleted %s</string>
@ -30,6 +34,30 @@
<string name="history_name_set">set name to %2$s</string>
<string name="history_description_changed">changed description from %1$s to %2$s</string>
<string name="history_description_set">set description to %2$s</string>
<string name="history_made_public">made %s public</string>
<string name="history_made_private">made %s private</string>
<string name="history_silenced">silenced %s</string>
<string name="history_unsilenced">unsilenced %s</string>
<string name="history_favorited">favorited %s</string>
<string name="history_unfavorited">unfavorited %s</string>
<string name="history_changed_list_picture">change this list\'s picture</string>
<string name="history_added_description_characters">added %1$d characters to %2$s description</string>
<string name="history_removed_description">removed %s description</string>
<string name="history_removed_description_characters">removed %1$d characters from %2$s description</string>
<string name="history_updated_description">updated %s description</string>
<string name="history_changed_list_owner">changed list owner to %s</string>
<string name="history_created_this_list">created this list</string>
<string name="history_unassigned">unassigned %s</string>
<string name="history_claimed">claimed %s</string>
<string name="history_assigned_to">assigned %1$s to %2$s</string>
<string name="history_created_for">created %1$s for %2$s</string>
<string name="history_created">created %s</string>
<string name="history_changed_due_date">changed %1$s due date from %2$s to %3$s</string>
<string name="history_set_due_date">set %1$s due date to %2$s</string>
<string name="history_removed_due_date">removed %s due date</string>
<string name="history_completed_repeating_task">completed %1$s (now due on %2$s)</string>
<string name="history_default">changed %1$s to %2$s</string>
<!-- <string name="update_string_friends">%1$s is now friends with %2$s</string>
<string name="update_string_request_friendship">%1$s wants to be friends with you</string>

@ -6,11 +6,14 @@
package com.todoroo.astrid.adapter;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.content.Context;
@ -41,7 +44,9 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.data.History;
@ -463,34 +468,54 @@ public class UpdateAdapter extends CursorAdapter {
} else if (History.COL_MEMBER_ADDED.equals(column) || History.COL_MEMBER_REMOVED.equals(column)) {
//
} else if (History.COL_COMPLETED_AT.equals(column)) {
long value = Long.parseLong(newValue);
long value = AndroidUtilities.tryParseLong(newValue, 0);
if (value > 0) {
result = context.getString(R.string.history_completed, item);
} else {
result = context.getString(R.string.history_uncompleted, item);
}
} else if (History.COL_DELETED_AT.equals(column)) {
long value = Long.parseLong(newValue);
long value = AndroidUtilities.tryParseLong(newValue, 0);
if (value > 0) {
result = context.getString(R.string.history_deleted, item);
} else {
result = context.getString(R.string.history_undeleted, item);
}
} else if (History.COL_IMPORTANCE.equals(column)) {
int oldPriority = Integer.parseInt(oldValue);
int newPriority = Integer.parseInt(newValue);
int oldPriority = AndroidUtilities.tryParseInt(oldValue, 0);
int newPriority = AndroidUtilities.tryParseInt(newValue, 0);
result = context.getString(R.string.history_importance_changed, itemPosessive, priorityString(oldPriority), priorityString(newPriority));
} else if (History.COL_NOTES_LENGTH.equals(column)) {
//
int oldLength = AndroidUtilities.tryParseInt(oldValue, 0);
int newLength = AndroidUtilities.tryParseInt(newValue, 0);
if (oldLength > 0 && newLength > oldLength)
result = context.getString(R.string.history_added_description_characters, (newLength - oldLength), itemPosessive);
else if (newLength == 0)
result = context.getString(R.string.history_removed_description, itemPosessive);
else if (oldLength > 0 && newLength < oldLength)
result = context.getString(R.string.history_removed_description_characters, (oldLength - newLength), itemPosessive);
else if (oldLength > 0 && oldLength == newLength)
result = context.getString(R.string.history_updated_description, itemPosessive);
} else if (History.COL_PUBLIC.equals(column)) {
//
int value = AndroidUtilities.tryParseInt(newValue, 0);
if (value > 0)
result = context.getString(R.string.history_made_public, item);
else
result = context.getString(R.string.history_made_private, item);
} else if (History.COL_DUE.equals(column)) {
//
if (!TextUtils.isEmpty(oldValue) && !TextUtils.isEmpty(newValue)
&& !"null".equals(oldValue) && !"null".equals(newValue))
result = context.getString(R.string.history_changed_due_date, itemPosessive, dateString(context, oldValue, newValue), dateString(context, newValue, oldValue));
else if (!TextUtils.isEmpty(newValue) && !"null".equals(newValue))
result = context.getString(R.string.history_set_due_date, itemPosessive, dateString(context, newValue, DateUtilities.timeToIso8601(DateUtilities.now(), true)));
else
result = context.getString(R.string.history_removed_due_date, itemPosessive);
} else if (History.COL_REPEAT.equals(column)) {
//
} else if (History.COL_TASK_REPEATED.equals(column)) {
//
result = context.getString(R.string.history_completed_repeating_task, item, dateString(context, newValue, oldValue));
} else if (History.COL_TITLE.equals(column)) {
if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
result = context.getString(R.string.history_title_changed, itemPosessive, oldValue, newValue);
@ -507,15 +532,39 @@ public class UpdateAdapter extends CursorAdapter {
else
result = context.getString(R.string.history_description_set, newValue);
} else if (History.COL_PICTURE_ID.equals(column) || History.COL_DEFAULT_LIST_IMAGE_ID.equals(column)) {
//
result = context.getString(R.string.history_changed_list_picture);
} else if (History.COL_IS_SILENT.equals(column)) {
//
int value = AndroidUtilities.tryParseInt(newValue, 0);
if (value > 0)
result = context.getString(R.string.history_silenced, item);
else
result = context.getString(R.string.history_unsilenced, item);
} else if (History.COL_IS_FAVORITE.equals(column)) {
//
int value = AndroidUtilities.tryParseInt(newValue, 0);
if (value > 0)
result = context.getString(R.string.history_favorited, item);
else
result = context.getString(R.string.history_unfavorited, item);
} else if (History.COL_USER_ID.equals(column)) {
//
String userId = history.getValue(History.USER_UUID);
JSONObject userValue = new JSONObject(newValue);
if (FROM_TAG_VIEW.equals(fromView) && !hasTask) {
if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
result = context.getString(R.string.history_changed_list_owner, userDisplay(context, userId, userValue));
else
result = context.getString(R.string.history_created_this_list);
} else if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue) && Task.USER_ID_UNASSIGNED.equals(userValue))
result = context.getString(R.string.history_unassigned, item);
else if (Task.USER_ID_UNASSIGNED.equals(oldValue) && userValue.optString("id").equals(ActFmPreferenceService.userId()))
result = context.getString(R.string.history_claimed, item);
else if (!TextUtils.isEmpty(oldValue) && !"null".equals(oldValue))
result = context.getString(R.string.history_assigned_to, item, userDisplay(context, userId, userValue));
else if (!userValue.optString("id").equals(ActFmPreferenceService.userId()) && !Task.USER_ID_UNASSIGNED.equals(userValue.optString("id")))
result = context.getString(R.string.history_created_for, item, userDisplay(context, userId, userValue));
else
result = context.getString(R.string.history_created, item);
} else {
// default display
result = context.getString(R.string.history_default, column, newValue);
}
} catch (Exception e) {
e.printStackTrace();
@ -524,6 +573,42 @@ public class UpdateAdapter extends CursorAdapter {
return null;
}
private static String dateString(Context context, String value, String other) {
boolean includeYear = (!TextUtils.isEmpty(other) && !value.substring(0, 4).equals(other.substring(0, 4)));
boolean hasTime = DateUtilities.isoStringHasTime(value);
long time = 0;
try {
time = DateUtilities.parseIso8601(value);
Date date = new Date(time);
String result = DateUtilities.getDateString(context, date, includeYear);
if (hasTime)
result += ", " + DateUtilities.getTimeString(context, date, false); //$NON-NLS-1$
return result;
} catch (ParseException e) {
return value;
}
}
@SuppressWarnings("nls")
private static String userDisplay(Context context, String historyUserId, JSONObject userJson) {
try {
String id = userJson.getString("id");
String name = userJson.getString("name");
if (historyUserId.equals(id) && ActFmPreferenceService.userId().equals(id))
return context.getString(R.string.history_yourself);
else if (ActFmPreferenceService.userId().equals(id))
return context.getString(R.string.history_you);
else if (RemoteModel.isValidUuid(id))
return name;
else return context.getString(R.string.history_a_deleted_user);
} catch (JSONException e) {
return context.getString(R.string.ENA_no_user).toLowerCase();
}
}
@SuppressWarnings("nls")
private static final String[] PRIORITY_STRINGS = { "!!!", "!!", "!", "o" };
private static String priorityString(int priority) {

Loading…
Cancel
Save