Search in sources :

Example 1 with User

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;
}
Also used : User(email.schaal.ocreader.database.model.User) Date(java.util.Date)

Example 2 with 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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) User(email.schaal.ocreader.database.model.User) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(android.util.Base64InputStream)

Aggregations

User (email.schaal.ocreader.database.model.User)2 Bitmap (android.graphics.Bitmap)1 Base64InputStream (android.util.Base64InputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1