Java 类android.arch.lifecycle.MediatorLiveData 实例源码

项目:Fairy    文件:LogcatContentRepository.java   
static LiveData<LogcatContent> creat (int id, LiveData<LogcatContent> rawData, String grep) {
    /**
     * ${rawData}变量是Source中的MediatorLiveData
     */
    MediatorLiveData<LogcatContent> rawMediaData = (MediatorLiveData) rawData;
    if (grep.equals("")) {
        writeClearCache(id, GrepFilter.RAW_SIGNAL);
        rawMediaData.setValue(clearCache);
        return rawData;
    }
    rawMediaData.setValue(clearCache);
    return GrepFilter.grepData(rawData, grep);
}
项目:Fairy    文件:ExampleUnitTest.java   
public Holder() {
    data = new MediatorLiveData<>();
    data.addSource(rawData, str -> {
        data.setValue(str);
    });
    transData.setValue(false);
}
项目:mapbox-plugins-android    文件:DataRepository.java   
private DataRepository(final SearchHistoryDatabase database) {
  this.database = database;
  observableSearchHistory = new MediatorLiveData<>();

  observableSearchHistory.addSource(database.searchHistoryDao().getAll(),
    new Observer<List<SearchHistoryEntity>>() {
      @Override
      public void onChanged(@Nullable List<SearchHistoryEntity> searchHistoryEntities) {
        if (database.getDatabaseCreated().getValue() != null) {
          observableSearchHistory.postValue(searchHistoryEntities);
        }
      }
    });
}
项目:android-architecture-components    文件:ProductListViewModel.java   
public ProductListViewModel(Application application) {
    super(application);

    mObservableProducts = new MediatorLiveData<>();
    // set by default null, until we get data from the database.
    mObservableProducts.setValue(null);

    LiveData<List<ProductEntity>> products = ((BasicApp) application).getRepository()
            .getProducts();

    // observe the changes of the products from the database and forward them
    mObservableProducts.addSource(products, mObservableProducts::setValue);
}
项目:android-architecture-components    文件:DataRepository.java   
private DataRepository(final AppDatabase database) {
    mDatabase = database;
    mObservableProducts = new MediatorLiveData<>();

    mObservableProducts.addSource(mDatabase.productDao().loadAllProducts(),
            productEntities -> {
                if (mDatabase.getDatabaseCreated().getValue() != null) {
                    mObservableProducts.postValue(productEntities);
                }
            });
}
项目:Fairy    文件:MergeResource.java   
MergeResource(AppExecutors executors) {
    this.executors = executors;
    result = new MediatorLiveData<>();
}
项目:AndroidGithubIssues    文件:ListIssuesViewModel.java   
public ListIssuesViewModel() {
    mApiResponse = new MediatorLiveData<>();
    mIssueRepository = new IssueRepositoryImpl();
}