/** * INTERNAL API Create User View Model * * @param user Initial User value * @param modules im.actor.android.modules reference */ public UserVM(@NotNull User user, @NotNull ModuleContext modules) { super(user); id = user.getUid(); sex = user.getSex(); isBot = user.isBot(); name = new StringValueModel("user." + id + ".name", user.getName()); localName = new StringValueModel("user." + id + ".local_name", user.getLocalName()); serverName = new StringValueModel("user." + id + ".server_name", user.getServerName()); nick = new StringValueModel("user." + id + ".nick", user.getNick()); about = new StringValueModel("user." + id + ".about", user.getAbout()); avatar = new AvatarValueModel("user." + id + ".avatar", user.getAvatar()); isContact = new BooleanValueModel( "user." + id + ".contact", modules.getContactsModule().isUserContact(id)); isInPhoneBook = new BooleanValueModel( "user." + id + ".in_pb", modules.getContactsModule().isUserInPhoneBook(id)); isBlocked = new BooleanValueModel("user." + id + ".blocked", user.isBlocked()); isVerified = new BooleanValueModel("user." + id + ".is_verified", user.isVerified()); timeZone = new StringValueModel("user." + id + ".time_zone", user.getTimeZone()); presence = new ValueModelUserPresence( "user." + id + ".presence", new UserPresence(UserPresence.State.UNKNOWN)); phones = new ValueModelUserPhone("user." + id + ".phones", buildPhones(user.getRecords())); emails = new ValueModelUserEmail("user." + id + ".emails", buildEmails(user.getRecords())); links = new ValueModelUserLink("user." + id + ".links", buildLinks(user.getRecords())); contacts = new ValueModelContactRecord( "user." + id + ".contacts", new ArrayListContactRecord(user.getRecords())); botCommands = new ValueModelBotCommands( "user." + id + ".bot_commands", new ArrayListBotCommands(user.getCommands())); // Notify about presence change every minute as text representation can change presenceTimer = new CommonTimer( new Runnable() { @Override public void run() { presence.forceNotify(); presenceTimer.schedule(PRESENCE_UPDATE_DELAY); } }); presenceTimer.schedule(PRESENCE_UPDATE_DELAY); }
@Override protected void updateValues(@NotNull User rawObj) { boolean isChanged = name.change(rawObj.getName()); isChanged |= localName.change(rawObj.getLocalName()); isChanged |= serverName.change(rawObj.getServerName()); isChanged |= nick.change(rawObj.getNick()); isChanged |= timeZone.change(rawObj.getTimeZone()); isChanged |= about.change(rawObj.getAbout()); isChanged |= avatar.change(rawObj.getAvatar()); isChanged |= isBlocked.change(rawObj.isBlocked()); isChanged |= isVerified.change(rawObj.isVerified()); isChanged |= botCommands.change(new ArrayListBotCommands(rawObj.getCommands())); // TODO: better changed checking? isChanged |= phones.change(buildPhones(rawObj.getRecords())); isChanged |= emails.change(buildEmails(rawObj.getRecords())); isChanged |= links.change(buildLinks(rawObj.getRecords())); isChanged |= contacts.change(new ArrayListContactRecord(rawObj.getRecords())); if (isChanged) { notifyChange(); } }