androidx.lifecycle.MutableLiveData Java Examples
The following examples show how to use
androidx.lifecycle.MutableLiveData.
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: PostDataSource.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, String query, int postType, SortType sortType, int filter, boolean nsfw) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; this.subredditOrUserName = subredditOrUserName; this.query = query; paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasPostLiveData = new MutableLiveData<>(); this.postType = postType; this.sortType = sortType == null ? new SortType(SortType.Type.RELEVANCE) : sortType; this.filter = filter; this.nsfw = nsfw; postLinkedHashSet = new LinkedHashSet<>(); }
Example #2
Source File: CoordinateHolder.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressLint("CheckResult") CoordinateHolder(CustomFormCoordinateBinding binding, FlowableProcessor<RowAction> processor, boolean isSearchMode, MutableLiveData<String> currentSelection) { super(binding); this.binding = binding; this.currentUid = currentSelection; binding.formCoordinates.setCurrentLocationListener(geometry -> { closeKeyboard(binding.formCoordinates); processor.onNext( RowAction.create(model.uid(), geometry == null ? null : geometry.coordinates(), getAdapterPosition(), model.featureType().name())); clearBackground(isSearchMode); } ); binding.formCoordinates.setMapListener( (CoordinatesView.OnMapPositionClick) binding.formCoordinates.getContext() ); binding.formCoordinates.setActivationListener(() -> setSelectedBackground(isSearchMode)); }
Example #3
Source File: MoodleViewModelTest.java From ETSMobile-Android2 with Apache License 2.0 | 6 votes |
@Test public void getCourses() { // Prepare LiveData containing the courses MutableLiveData<RemoteResource<List<MoodleCourse>>> liveData = new MutableLiveData<>(); when(repository.getCourses()).thenReturn(liveData); // Prepare observer Observer<RemoteResource<List<MoodleCourse>>> observer = mock(Observer.class); viewModel.getCourses().observeForever(observer); verify(observer, never()).onChanged(any(RemoteResource.class)); // Set a value and check if onChanged has been called RemoteResource<List<MoodleCourse>> remoteRes = RemoteResource.loading(null); liveData.setValue(remoteRes); verify(observer).onChanged(remoteRes); reset(observer); // Set another value and check if onChanged has been called again remoteRes = RemoteResource.success(new MoodleCourses()); liveData.setValue(remoteRes); verify(observer).onChanged(remoteRes); }
Example #4
Source File: MoodleViewModelTest.java From ETSMobile-Android2 with Apache License 2.0 | 6 votes |
@Test public void getAssignmentCourses() { // Prepare LiveData MutableLiveData<RemoteResource<List<MoodleAssignmentCourse>>> liveData = new MutableLiveData<>(); when(repository.getAssignmentCourses()).thenReturn(liveData); // Prepare Observer Observer<RemoteResource<List<MoodleAssignmentCourse>>> observer = mock(Observer.class); viewModel.getAssignmentCourses().observeForever(observer); verify(observer, never()).onChanged(any(RemoteResource.class)); // Set a value and check if onChanged was called RemoteResource<List<MoodleAssignmentCourse>> remoteRes = RemoteResource.loading(null); liveData.setValue(remoteRes); verify(observer).onChanged(remoteRes); reset(observer); // Set another value and check if onChanged was called List<MoodleAssignmentCourse> list = new ArrayList<>(); remoteRes = RemoteResource.success(list); liveData.setValue(remoteRes); verify(observer).onChanged(any(RemoteResource.class)); }
Example #5
Source File: ConversationListViewModel.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private ConversationListViewModel(@NonNull Application application, @NonNull SearchRepository searchRepository) { this.application = application; this.megaphone = new MutableLiveData<>(); this.searchResult = new MutableLiveData<>(); this.searchRepository = searchRepository; this.megaphoneRepository = ApplicationDependencies.getMegaphoneRepository(); this.debouncer = new Debouncer(300); this.observer = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { if (!TextUtils.isEmpty(getLastQuery())) { searchRepository.query(getLastQuery(), searchResult::postValue); } } }; application.getContentResolver().registerContentObserver(DatabaseContentProviders.ConversationList.CONTENT_URI, true, observer); }
Example #6
Source File: UserListingViewModel.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
public UserListingViewModel(Retrofit retrofit, String query, SortType sortType) { userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType); initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), UserListingDataSource::getInitialLoadStateLiveData); paginationNetworkState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), UserListingDataSource::getPaginationNetworkStateLiveData); hasUserLiveData = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), UserListingDataSource::hasUserLiveData); sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) .setEnablePlaceholders(false) .setPageSize(25) .build(); users = Transformations.switchMap(sortTypeLiveData, sort -> { userListingDataSourceFactory.changeSortType(sortTypeLiveData.getValue()); return (new LivePagedListBuilder(userListingDataSourceFactory, pagedListConfig)).build(); }); }
Example #7
Source File: MainViewModel.java From ground-android with Apache License 2.0 | 6 votes |
@Inject public MainViewModel( ProjectRepository projectRepository, FeatureRepository featureRepository, Navigator navigator) { windowInsetsLiveData = new MutableLiveData<>(); this.projectRepository = projectRepository; this.featureRepository = featureRepository; this.navigator = navigator; // TODO: Move to background service. disposeOnClear( projectRepository .getActiveProjectOnceAndStream() .switchMapCompletable(this::syncFeatures) .subscribe()); }
Example #8
Source File: GankViewModel.java From CloudReader with Apache License 2.0 | 6 votes |
public MutableLiveData<GankIoDataBean> loadGankData() { final MutableLiveData<GankIoDataBean> data = new MutableLiveData<>(); mModel.setData("GanHuo", mType, mPage, 20); mModel.getGankIoData(new RequestImpl() { @Override public void loadSuccess(Object object) { data.setValue(DataUtil.getTrueData((GankIoDataBean) object)); } @Override public void loadFailed() { if (mPage > 1) { mPage--; } data.setValue(null); } @Override public void addSubscription(Disposable disposable) { addDisposable(disposable); } }); return data; }
Example #9
Source File: ViewOnceMessageViewModel.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private ViewOnceMessageViewModel(@NonNull Application application, long messageId, @NonNull ViewOnceMessageRepository repository) { this.application = application; this.repository = repository; this.message = new MutableLiveData<>(); this.observer = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { repository.getMessage(messageId, optionalMessage -> onMessageRetrieved(optionalMessage)); } }; repository.getMessage(messageId, message -> { if (message.isPresent()) { Uri uri = DatabaseContentProviders.Conversation.getUriForThread(message.get().getThreadId()); application.getContentResolver().registerContentObserver(uri, true, observer); } onMessageRetrieved(message); }); }
Example #10
Source File: CommentDataSource.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, SortType sortType, boolean areSavedComments) { this.retrofit = retrofit; this.locale = locale; this.accessToken = accessToken; this.username = username; this.sortType = sortType; this.areSavedComments = areSavedComments; paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasPostLiveData = new MutableLiveData<>(); }
Example #11
Source File: PagerViewModel.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
protected boolean init(@NonNull ListResource<T> resource) { if (listResource == null) { listResource = new MutableLiveData<>(); listResource.setValue(resource); return true; } return false; }
Example #12
Source File: HomeScreenViewModel.java From ground-android with Apache License 2.0 | 5 votes |
@Inject HomeScreenViewModel( ProjectRepository projectRepository, FeatureRepository featureRepository, AuthenticationManager authManager, Navigator navigator, Schedulers schedulers) { this.projectRepository = projectRepository; this.addFeatureDialogRequests = new MutableLiveData<>(); this.openDrawerRequests = new MutableLiveData<>(); this.bottomSheetState = new MutableLiveData<>(); this.activeProject = LiveDataReactiveStreams.fromPublisher(projectRepository.getActiveProjectOnceAndStream()); this.navigator = navigator; this.addFeatureClicks = PublishSubject.create(); disposeOnClear( addFeatureClicks .switchMapSingle( newFeature -> featureRepository .saveFeature(newFeature, authManager.getCurrentUser()) .toSingleDefault(newFeature) .doOnError(this::onAddFeatureError) .onErrorResumeNext(Single.never())) // Prevent from breaking upstream. .observeOn(schedulers.ui()) .subscribe(this::showBottomSheet)); }
Example #13
Source File: RecognizerRepository.java From blinkreceipt-android with MIT License | 5 votes |
public LiveData<RecognizerResults> recognize(@NonNull ScanOptions options, @NonNull Bitmap bitmap, @NonNull CameraOrientation orientation ) { final MutableLiveData<RecognizerResults> data = new MutableLiveData<>(); //This is not on the main thread! service.recognize( options, bitmap, orientation, data::postValue); return data; }
Example #14
Source File: MovieDataSourceFactory.java From android-popular-movies-app with Apache License 2.0 | 5 votes |
@Override public DataSource<Integer, Movie> create() { mMovieDataSource = new MovieDataSource(mSortBy); // Keep reference to the data source with a MutableLiveData reference mPostLiveData = new MutableLiveData<>(); mPostLiveData.postValue(mMovieDataSource); return mMovieDataSource; }
Example #15
Source File: BindAppPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * Obtains an LiveData to <code>description</code> property * * @return * an LiveData to <code>description</code> property */ public MutableLiveData<String> getDescriptionAsLiveData() { KriptonXLiveDataHandlerImpl<String> liveData=new KriptonXLiveDataHandlerImpl<String>() { @Override protected String compute() { BindAppPreferences.this.refresh(); return BindAppPreferences.this.getDescription(); } }; registryLiveData("description", liveData); return liveData.getLiveData(); }
Example #16
Source File: SearchActivityModel.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
public void init(int defaultPosition, String defaultQuery) { super.init(defaultPosition); if (searchQuery == null) { searchQuery = new MutableLiveData<>(); searchQuery.setValue(defaultQuery); } }
Example #17
Source File: FilesUploadViewModel.java From mcumgr-android with Apache License 2.0 | 5 votes |
@Inject FilesUploadViewModel(final FsManager manager, @Named("busy") final MutableLiveData<Boolean> state) { super(state); mStateLiveData.setValue(State.IDLE); mManager = manager; }
Example #18
Source File: PostDataSourceFactory.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, SortType sortType, String where, int filter, boolean nsfw) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; this.subredditName = subredditName; postDataSourceLiveData = new MutableLiveData<>(); this.postType = postType; this.sortType = sortType; userWhere = where; this.filter = filter; this.nsfw = nsfw; }
Example #19
Source File: SubredditListingDataSource.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
SubredditListingDataSource(Retrofit retrofit, String query, SortType sortType) { this.retrofit = retrofit; this.query = query; this.sortType = sortType; paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasSubredditLiveData = new MutableLiveData<>(); }
Example #20
Source File: MessageDataSource.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
MessageDataSource(Retrofit oauthRetrofit, Locale locale, String accessToken, String where) { this.oauthRetrofit = oauthRetrofit; this.locale = locale; this.accessToken = accessToken; this.where = where; if (where.equals(FetchMessages.WHERE_MESSAGES)) { messageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE; } else { messageType = FetchMessages.MESSAGE_TYPE_NOTIFICATION; } paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); hasPostLiveData = new MutableLiveData<>(); }
Example #21
Source File: PostDataSourceFactory.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, SortType sortType, int filter, boolean nsfw) { this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; this.subredditName = subredditName; postDataSourceLiveData = new MutableLiveData<>(); this.postType = postType; this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; }
Example #22
Source File: UserListViewModel.java From webrtc_android with MIT License | 5 votes |
public LiveData<List<UserBean>> getUserList() { if (mList == null) { mList = new MutableLiveData<>(); loadUsers(); } return mList; }
Example #23
Source File: CollectionActivityRepository.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
public void getACuratedCollection(@NonNull MutableLiveData<Resource<Collection>> current, String id) { assert current.getValue() != null; current.setValue(Resource.loading(current.getValue().data)); service.cancel(); service.requestACuratedCollections(id, new ResourceObserver<>(current)); }
Example #24
Source File: RadioButtonRow.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
public RadioButtonRow(LayoutInflater layoutInflater, @NonNull FlowableProcessor<RowAction> processor, boolean isBgTransparent, String renderType, MutableLiveData<String> currentSelection) { this.inflater = layoutInflater; this.processor = processor; this.isBgTransparent = isBgTransparent; this.renderType = renderType; this.currentSelection = currentSelection; }
Example #25
Source File: LiveDataUtilTest.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Test public void on_update_a() { MutableLiveData<String> liveDataA = new MutableLiveData<>(); MutableLiveData<String> liveDataB = new MutableLiveData<>(); LiveData<String> combined = LiveDataUtil.combineLatest(liveDataA, liveDataB, (a, b) -> a + b); liveDataA.setValue("Hello, "); liveDataB.setValue("World!"); assertEquals("Hello, World!", getValue(combined)); liveDataA.setValue("Welcome, "); assertEquals("Welcome, World!", getValue(combined)); }
Example #26
Source File: LiveDataUtilTest.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Test public void combined_value_after_a_and_b() { MutableLiveData<String> liveDataA = new MutableLiveData<>(); MutableLiveData<String> liveDataB = new MutableLiveData<>(); LiveData<String> combined = LiveDataUtil.combineLatest(liveDataA, liveDataB, (a, b) -> a + b); liveDataA.setValue("Hello, "); liveDataB.setValue("World!"); assertEquals("Hello, World!", getValue(combined)); }
Example #27
Source File: ResultDataSourceFactory.java From ArchPackages with GNU General Public License v3.0 | 5 votes |
public ResultDataSourceFactory(int keywordsParameter, String query, List<String> listRepo, List<String> listArch, String flagged) { this.keywordsParameter = keywordsParameter; this.query = query; this.listRepo = listRepo; this.listArch = listArch; this.flagged = flagged; this.mutableLiveData = new MutableLiveData<>(); }
Example #28
Source File: LiveDataUtilTest.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Test public void no_value_after_just_a() { MutableLiveData<String> liveDataA = new MutableLiveData<>(); MutableLiveData<String> liveDataB = new MutableLiveData<>(); LiveData<String> combined = LiveDataUtil.combineLatest(liveDataA, liveDataB, (a, b) -> a + b); liveDataA.setValue("Hello, "); assertNoValue(combined); }
Example #29
Source File: TypingStatusRepository.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public synchronized void clear() { TypingState empty = new TypingState(Collections.emptyList(), false); for (MutableLiveData<TypingState> notifier : notifiers.values()) { notifier.postValue(empty); } notifiers.clear(); typistMap.clear(); timers.clear(); threadsNotifier.postValue(Collections.emptySet()); }
Example #30
Source File: MapContainerViewModel.java From ground-android with Apache License 2.0 | 5 votes |
@Inject MapContainerViewModel( ProjectRepository projectRepository, FeatureRepository featureRepository, LocationManager locationManager, OfflineAreaRepository offlineAreaRepository) { this.featureRepository = featureRepository; this.locationManager = locationManager; this.locationLockChangeRequests = PublishSubject.create(); this.cameraUpdateSubject = PublishSubject.create(); Flowable<BooleanOrError> locationLockStateFlowable = createLocationLockStateFlowable().share(); this.locationLockState = LiveDataReactiveStreams.fromPublisher( locationLockStateFlowable.startWith(BooleanOrError.falseValue())); this.cameraUpdateRequests = LiveDataReactiveStreams.fromPublisher( createCameraUpdateFlowable(locationLockStateFlowable)); this.cameraPosition = new MutableLiveData<>(); this.activeProject = LiveDataReactiveStreams.fromPublisher(projectRepository.getActiveProjectOnceAndStream()); // TODO: Clear feature markers when project is deactivated. // TODO: Since we depend on project stream from repo anyway, this transformation can be moved // into the repo? this.mapPins = LiveDataReactiveStreams.fromPublisher( projectRepository .getActiveProjectOnceAndStream() .map(Loadable::value) .switchMap(this::getFeaturesStream) .map(MapContainerViewModel::toMapPins)); this.mbtilesFilePaths = LiveDataReactiveStreams.fromPublisher( offlineAreaRepository .getDownloadedTilesOnceAndStream() .map(set -> stream(set).map(Tile::getPath).collect(toImmutableSet()))); }