android.arch.lifecycle.MutableLiveData类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中android.arch.lifecycle.MutableLiveData类的一些代码示例,展示了MutableLiveData类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MutableLiveData类的具体详情如下:
包路径:android.arch.lifecycle.MutableLiveData
类名称:MutableLiveData

MutableLiveData介绍

[英]LiveData which publicly exposes #setValue(T) and #postValue(T) method.
[中]LiveData公开#setValue(T)和#postValue(T)方法。

代码示例

代码示例来源:origin: hidroh/materialistic

void setItems(Item[] items) {
    mItems.setValue(Pair.create(mItems.getValue() != null ? mItems.getValue().second : null, items));
  }
}

代码示例来源:origin: hidroh/materialistic

public LiveData<Pair<Item[], Item[]>> getStories(String filter, @ItemManager.CacheMode int cacheMode) {
  if (mItems == null) {
    mItems = new MutableLiveData<>();
    Observable.fromCallable(() -> mItemManager.getStories(filter, cacheMode))
        .subscribeOn(mIoThreadScheduler)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(items -> setItems(items));
  }
  return mItems;
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onDestroy() {
 if (connectionSub!=null) {
  connectionSub.dispose();
 }
 disconnect();
 stopForeground(true);
 STATUS.postValue(Status.NOT_RUNNING);
 super.onDestroy();
}

代码示例来源:origin: hidroh/materialistic

public void setLiveValue(Uri uri) {
  mLiveData.setValue(uri);
  // clear notification Uri after notifying all active observers
  mLiveData.setValue(null);
}

代码示例来源:origin: kioko/android-liveData-viewModel

public static <T> LiveData<ApiResponse<T>> createCall(Response<T> response) {
    MutableLiveData<ApiResponse<T>> data = new MutableLiveData<>();
    data.setValue(new ApiResponse<>(response));
    return data;
  }
}

代码示例来源:origin: GoldenKappa/notSABS

public BillingModel() {
    isSupportedLiveData = new MutableLiveData<>();
    isPremiumLiveData = new MutableLiveData<>();
    priceLiveData = new MutableLiveData<>();
    threeMonthPriceLiveData = new MutableLiveData<>();
    isSupportedLiveData.postValue(false);
    isPremiumLiveData.postValue(false);
    priceLiveData.postValue("");
  }
}

代码示例来源:origin: TrustWallet/trust-wallet-android-source

public void fetchTokens() {
  progress.postValue(true);
  if (defaultNetwork.getValue() == null) {
    findDefaultNetwork();
  }
  disposable = fetchTokensInteract
      .fetch(wallet.getValue())
      .subscribe(this::onTokens, this::onError);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setHasOptionsMenu(true);
 ShoutingEchoService.STATUS.observe(this,
  status -> {
   if (server!=null && status!=null) server.setChecked(status.isRunning);
  });
}

代码示例来源:origin: commonsguy/cw-omnibus

private boolean isServerRunning() {
 ShoutingEchoService.Status status=ShoutingEchoService.STATUS.getValue();
 return(status!=null && status.isRunning);
}

代码示例来源:origin: k9mail/k-9

@MainThread
public void setValue(@Nullable T t) {
  pending.set(true);
  super.setValue(t);
}

代码示例来源:origin: VivekNeel/CricKotlin

public static <T> LiveData<ApiResponse<T>> createCall(Response<T> response) {
    MutableLiveData<ApiResponse<T>> data = new MutableLiveData<>();
    data.setValue(new ApiResponse<>(response));
    return data;
  }
}

代码示例来源:origin: TrustWallet/trust-wallet-android-source

public void fetchTransactions() {
  progress.postValue(true);
  transactionDisposable = Observable.interval(0, FETCH_TRANSACTIONS_INTERVAL, TimeUnit.SECONDS)
    .doOnNext(l ->
      disposable = fetchTransactionsInteract
          .fetch(defaultWallet.getValue()/*new Wallet("0x60f7a1cbc59470b74b1df20b133700ec381f15d3")*/)
          .subscribe(this::onTransactions, this::onError))
    .subscribe();
}

代码示例来源:origin: k9mail/k-9

@MainThread
public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer<T> observer) {
  if (hasActiveObservers()) {
    Timber.w("Multiple observers registered but only one will be notified of changes.");
  }
  // Observe the internal MutableLiveData
  super.observe(owner, new Observer<T>() {
    @Override
    public void onChanged(@Nullable T t) {
      if (pending.compareAndSet(true, false)) {
        observer.onChanged(t);
      }
    }
  });
}

代码示例来源:origin: hidroh/materialistic

public void refreshStories(String filter, @ItemManager.CacheMode int cacheMode) {
  if (mItems == null || mItems.getValue() == null) {
    return;
  }
  Observable.fromCallable(() -> mItemManager.getStories(filter, cacheMode))
      .subscribeOn(mIoThreadScheduler)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(items -> setItems(items));
}

代码示例来源:origin: SergeyVinyar/AndroidNewArchitectureExample

public void refreshData() {
    cityNameLiveData.setValue(cityNameLiveData.getValue());
  }
}

代码示例来源:origin: ittianyu/MVVM

@Override
  protected void onPostExecute(Long rowId) {
    data.setValue(rowId);
  }
}.execute();

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate() {
 super.onCreate();
 rxBluetooth=new RxBluetooth(getApplicationContext());
 acceptConnections();
 NotificationManager mgr=
  (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
 if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O &&
  mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) {
  mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER,
   "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
 }
 startForeground(1338, buildForegroundNotification());
 STATUS.postValue(Status.IS_RUNNING);
}

代码示例来源:origin: HarinTrivedi/Easy.Api

public UserViewModel(Application application) {
 super(application);
 // initialize live data
 usersLiveData = new MutableLiveData<>();
 loadingStateLiveData = new MutableLiveData<>();
 // set by default null
 usersLiveData.setValue(null);
 //EasyApi Configuration
 usersListApi = new EasyApi.Builder<Envelop<List<User>>>(Objects.requireNonNull(application))
   .attachLoadingLiveData(loadingStateLiveData).build();
 usersListRxApi = new EasyApi.Builder<Envelop<List<User>>>(Objects.requireNonNull(application))
   .attachLoadingLiveData(loadingStateLiveData).configureWithRx().build();
}

代码示例来源:origin: anitaa1990/PagingLibrary-Sample

public FeedDataSource(AppController appController) {
  this.appController = appController;
  networkState = new MutableLiveData();
  initialLoading = new MutableLiveData();
}

代码示例来源:origin: JeremyLiao/LiveDataBus

public void observeSticky(@NonNull LifecycleOwner owner, @NonNull Observer<T> observer) {
  super.observe(owner, observer);
}

相关文章