本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
}