Search in sources :

Example 1 with UserDao

use of nodomain.freeyourgadget.gadgetbridge.entities.UserDao in project Gadgetbridge by Freeyourgadget.

the class DBHelper method getUser.

/**
     * Looks up the user entity in the database. If a user exists already, it will
     * be updated with the current preferences values. If no user exists yet, it will
     * be created in the database.
     *
     * Note: so far there is only ever a single user; there is no multi-user support yet
     * @param session
     * @return the User entity
     */
@NonNull
public static User getUser(DaoSession session) {
    ActivityUser prefsUser = new ActivityUser();
    UserDao userDao = session.getUserDao();
    User user;
    List<User> users = userDao.loadAll();
    if (users.isEmpty()) {
        user = createUser(prefsUser, session);
    } else {
        // TODO: multiple users support?
        user = users.get(0);
        ensureUserUpToDate(user, prefsUser, session);
    }
    ensureUserAttributes(user, prefsUser, session);
    return user;
}
Also used : User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) UserDao(nodomain.freeyourgadget.gadgetbridge.entities.UserDao) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 UserDao (nodomain.freeyourgadget.gadgetbridge.entities.UserDao)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1