private User getUserFromPreferenceFile(Site site) { SharedPreferences preferenceFile = getSharedPreferences(PREFERENCE_FILE, MODE_PRIVATE); String authToken = preferenceFile.getString(site.mName + AUTH_TOKEN_KEY, null); String username = preferenceFile.getString(site.mName + USERNAME_KEY, null); int userid = preferenceFile.getInt(site.mName + USERID_KEY, 0); User user = null; if (username != null && authToken != null) { user = new User(); user.setAuthToken(authToken); user.setUsername(username); user.setUserid(userid); } return user; }
/** Login parsing info */ public static User parseLoginInfo(String json) throws JSONException { JSONObject jUser = new JSONObject(json); User user = new User(); user.setUserid(jUser.getInt("userid")); user.setUsername(jUser.getString("username")); if (!jUser.isNull("image")) user.setAvatar(parseImage(jUser.getJSONObject("image"), null)); user.setAboutRaw(jUser.getString("about_raw")); user.setAboutRendered(jUser.getString("about_rendered")); if (!jUser.isNull("summary")) user.setSummary(jUser.getString("summary")); if (!jUser.isNull("location")) user.setLocation(jUser.getString("location")); if (!jUser.isNull("join_date")) user.setJoinDate(jUser.getInt("join_date")); user.setBadges(parseBadges(jUser.getJSONObject("badge_counts"))); user.setReputation(jUser.getInt("reputation")); user.setCertificationCount(jUser.getInt("certification_count")); user.setAuthToken(jUser.getString("authToken")); return user; }