Code cleanup, fixes to displaying user name in comments

pull/14/head
Sam Bosley 12 years ago
parent 8125d79f71
commit e9f8d1f4f8

@ -8,6 +8,8 @@ package com.todoroo.astrid.actfm.sync;
import org.json.JSONException;
import org.json.JSONObject;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.billing.BillingConstants;
@ -100,23 +102,6 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
StatisticsService.reportEvent(StatisticsConstants.ACTFM_SYNC_ERROR, "type", type); //$NON-NLS-1$
}
// /**
// * Return JSON object user, either yourself or the user of the model
// * @param update
// * @return
// */
// public static JSONObject userFromModel(RemoteModel model) {
// if (Task.USER_ID_SELF.equals(model.getValue(RemoteModel.USER_ID_PROPERTY))) {
// return thisUser();
// } else {
// try {
// return new JSONObject(model.getValue(RemoteModel.USER_JSON_PROPERTY));
// } catch (JSONException e) {
// return new JSONObject();
// }
// }
// }
public synchronized static JSONObject thisUser() {
if(user == null) {
user = new JSONObject();
@ -164,4 +149,25 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
return Preferences.getStringValue(PREF_NAME);
}
@SuppressWarnings("nls")
public static String thisUserName() {
JSONObject thisUser = thisUser();
String name = thisUser.optString("name");
if (!(TextUtils.isEmpty(name) || "null".equals(name)))
return name;
String firstName = thisUser.optString("first_name");
boolean firstNameEmpty = TextUtils.isEmpty(firstName) || "null".equals(firstName);
String lastName = thisUser.optString("last_name");
boolean lastNameEmpty = TextUtils.isEmpty(lastName) || "null".equals(lastName);
if (firstNameEmpty && lastNameEmpty)
return thisUser.optString("email");
StringBuilder nameBuilder = new StringBuilder();
if (!firstNameEmpty)
nameBuilder.append(firstName).append(" ");
if (!lastNameEmpty)
nameBuilder.append(lastName);
return nameBuilder.toString().trim();
}
}

@ -15,6 +15,7 @@
<string name="update_string_default_comment">%1$s commented: %3$s</string>
<string name="update_string_task_comment">%1$s on $link_task: %3$s</string>
<string name="update_string_tag_comment">%1$s on %2$s: %3$s</string>
<string name="update_string_user_self">You</string>
<!-- <string name="update_string_friends">%1$s is now friends with %2$s</string>

@ -38,6 +38,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.helper.AsyncImageView;
@ -227,7 +228,14 @@ public class UpdateAdapter extends CursorAdapter {
}
public static Spanned getUpdateComment(final AstridActivity context, UserActivity activity, User user, String linkColor, String fromView) {
String userDisplay = user.getDisplayName();
String userDisplay;
if (activity.getValue(UserActivity.USER_UUID).equals(Task.USER_ID_SELF)) {
userDisplay = context.getString(R.string.update_string_user_self);
} else if (user == null) {
userDisplay = context.getString(R.string.ENA_no_user);
} else {
userDisplay = user.getDisplayName();
}
if (TextUtils.isEmpty(userDisplay))
userDisplay = context.getString(R.string.ENA_no_user);
String targetName = activity.getValue(UserActivity.TARGET_NAME);

Loading…
Cancel
Save