當前位置: 首頁>>代碼示例>>Java>>正文


Java BehaviorSubject.asObservable方法代碼示例

本文整理匯總了Java中rx.subjects.BehaviorSubject.asObservable方法的典型用法代碼示例。如果您正苦於以下問題:Java BehaviorSubject.asObservable方法的具體用法?Java BehaviorSubject.asObservable怎麽用?Java BehaviorSubject.asObservable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.subjects.BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.asObservable方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAutoPlaylistSongs

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
private Observable<List<Song>> getAutoPlaylistSongs(AutoPlaylist playlist) {
    BehaviorSubject<List<Song>> subject;

    if (mPlaylistContents.containsKey(playlist)) {
        subject = mPlaylistContents.get(playlist);
    } else {
        subject = BehaviorSubject.create();
        mPlaylistContents.put(playlist, subject);

        playlist.generatePlaylist(mMusicStore, this, mPlayCountStore)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        subject.observeOn(Schedulers.io())
                .subscribe(contents -> {
                    MediaStoreUtil.editPlaylist(mContext, playlist, contents);
                }, throwable -> {
                    Timber.e(throwable, "Failed to save playlist contents");
                });
    }

    return subject.asObservable();
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:24,代碼來源:LocalPlaylistStore.java

示例2: updateRepo

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
public Observable<String> updateRepo(String userName) {
    BehaviorSubject<String> requestSubject = BehaviorSubject.create();

    Observable<List<Repo>> observable = mClient.getRepos(userName);
    observable.subscribeOn(Schedulers.io())
              .observeOn(Schedulers.io())
              .subscribe(l -> {
                                mDatabase.insertRepoList(l);
                                requestSubject.onNext(userName);},
                         e -> requestSubject.onError(e),
                         () -> requestSubject.onCompleted());
    return requestSubject.asObservable();
}
 
開發者ID:fedepaol,項目名稱:RxRestSample,代碼行數:14,代碼來源:ObservableGithubRepos.java

示例3: refresh

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<Boolean> refresh() {
    mSongLoadingState.onNext(true);
    mArtistLoadingState.onNext(true);
    mAlbumLoadingState.onNext(true);
    mGenreLoadingState.onNext(true);

    BehaviorSubject<Boolean> result = BehaviorSubject.create();

    MediaStoreUtil.promptPermission(mContext)
            .observeOn(Schedulers.io())
            .map(granted -> {
                if (granted) {
                    if (mSongs != null) {
                        mSongs.onNext(getAllSongs());
                    }
                    if (mArtists != null) {
                        mArtists.onNext(getAllArtists());
                    }
                    if (mAlbums != null) {
                        mAlbums.onNext(getAllAlbums());
                    }
                    if (mGenres != null) {
                        mGenres.onNext(getAllGenres());
                    }
                }
                mSongLoadingState.onNext(false);
                mArtistLoadingState.onNext(false);
                mAlbumLoadingState.onNext(false);
                mGenreLoadingState.onNext(false);
                return granted;
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(result);

    return result.asObservable();
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:38,代碼來源:LocalMusicStore.java

示例4: getSongs

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<List<Song>> getSongs() {
    if (mSongs == null) {
        BehaviorSubject<List<Song>> subject = BehaviorSubject.create();

        Observable.fromCallable(() -> this.<Song>parseJson(SONGS_FILENAME, Song[].class))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        mSongs = subject.asObservable();
    }

    return mSongs;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:16,代碼來源:DemoMusicStore.java

示例5: getAlbums

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<List<Album>> getAlbums() {
    if (mAlbums == null) {
        BehaviorSubject<List<Album>> subject = BehaviorSubject.create();

        Observable.fromCallable(() -> this.<Album>parseJson(ALBUMS_FILENAME, Album[].class))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        mAlbums = subject.asObservable();
    }

    return mAlbums;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:16,代碼來源:DemoMusicStore.java

示例6: getArtists

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<List<Artist>> getArtists() {
    if (mArtists == null) {
        BehaviorSubject<List<Artist>> subject = BehaviorSubject.create();

        Observable.fromCallable(() -> this.<Artist>parseJson(ARTISTS_FILENAME, Artist[].class))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        mArtists = subject.asObservable();
    }

    return mArtists;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:16,代碼來源:DemoMusicStore.java

示例7: getGenres

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
@Override
public Observable<List<Genre>> getGenres() {
    if (mGenres == null) {
        BehaviorSubject<List<Genre>> subject = BehaviorSubject.create();

        Observable.fromCallable(() -> this.<Genre>parseJson(GENRES_FILENAME, Genre[].class))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subject::onNext, subject::onError);

        mGenres = subject.asObservable();
    }

    return mGenres;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:16,代碼來源:DemoMusicStore.java

示例8: getPlaylistSongs

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
private Observable<List<Song>> getPlaylistSongs(Playlist playlist) {
    BehaviorSubject<List<Song>> subject;

    if (mPlaylistContents.containsKey(playlist)) {
        subject = mPlaylistContents.get(playlist);
    } else {
        subject = BehaviorSubject.create();
        mPlaylistContents.put(playlist, subject);

        Observable.fromCallable(() -> MediaStoreUtil.getPlaylistSongs(mContext, playlist))
                .subscribe(subject::onNext, subject::onError);
    }

    return subject.asObservable();
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:16,代碼來源:LocalPlaylistStore.java

示例9: getUploadProgressStream

import rx.subjects.BehaviorSubject; //導入方法依賴的package包/類
public Observable<YouTubeUploader.UploadProgress> getUploadProgressStream(long id, String youtubeAccount) {
    final Object key = createKey(id, youtubeAccount);
    synchronized (lock) {
        BehaviorSubject<YouTubeUploader.UploadProgress> publisher = publishers.get(key);
        if (publisher == null) {
            publisher = BehaviorSubject.create();
            publishers.put(key, publisher);
        }

        Observable<YouTubeUploader.UploadProgress> observable = uploads.get(key);
        if (observable != null) {
            // XXX Shouldn't we keep a reference of the subscription? Damn, this is a huge f*cking mess.
            observable.subscribe(publisher);
        }

        return publisher.asObservable();
    }
}
 
開發者ID:labhackercd,項目名稱:edm,代碼行數:19,代碼來源:VideoAttachmentUploader.java


注:本文中的rx.subjects.BehaviorSubject.asObservable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。