use of rx.functions.Action1 in project pinpoint by naver.
the class CompletableTestRunner method completableError.
public void completableError() throws Exception {
final String message = "Hello World";
final Exception expected = new RuntimeException("expected");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Exception> actual = new AtomicReference<>();
Subscription subscription = shoutService.shout(message, expected).subscribeOn(Schedulers.computation()).doOnCompleted(new Action0() {
@Override
public void call() {
latch.countDown();
}
}).doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
actual.set((Exception) throwable);
latch.countDown();
}
}).subscribe();
latch.await(500L, TimeUnit.MILLISECONDS);
subscription.unsubscribe();
Assert.assertSame(expected, actual.get());
TestHelper.awaitForSpanDataFlush();
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
// Skip rx java internal traces as they differ between versions and it's too much work to split the tests.
// Instead, we can verify them indirectly by checking if user methods have been traced.
verifier.ignoreServiceType("RX_JAVA_INTERNAL");
verifier.awaitTrace(event(ServiceType.ASYNC.getName(), "Asynchronous Invocation"), 20, 500);
Method subscribeMethod = Completable.class.getDeclaredMethod("subscribe");
verifier.verifyTrace(event("RX_JAVA", subscribeMethod));
// event - RX_JAVA_INTERNAL some form of Worker.schedule(Action0)
verifier.verifyTrace(event(ServiceType.ASYNC.getName(), "Asynchronous Invocation"));
// event - RX_JAVA_INTERNAL some form of Action0 implementation's call() inside OperatorSubscribeOn that gets scheduled
Method shoutMethod = EchoRepository.class.getDeclaredMethod("shout", String.class, Exception.class);
verifier.verifyTrace(event(ServiceType.INTERNAL_METHOD.getName(), shoutMethod, expected));
}
use of rx.functions.Action1 in project archi by ivacf.
the class RepositoryViewModel method loadFullUser.
private void loadFullUser(String url) {
ArchiApplication application = ArchiApplication.get(context);
GithubService githubService = application.getGithubService();
subscription = githubService.userFromUrl(url).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Action1<User>() {
@Override
public void call(User user) {
Log.i(TAG, "Full user data loaded " + user);
ownerName.set(user.name);
ownerEmail.set(user.email);
ownerLocation.set(user.location);
ownerEmailVisibility.set(user.hasEmail() ? View.VISIBLE : View.GONE);
ownerLocationVisibility.set(user.hasLocation() ? View.VISIBLE : View.GONE);
ownerLayoutVisibility.set(View.VISIBLE);
}
});
}
use of rx.functions.Action1 in project ListenerMusicPlayer by hefuyicoder.
the class FolderAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(final ItemHolder itemHolder, final int position) {
itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
int adapterPosition = itemHolder.getAdapterPosition();
final FolderInfo folderInfo = arraylist.get(adapterPosition);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_folder_addto_queue:
getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.Folder);
}
});
break;
case R.id.popup_folder_addto_playlist:
getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showAddPlaylistDialog(mContext, ids);
}
});
break;
case R.id.popup_folder_delete:
new MaterialDialog.Builder(mContext).title(mContext.getResources().getString(R.string.delete_folder)).content("删除文件夹下" + folderInfo.songCount + "首歌曲?").positiveText(R.string.delete).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.deleteTracks(mContext, ids);
RxBus.getInstance().post(new MediaUpdateEvent());
}
});
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
}).show();
break;
}
return false;
}
});
menu.inflate(R.menu.popup_folder);
menu.show();
}
});
}
use of rx.functions.Action1 in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method addFolders.
@Override
public void addFolders(List<File> folders, final List<Folder> existedFolders) {
Subscription subscription = Observable.from(folders).filter(new Func1<File, Boolean>() {
@Override
public Boolean call(File file) {
for (Folder folder : existedFolders) {
if (file.getAbsolutePath().equals(folder.getPath())) {
return false;
}
}
return true;
}
}).flatMap(new Func1<File, Observable<Folder>>() {
@Override
public Observable<Folder> call(File file) {
Folder folder = new Folder();
folder.setName(file.getName());
folder.setPath(file.getAbsolutePath());
List<Song> musicFiles = FileUtils.musicFiles(file);
folder.setSongs(musicFiles);
folder.setNumOfSongs(musicFiles.size());
return Observable.just(folder);
}
}).toList().flatMap(new Func1<List<Folder>, Observable<List<Folder>>>() {
@Override
public Observable<List<Folder>> call(List<Folder> folders) {
return mRepository.create(folders);
}
}).doOnNext(new Action1<List<Folder>>() {
@Override
public void call(List<Folder> folders) {
Collections.sort(folders, new Comparator<Folder>() {
@Override
public int compare(Folder f1, Folder f2) {
return f1.getName().compareToIgnoreCase(f2.getName());
}
});
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<List<Folder>>() {
@Override
public void onStart() {
mView.showLoading();
}
@Override
public void onCompleted() {
mView.hideLoading();
}
@Override
public void onError(Throwable e) {
mView.hideLoading();
mView.handleError(e);
}
@Override
public void onNext(List<Folder> allNewFolders) {
mView.onFoldersAdded(allNewFolders);
}
});
mSubscriptions.add(subscription);
}
use of rx.functions.Action1 in project StylishMusicPlayer by ryanhoo.
the class LocalMusicPresenter method onLoadFinished.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Subscription subscription = Observable.just(cursor).flatMap(new Func1<Cursor, Observable<List<Song>>>() {
@Override
public Observable<List<Song>> call(Cursor cursor) {
List<Song> songs = new ArrayList<>();
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
do {
Song song = cursorToMusic(cursor);
songs.add(song);
} while (cursor.moveToNext());
}
return mRepository.insert(songs);
}
}).doOnNext(new Action1<List<Song>>() {
@Override
public void call(List<Song> songs) {
Log.d(TAG, "onLoadFinished: " + songs.size());
Collections.sort(songs, new Comparator<Song>() {
@Override
public int compare(Song left, Song right) {
return left.getDisplayName().compareTo(right.getDisplayName());
}
});
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<List<Song>>() {
@Override
public void onStart() {
mView.showProgress();
}
@Override
public void onCompleted() {
mView.hideProgress();
}
@Override
public void onError(Throwable throwable) {
mView.hideProgress();
Log.e(TAG, "onError: ", throwable);
}
@Override
public void onNext(List<Song> songs) {
mView.onLocalMusicLoaded(songs);
mView.emptyView(songs.isEmpty());
}
});
mSubscriptions.add(subscription);
}
Aggregations