androidx.lifecycle.LiveData Java Examples

The following examples show how to use androidx.lifecycle.LiveData. 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: LiveDataUtilTest.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void on_default_values() {
  MutableLiveData<Integer> liveDataA = new DefaultValueLiveData<>(10);
  MutableLiveData<Integer> liveDataB = new DefaultValueLiveData<>(30);

  LiveData<Integer> combined = LiveDataUtil.combineLatest(liveDataA, liveDataB, (a, b) -> a * b);

  assertEquals(Integer.valueOf(300), getValue(combined));
}
 
Example #2
Source File: DisplayManager.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
public DisplayManager(@NonNull Activity activity, @Nullable LiveData<RendererItem> selectedRender, boolean textureView, boolean cloneMode, boolean benchmark) {
    mActivity = activity;
    mSelectedRenderer = selectedRender;
    mMediaRouter = (MediaRouter) activity.getApplicationContext().getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mTextureView = textureView;
    mPresentation = !cloneMode && !benchmark && selectedRender != null && selectedRender.getValue() == null ? createPresentation() : null;
    if (mSelectedRenderer != null) {
        mRendererItem = mSelectedRenderer.getValue();
        mSelectedRenderer.observeForever(mRendererObs);
    }
    mDisplayType = benchmark ? DisplayType.PRIMARY : getCurrentType();
}
 
Example #3
Source File: SearchRepository.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
LiveData searchTrackedEntities(@Nullable Program selectedProgram,
                                                          @NonNull String trackedEntityType,
                                                          @NonNull List<String> orgUnits,
                                                          @Nonnull List<State> states,
                                                          @NonNull List<EventStatus> statuses,
                                                          @Nullable HashMap<String, String> queryData,
                                                          boolean assignedToMe,
                                                          boolean isOnline);
 
Example #4
Source File: VideosRepository.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
/**
 * View Model talks to repository through this method to fetch the live data.
 *
 * @param category category
 * @return The list of categories which is wrapped in a live data.
 */
public LiveData<List<VideoEntity>> getVideosInSameCategoryLiveData(String category) {

    // always try to retrive from local cache firstly
    if (mVideoEntitiesCache.containsKey(category)) {
        return mVideoEntitiesCache.get(category);
    }
    LiveData<List<VideoEntity>> videoEntities = mVideoDao.loadVideoInSameCateogry(category);
    mVideoEntitiesCache.put(category, videoEntities);
    return videoEntities;
}
 
Example #5
Source File: PFPinCodeViewModel.java    From PFLockScreen-Android with Apache License 2.0 5 votes vote down vote up
public LiveData<PFResult<Boolean>> delete() {
    final PFLiveData<PFResult<Boolean>> liveData = new PFLiveData<>();
    PFSecurityManager.getInstance().getPinCodeHelper().delete(
            new PFPinCodeHelperCallback<Boolean>() {
                @Override
                public void onResult(PFResult<Boolean> result) {
                    liveData.setData(result);
                }
            }
    );
    return liveData;
}
 
Example #6
Source File: NetworkBoundResource.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@MainThread
protected NetworkBoundResource() {
    result.setValue(RemoteResource.loading(null));
    LiveData<ResultType> dbSource = loadFromDb();
    result.addSource(dbSource, data -> {
        result.removeSource(dbSource);
        if (shouldFetch(data)) {
            fetchFromNetwork(dbSource);
        } else {
            result.addSource(dbSource,
                    newData -> result.setValue(RemoteResource.success(newData)));
        }
    });
}
 
Example #7
Source File: LiveDataUtilTest.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@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 #8
Source File: TransactionListViewModel.java    From Gander with Apache License 2.0 5 votes vote down vote up
LiveData<PagedList<HttpTransactionUIHelper>> getTransactions(String key) {
    if (key == null || key.trim().length() == 0) {
        return mTransactions;
    } else {
        DataSource.Factory<Integer, HttpTransactionUIHelper> factory = mTransactionDao.getAllTransactionsWith(key, TransactionDao.SearchType.DEFAULT).map(HttpTransactionUIHelper.HTTP_TRANSACTION_UI_HELPER_FUNCTION);
        return new LivePagedListBuilder<>(factory, config).build();
    }
}
 
Example #9
Source File: LiveEventBusCore.java    From LiveEventBus with Apache License 2.0 5 votes vote down vote up
private String getObserverInfo(LiveData liveData) {
    try {
        Field field = LiveData.class.getDeclaredField("mObservers");
        field.setAccessible(true);
        Object mObservers = field.get(liveData);
        return mObservers.toString();
    } catch (Exception e) {
        return "";
    }
}
 
Example #10
Source File: DeviceStatusViewModel.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
public LiveData<BondingState> getBondState() {
    return mBondStateLiveData;
}
 
Example #11
Source File: DiscoverMoviesViewModel.java    From PopularMovies with MIT License 4 votes vote down vote up
public LiveData<PagedList<Movie>> getPagedList() {
    return pagedList;
}
 
Example #12
Source File: LoginViewModel.java    From UpdogFarmer with GNU General Public License v3.0 4 votes vote down vote up
LiveData<Integer> getTimeDifference() {
    if (!timeAligned) {
        alignTime();
    }
    return timeDifference;
}
 
Example #13
Source File: ThreadRepository.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public LiveData<List<MailboxWithRoleAndName>> getMailboxes(String threadId) {
    return Transformations.switchMap(databaseLiveData, database ->database.mailboxDao().getMailboxesForThreadLiveData(threadId));
}
 
Example #14
Source File: MailboxQueryViewModel.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public LiveData<MailboxOverviewItem> getMailbox() {
    return mailbox;
}
 
Example #15
Source File: MovieRepository.java    From PopularMovies with MIT License 4 votes vote down vote up
@Override
public LiveData<List<Movie>> getAllFavoriteMovies() {
    return mLocalDataSource.getAllFavoriteMovies();
}
 
Example #16
Source File: TeiDashboardMobileActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public LiveData<Boolean> observeFilters() {
    return filtersShowing;
}
 
Example #17
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    AudienceNetworkAds.initialize(this);
    dataObjectRepositry = DataObjectRepositry.dataObjectRepositry;
    ButterKnife.bind(this);
    getSafeIntent();
    initUI();
    onClick();
    addToFirebase();


    interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
    AdRequest adRequest = new AdRequest.Builder().build();
    interstitialAd.loadAd(adRequest);

    allLoginUserList.clear();
    LiveData<List<Logins>> loggedInUsers = DataObjectRepositry.dataObjectRepositry.getAllUsers();
    loggedInUsers.observe(MainActivity.this, new Observer<List<Logins>>() {
        @Override
        public void onChanged(List<Logins> logins) {
            if (logins.size() > 0) {
                allLoginUserList.clear();
                for (Logins logins1 : logins) {

                    DrawerMenuPojo drawerMenuPojo1 = new DrawerMenuPojo();
                    drawerMenuPojo1.setMenuName(logins1.getUserName());
                    drawerMenuPojo1.setImage(R.drawable.ic_account);
                    allLoginUserList.add(drawerMenuPojo1);

                }
            }
        }
    });


    if (!TextUtils.isEmpty(user_id)) {

        showLoading();
        new GetUserInfo(user_id).execute();
    } else {

        changeFragment(new StoriesFragment());
        toolbar.setTitle("Stories");
    }
    toolbar.setTitle("Stories");
}
 
Example #18
Source File: MessageViewModel.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 4 votes vote down vote up
public LiveData<PagedList<Message>> getMessages() {
    return messages;
}
 
Example #19
Source File: InvalidationLiveDataContainer.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
void onActive(LiveData liveData) {
    mLiveDataSet.add(liveData);
}
 
Example #20
Source File: SampleViewModel.java    From permission-bitte with MIT License 4 votes vote down vote up
LiveData<State> getState() {
  return state;
}
 
Example #21
Source File: MessageRequestViewModel.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public LiveData<RecipientInfo> getRecipientInfo() {
  return recipientInfo;
}
 
Example #22
Source File: MainViewModel.java    From blinkreceipt-android with MIT License 4 votes vote down vote up
public LiveData<RecognizerResults> scanItems() {
    return scanItems;
}
 
Example #23
Source File: NoteRepository.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 4 votes vote down vote up
LiveData<List<Note>> getAllNotes(){
    return mAllNotes;
}
 
Example #24
Source File: AutoDiscoverViewModel.java    From UpdogFarmer with GNU General Public License v3.0 4 votes vote down vote up
LiveData<String> getStatus() {
    return statusText;
}
 
Example #25
Source File: EchoViewModel.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@NonNull
public LiveData<String> getResponse() {
    return mResponseLiveData;
}
 
Example #26
Source File: DataViewModel.java    From ui with Apache License 2.0 4 votes vote down vote up
public LiveData<String> getDataLeft() {
    return left;
}
 
Example #27
Source File: LiveDataTimerViewModel.java    From android-lifecycles with Apache License 2.0 4 votes vote down vote up
public LiveData<Long> getElapsedTime() {
    return mElapsedTime;
}
 
Example #28
Source File: McuMgrViewModel.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@NonNull
public LiveData<Boolean> getBusyState() {
    return mBusyStateLiveData;
}
 
Example #29
Source File: WordRepository.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 4 votes vote down vote up
LiveData<List<Word>> getAllWords() {
    return mAllWords;
}
 
Example #30
Source File: DaoIdentity.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
        " JOIN account ON account.id = identity.account")
LiveData<List<TupleIdentityEx>> liveIdentities();