use of email.schaal.ocreader.database.model.User in project ocreader by schaal.
the class UserTypeAdapter method fromJson.
@Override
public User fromJson(@NonNull JsonReader in) throws IOException {
if (in.peek() == JsonReader.Token.NULL) {
in.nextNull();
return null;
}
User user = new User();
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
switch(name) {
case "userId":
user.setUserId(in.nextString());
break;
case "displayName":
user.setDisplayName(in.nextString());
break;
case "lastLoginTimestamp":
user.setLastLogin(new Date(in.nextLong() * 1000));
break;
case "avatar":
if (in.peek() == JsonReader.Token.NULL)
in.skipValue();
else
readAvatar(in, user, name);
break;
default:
Log.w(TAG, "Unknown value in user json: " + name);
in.skipValue();
break;
}
}
in.endObject();
return user;
}
use of email.schaal.ocreader.database.model.User in project ocreader by schaal.
the class ListActivity method updateUserProfile.
private void updateUserProfile() {
final String username = Preferences.USERNAME.getString(PreferenceManager.getDefaultSharedPreferences(this));
if (username != null) {
final User user = getRealm().where(User.class).equalTo(User.USER_ID, username).findFirst();
if (user != null) {
profileDrawerItem.withName(user.getDisplayName());
final String encodedImage = user.getAvatar();
if (encodedImage != null) {
Bitmap avatarBitmap = BitmapFactory.decodeStream(new Base64InputStream(new ByteArrayInputStream(encodedImage.getBytes()), Base64.DEFAULT));
profileDrawerItem.withIcon(avatarBitmap);
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
if (accountHeader != null)
accountHeader.updateProfile(profileDrawerItem);
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
} else {
profileDrawerItem.withIcon(R.mipmap.ic_launcher);
}
}
Aggregations