Observable 複数データソース に優先順位をつける

通信を使うとき, 必要になるだろうよくあるパターンだと思います.

通信状況や不要なリクエストやキャッシュを使うかどうか.

どこからデータを取得してくるか.

- メモリ
- ストレージ
- ネットワーク

それぞれのソース別に Observable を作ったら, 優先順位をつけたら連結する.

ReactiveX_-_Concat_operator

ReactiveX - Concat operator

条件をつけて, 最初の一つだけ利用する.

ReactiveX_-_First_operator

ReactiveX - First operator

そんなサンプルコードがあります.


// Create our sequence for querying best available data
Observable<Data> source = Observable.concat(
    sources.memory(),
    sources.disk(),
    sources.network()
  )
  .first(data -> data != null && data.isUpToDate());

// "Request" latest data once a second
Observable.interval(1, TimeUnit.SECONDS)
  .flatMap(__ -> source)
  .subscribe(data -> System.out.println("Received: " + data.value));

rxjava-multiple-sources-sample/Sample.java


public Observable<GfyItem> getGfyItem(final String gifUrl, final String gfyName) {

  // Use the first source that returns a valid name
  return Observable.concat(

    // We already have the name
    Observable.just(gfyName),

    // We check for a pre-converted gif (for the gfyname)
    getPreExistingGfyName(gifUrl),

    // We need to convert the gif (then retrieve the gfyname)
    convertGifToGfyName(gifUrl)
  )
  .first(result -> !TextUtils.isEmpty(result))
  .flatMap(this::getMetadata)
  .map(GfyMetadata::getGfyItem);
}

android-gfycat/GfycatService.java

非常にわかりやすいサンプルや記事で勉強になりますっ.

Loading data from multiple sources with RxJava


こんな木製の Android/iPhone 見かけたらちとびびる

こういうかんじ.

Nexus_5_Skins__Wraps___Decals____dbrand

iPhone_6s_Skins__Wraps___Decals____dbrand

かなりきもいです.

街で見かけたら二度見しちゃいそうです.

これ, シールです.

Nexus_5_Skins____How_to_Apply____dbrand_🔊

Nexus_5_Skins____How_to_Apply____dbrand_🔊

Nexus_5_Skins____How_to_Apply____dbrand_🔊

貼り付けたらドライヤーで乾かします.

Nexus_5_Skins____How_to_Apply____dbrand_🔊

このシール, 非常に緻密にできており色も多数用意されています.

Nexus 5 Skins, Wraps & Decals // dbrand

表・裏・側面など一式で $10 程度.

私も「木製」にしちゃおうか.

dbrand____iPhone_6s_Skins__Nexus_6P_Skins__Galaxy_S7_Edge_Skins__Galaxy_S7_Skins

dbrand // iPhone 6s Skins, Nexus 6P Skins, Galaxy S7 Edge Skins, Galaxy S7 Skins


Google Play デベロッパー コンソール で「コナミコード」を

The Konami Code (Japanese: コナミコマンド, Konami komando, "Konami command") is a cheat code that appears in many Konami video games, although the code also appears in some non-Konami games.

Konami Code - Wikipedia, the free encyclopedia

コナミコマンドとは、コナミ(およびコナミデジタルエンタテインメント)から発売された多数のコンピュータゲームに登場する隠しコマンドの一種である。初出はファミリーコンピュータ版『グラディウス』(1986年)で、ゲーム中にポーズボタンを押して一時停止し、十字キーとABボタンで「上上下下左右左右BA」の順に入力すると自機が強化される。

コナミコマンド - Wikipedia

Konami_Code_-_Wikipedia__the_free_encyclopedia

Google Play デベロッパーコンソール上でやってみると...

すべてのアプリ_-_Google_Play_Developer_Console

画面が傾きます.

クッキーを消すと元に戻ります.

以上です.