Exemplo n.º 1
0
 public static void setCurrentUser(UserWrapper user) {
   mCurrentUser = user;
   if (mContext == null) {
     throw new IllegalStateException("context not initialized yet");
   }
   try {
     SharedPreferences.Editor editor = mSharedPref.edit();
     editor.putString(KEY_USER, JsonUtil.getObjectMapper().writeValueAsString(user)).apply();
   } catch (JsonProcessingException e) {
     Log.e(TAG, "failed to serialize user", e);
   }
 }
Exemplo n.º 2
0
 public static void init() {
   try {
     String currentUserJson = mSharedPref.getString(KEY_USER, null);
     if (currentUserJson != null) {
       mCurrentUser = JsonUtil.getObjectMapper().readValue(currentUserJson, UserWrapper.class);
       mLoginState = LOGGED_IN;
     } else {
       mCurrentUser = null;
       mLoginState = NOT_LOGGED_IN;
     }
   } catch (Exception e) {
     Log.e(TAG, "failed to deserialize user", e);
   }
 }
Exemplo n.º 3
0
 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {
   if (dataSnapshot.getValue() != null) {
     try {
       HashMap<String, Map<String, String>> map = dataSnapshot.getValue(HashMap.class);
       mFriends = new FriendWrapper[map.size()];
       int i = 0;
       for (Map.Entry<String, Map<String, String>> entry : map.entrySet()) {
         FriendWrapper friendWrapper = new FriendWrapper();
         friendWrapper.setId(entry.getKey());
         friendWrapper.setData(
             JsonUtil.getObjectMapper().convertValue(entry.getValue(), FriendData.class));
         mFriends[i] = friendWrapper;
         i++;
       }
       checkResult(true, mResultListener);
     } catch (Exception e) {
       checkResult(false, mResultListener);
     }
   } else {
     checkResult(true, mResultListener);
   }
 }