Last active
October 21, 2015 08:18
-
-
Save showsky/816cf063efa7a440e490 to your computer and use it in GitHub Desktop.
RxJava, RxAndroid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new Thread() { | |
| @Override | |
| public void run() { | |
| super.run(); | |
| for (File folder : folders) { | |
| File[] files = folder.listFiles(); | |
| for (File file : files) { | |
| if (file.getName().endsWith(".png")) { | |
| final Bitmap bitmap = getBitmapFromFile(file); | |
| getActivity().runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { | |
| imageCollectorView.addImage(bitmap); | |
| } | |
| }); | |
| } | |
| } | |
| } | |
| } | |
| }.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable.from(folders) | |
| .flatMap(new Func1<File, Observable<File>>() { | |
| @Override | |
| public Observable<File> call(File file) { | |
| return Observable.from(file.listFiles()); | |
| } | |
| }) | |
| .filter(new Func1<File, Boolean>() { | |
| @Override | |
| public Boolean call(File file) { | |
| return file.getName().endsWith(".png"); | |
| } | |
| }) | |
| .map(new Func1<File, Bitmap>() { | |
| @Override | |
| public Bitmap call(File file) { | |
| return getBitmapFromFile(file); | |
| } | |
| }) | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(new Action1<Bitmap>() { | |
| @Override | |
| public void call(Bitmap bitmap) { | |
| imageCollectorView.addImage(bitmap); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment