Fixed bug where activity would sometimes say 'Someone' for a while after first login

pull/14/head
Sam Bosley 12 years ago
parent c7383030d1
commit c6e15bc251

@ -538,6 +538,8 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
Preferences.setString(ActFmPreferenceService.PREF_PICTURE, Preferences.setString(ActFmPreferenceService.PREF_PICTURE,
result.optString("picture")); result.optString("picture"));
actFmPreferenceService.reloadThisUser();
setResult(RESULT_OK); setResult(RESULT_OK);
finish(); finish();

@ -94,9 +94,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
* @return * @return
*/ */
public static JSONObject userFromModel(RemoteModel model) { public static JSONObject userFromModel(RemoteModel model) {
if(model.getValue(RemoteModel.USER_ID_PROPERTY) == 0) if(model.getValue(RemoteModel.USER_ID_PROPERTY) == 0) {
return thisUser(); return thisUser();
else { }else {
try { try {
return new JSONObject(model.getValue(RemoteModel.USER_JSON_PROPERTY)); return new JSONObject(model.getValue(RemoteModel.USER_JSON_PROPERTY));
} catch (JSONException e) { } catch (JSONException e) {
@ -118,25 +118,36 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
return String.format("%s: %s", updateUser.optString("name"), description); return String.format("%s: %s", updateUser.optString("name"), description);
} }
@SuppressWarnings("nls")
public synchronized static JSONObject thisUser() { public synchronized static JSONObject thisUser() {
if(user == null) { if(user == null) {
user = new JSONObject(); user = new JSONObject();
try { populateUser();
user.put("name", Preferences.getStringValue(PREF_NAME));
user.put("first_name", Preferences.getStringValue(PREF_FIRST_NAME));
user.put("last_name", Preferences.getStringValue(PREF_LAST_NAME));
user.put("premium", Preferences.getBoolean(PREF_PREMIUM, false));
user.put("email", Preferences.getStringValue(PREF_EMAIL));
user.put("picture", Preferences.getStringValue(PREF_PICTURE));
user.put("id", Preferences.getLong(PREF_USER_ID, 0));
} catch (JSONException e) {
throw new RuntimeException(e);
}
} }
return user; return user;
} }
public synchronized static void reloadThisUser() {
if (user == null)
return;
populateUser();
}
@SuppressWarnings("nls")
private static void populateUser() {
try {
user.put("name", Preferences.getStringValue(PREF_NAME));
user.put("first_name", Preferences.getStringValue(PREF_FIRST_NAME));
user.put("last_name", Preferences.getStringValue(PREF_LAST_NAME));
user.put("premium", Preferences.getBoolean(PREF_PREMIUM, false));
user.put("email", Preferences.getStringValue(PREF_EMAIL));
user.put("picture", Preferences.getStringValue(PREF_PICTURE));
user.put("id", Preferences.getLong(PREF_USER_ID, 0));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
public static boolean isPremiumUser() { public static boolean isPremiumUser() {
return Preferences.getBoolean(PREF_PREMIUM, false); return Preferences.getBoolean(PREF_PREMIUM, false);
} }

@ -181,6 +181,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
Preferences.setString(ActFmPreferenceService.PREF_EMAIL, status.optString("email")); Preferences.setString(ActFmPreferenceService.PREF_EMAIL, status.optString("email"));
if (status.has("picture")) if (status.has("picture"))
Preferences.setString(ActFmPreferenceService.PREF_PICTURE, status.optString("picture")); Preferences.setString(ActFmPreferenceService.PREF_PICTURE, status.optString("picture"));
actFmPreferenceService.reloadThisUser();
} catch (IOException e) { } catch (IOException e) {
handler.handleException("actfm-sync", e, e.toString()); //$NON-NLS-1$ handler.handleException("actfm-sync", e, e.toString()); //$NON-NLS-1$
} }

@ -229,9 +229,9 @@ public class UpdateAdapter extends CursorAdapter {
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static Spanned getUpdateComment (final AstridActivity activity, Update update, JSONObject user, String linkColor, String fromView) { public static Spanned getUpdateComment (final AstridActivity activity, Update update, JSONObject user, String linkColor, String fromView) {
if (user == null) { if (user == null)
user = ActFmPreferenceService.userFromModel(update); user = ActFmPreferenceService.userFromModel(update);
}
JSONObject otherUser = null; JSONObject otherUser = null;
try { try {
otherUser = new JSONObject(update.getValue(Update.OTHER_USER)); otherUser = new JSONObject(update.getValue(Update.OTHER_USER));

Loading…
Cancel
Save