Java Code Examples for androidx.lifecycle.Transformations#map()
The following examples show how to use
androidx.lifecycle.Transformations#map() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddGroupDetailsViewModel.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private AddGroupDetailsViewModel(@NonNull RecipientId[] recipientIds, @NonNull AddGroupDetailsRepository repository) { this.repository = repository; MutableLiveData<List<GroupMemberEntry.NewGroupCandidate>> initialMembers = new MutableLiveData<>(); LiveData<Boolean> isValidName = Transformations.map(name, name -> !TextUtils.isEmpty(name)); members = LiveDataUtil.combineLatest(initialMembers, deleted, AddGroupDetailsViewModel::filterDeletedMembers); isMms = Transformations.map(members, this::isAnyForcedSms); canSubmitForm = LiveDataUtil.combineLatest(isMms, isValidName, (mms, validName) -> mms || validName); repository.resolveMembers(recipientIds, initialMembers::postValue); }
Example 2
Source File: KeywordQueryViewModel.java From lttrs-android with Apache License 2.0 | 5 votes |
KeywordQueryViewModel(final Application application, ListenableFuture<AccountWithCredentials> account, @NonNull final String keyword) { super(application, account); this.keyword = keyword; //TODO; we probably want to change this to someInThreadHaveKeyword this.emailQueryLiveData = Transformations.map(queryRepository.getTrashAndJunk(), trashAndJunk -> EmailQuery.of( EmailFilterCondition.builder().hasKeyword(keyword).inMailboxOtherThan(trashAndJunk).build(), true )); init(); }
Example 3
Source File: MailboxQueryViewModel.java From lttrs-android with Apache License 2.0 | 5 votes |
MailboxQueryViewModel(final Application application, ListenableFuture<AccountWithCredentials> account, final String mailboxId) { super(application, account); this.mailbox = this.queryRepository.getMailboxOverviewItem(mailboxId); this.emailQueryLiveData = Transformations.map(mailbox, input -> { if (input == null) { return EmailQuery.unfiltered(true); } else { return EmailQuery.of(EmailFilterCondition.builder().inMailbox(input.id).build(), true); } }); init(); }
Example 4
Source File: ReactionsViewModel.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public @NonNull LiveData<List<EmojiCount>> getEmojiCounts() { return Transformations.map(repository.getReactions(), reactionList -> Stream.of(reactionList) .groupBy(Reaction::getEmoji) .sorted(this::compareReactions) .map(entry -> new EmojiCount(entry.getKey(), entry.getValue().size())) .toList()); }
Example 5
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private LiveData<MemberLevel> selfMemberLevel() { return Transformations.map(groupRecord, g -> { if (g.isAdmin(Recipient.self())) { return MemberLevel.ADMIN; } else { return g.isActive() ? MemberLevel.MEMBER : MemberLevel.NOT_A_MEMBER; } }); }
Example 6
Source File: AbstractQueryViewModel.java From lttrs-android with Apache License 2.0 | 5 votes |
AbstractQueryViewModel(@NonNull Application application, ListenableFuture<AccountWithCredentials> account) { super(application); final WorkManager workManager = WorkManager.getInstance(application); this.queryRepository = new QueryRepository(application, account); this.important = this.queryRepository.getImportant(); this.emailModificationWorkInfo = Transformations.map(workManager.getWorkInfosByTagLiveData(AbstractMuaWorker.TAG_EMAIL_MODIFICATION), WorkInfoUtil::allDone); }
Example 7
Source File: SearchQueryViewModel.java From lttrs-android with Apache License 2.0 | 5 votes |
SearchQueryViewModel(final Application application, final ListenableFuture<AccountWithCredentials> account, final String searchTerm) { super(application, account); this.searchTerm = searchTerm; this.inbox = queryRepository.getInbox(); this.searchQueryLiveData = Transformations.map(queryRepository.getTrashAndJunk(), trashAndJunk -> EmailQuery.of( EmailFilterCondition.builder().text(searchTerm).inMailboxOtherThan(trashAndJunk).build(), true )); init(); }
Example 8
Source File: ManageGroupViewModel.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private ManageGroupViewModel(@NonNull Context context, @NonNull ManageGroupRepository manageGroupRepository) { this.context = context; this.manageGroupRepository = manageGroupRepository; manageGroupRepository.getGroupState(this::groupStateLoaded); LiveGroup liveGroup = new LiveGroup(manageGroupRepository.getGroupId()); this.title = Transformations.map(liveGroup.getTitle(), title -> TextUtils.isEmpty(title) ? context.getString(R.string.Recipient_unknown) : title); this.isAdmin = liveGroup.isSelfAdmin(); this.canCollapseMemberList = LiveDataUtil.combineLatest(memberListCollapseState, Transformations.map(liveGroup.getFullMembers(), m -> m.size() > MAX_COLLAPSED_MEMBERS), (state, hasEnoughMembers) -> state != CollapseState.OPEN && hasEnoughMembers); this.members = LiveDataUtil.combineLatest(liveGroup.getFullMembers(), memberListCollapseState, this::filterMemberList); this.pendingMemberCount = liveGroup.getPendingMemberCount(); this.memberCountSummary = liveGroup.getMembershipCountDescription(context.getResources()); this.fullMemberCountSummary = liveGroup.getFullMembershipCountDescription(context.getResources()); this.editMembershipRights = liveGroup.getMembershipAdditionAccessControl(); this.editGroupAttributesRights = liveGroup.getAttributesAccessControl(); this.disappearingMessageTimer = Transformations.map(liveGroup.getExpireMessages(), expiration -> ExpirationUtil.getExpirationDisplayValue(context, expiration)); this.canEditGroupAttributes = liveGroup.selfCanEditGroupAttributes(); this.canAddMembers = liveGroup.selfCanAddMembers(); this.groupRecipient = liveGroup.getGroupRecipient(); this.muteState = Transformations.map(this.groupRecipient, recipient -> new MuteState(recipient.getMuteUntil(), recipient.isMuted())); this.hasCustomNotifications = Transformations.map(this.groupRecipient, recipient -> recipient.getNotificationChannel() != null || !NotificationChannels.supported()); this.canLeaveGroup = liveGroup.isActive(); this.canBlockGroup = Transformations.map(this.groupRecipient, recipient -> !recipient.isBlocked()); }
Example 9
Source File: AddMembersViewModel.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static LiveData<AddMemberDialogMessageState> getStateWithoutGroupTitle(@NonNull AddMemberDialogMessageStatePartial partialState) { if (partialState.recipientId != null) { return Transformations.map(Recipient.live(partialState.recipientId).getLiveData(), r -> new AddMemberDialogMessageState(r, "")); } else { return new DefaultValueLiveData<>(new AddMemberDialogMessageState(partialState.memberCount, "")); } }
Example 10
Source File: CustomNotificationsViewModel.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private CustomNotificationsViewModel(@NonNull GroupId groupId, @NonNull CustomNotificationsRepository repository) { this.liveGroup = new LiveGroup(groupId); this.repository = repository; this.hasCustomNotifications = Transformations.map(liveGroup.getGroupRecipient(), recipient -> recipient.getNotificationChannel() != null || !NotificationChannels.supported()); this.isVibrateEnabled = Transformations.map(liveGroup.getGroupRecipient(), Recipient::getMessageVibrate); this.notificationSound = Transformations.map(liveGroup.getGroupRecipient(), Recipient::getMessageRingtone); repository.onLoad(() -> isInitialLoadComplete.postValue(true)); }
Example 11
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<Boolean> isActive() { return Transformations.map(groupRecord, GroupDatabase.GroupRecord::isActive); }
Example 12
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<Integer> getPendingMemberCount() { return Transformations.map(groupRecord, g -> g.isV2Group() ? g.requireV2GroupProperties().getDecryptedGroup().getPendingMembersCount() : 0); }
Example 13
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<GroupAccessControl> getMembershipAdditionAccessControl() { return Transformations.map(groupRecord, GroupDatabase.GroupRecord::getMembershipAdditionAccessControl); }
Example 14
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<Boolean> isSelfAdmin() { return Transformations.map(groupRecord, g -> g.isAdmin(Recipient.self())); }
Example 15
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<Integer> getExpireMessages() { return Transformations.map(recipient, Recipient::getExpireMessages); }
Example 16
Source File: LiveGroup.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/** * A string representing the count of full members. */ public LiveData<String> getFullMembershipCountDescription(@NonNull Resources resources) { return Transformations.map(getFullMembers(), fullMembers -> getMembershipDescription(resources, 0, fullMembers.size())); }
Example 17
Source File: WebRtcCallViewModel.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public LiveData<Long> getCallTime() { return Transformations.map(ellapsed, timeInCall -> callConnectedTime == -1 ? -1 : timeInCall); }
Example 18
Source File: QueryRepository.java From lttrs-android with Apache License 2.0 | 4 votes |
public LiveData<Boolean> isRunningQueryFor(final EmailQuery query) { return Transformations.map(runningQueriesLiveData, queryStrings -> queryStrings.contains(query.toQueryString())); }
Example 19
Source File: QueryRepository.java From lttrs-android with Apache License 2.0 | 4 votes |
public LiveData<Boolean> isRunningPagingRequestFor(final EmailQuery query) { return Transformations.map(runningPagingRequestsLiveData, queryStrings -> queryStrings.contains(query.toQueryString())); }
Example 20
Source File: TransactionDetailViewModel.java From Gander with Apache License 2.0 | 4 votes |
LiveData<HttpTransactionUIHelper> getTransactionWithId(long id) { return Transformations.map(mTransactionDao.getTransactionsWithId(id), HTTP_TRANSACTION_UI_HELPER_FUNCTION); }