use of rx.Subscriber in project mosby by sockeqwe.
the class MailProviderTest method changeLabel.
@Test
public void changeLabel() {
mailProvider.getMail(1).subscribe(new Action1<Mail>() {
@Override
public void call(Mail mail) {
final AtomicBoolean changed = new AtomicBoolean(false);
final String newLabel = "foo";
mailProvider.setLabel(mail.getId(), newLabel).subscribe(new Subscriber<Mail>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
Assert.fail("Error while changing label");
}
@Override
public void onNext(Mail mail) {
Assert.assertEquals(mail.getLabel(), newLabel);
changed.set(true);
}
});
Assert.assertTrue(changed.get());
}
});
}
use of rx.Subscriber in project PhotoNoter by yydcdut.
the class SplashPresenterImpl method checkDisks.
private void checkDisks() {
if (!mLocalStorageUtils.isFirstTime()) {
initFiles();
Observable.create(new Observable.OnSubscribe<File[]>() {
@Override
public void call(Subscriber<? super File[]> subscriber) {
File f = new File(FilePathUtils.getPath());
if (f.exists()) {
subscriber.onNext(f.listFiles());
subscriber.onCompleted();
} else {
subscriber.onError(new RxException(""));
}
}
}).flatMap(fileList -> Observable.from(fileList)).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()).filter(file1 -> !file1.isDirectory()).filter(file -> file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png") || file.getName().toLowerCase().endsWith(".jpeg")).count().subscribe((fileNumber -> {
mRxSandBox.getNumber().subscribe((integer -> {
if (fileNumber != integer) {
Intent checkIntent = new Intent(mContext, CheckService.class);
mContext.startService(checkIntent);
}
}), (throwable -> YLog.e(throwable)));
}), (throwable -> YLog.e(throwable)));
}
}
use of rx.Subscriber in project PhotoNoter by yydcdut.
the class AlbumPresenterImpl method savePhotosFromGallery.
@Override
public void savePhotosFromGallery(ArrayList<String> pathList) {
List<PhotoNote> photoNotes = new ArrayList<>(pathList.size());
for (String path : pathList) {
PhotoNote photoNote = new PhotoNote(System.currentTimeMillis() + ".jpg", System.currentTimeMillis(), System.currentTimeMillis(), "", "", System.currentTimeMillis(), System.currentTimeMillis(), mCategoryId);
photoNote.setTag(path);
photoNotes.add(photoNote);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
YLog.e(e);
}
}
mRxPhotoNote.savePhotoNotes(photoNotes).flatMap(//注意看这里是photoNotes
photoNotes1 -> Observable.from(photoNotes)).map(photoNote -> {
String path = (String) photoNote.getTag();
if (!TextUtils.isEmpty(path)) {
try {
FilePathUtils.copyFile(path, photoNote.getBigPhotoPathWithoutFile());
FilePathUtils.saveSmallPhotoFromBigPhoto(photoNote.getBigPhotoPathWithFile(), photoNote.getPhotoName());
photoNote.setPaletteColor(Utils.getPaletteColor(ImageLoaderManager.loadImageSync(photoNote.getBigPhotoPathWithFile())));
} catch (IOException e) {
YLog.e(e);
}
}
return photoNote;
}).lift(new Observable.Operator<Integer, PhotoNote>() {
@Override
public Subscriber<? super PhotoNote> call(Subscriber<? super Integer> subscriber) {
return new Subscriber<PhotoNote>() {
@Override
public void onCompleted() {
subscriber.onNext(mCategoryId);
subscriber.onCompleted();
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(PhotoNote photoNote) {
}
};
}
}).doOnSubscribe(() -> mAlbumView.showProgressBar()).subscribeOn(AndroidSchedulers.mainThread()).subscribe(integer -> {
EventBus.getDefault().post(new PhotoNoteCreateEvent());
mRxPhotoNote.refreshByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).subscribe(photoNoteList -> {
mAlbumView.updateData(photoNoteList);
mAlbumView.notifyDataSetChanged();
mAlbumView.hideProgressBar();
}, (throwable -> YLog.e(throwable)));
}, (throwable -> YLog.e(throwable)));
}
use of rx.Subscriber in project PhotoNoter by yydcdut.
the class RxCategory method updateOrder.
/**
* 更新顺序
*
* @return
*/
public Observable<List<Category>> updateOrder() {
return Observable.create(new Observable.OnSubscribe<List<Category>>() {
@Override
public void call(Subscriber<? super List<Category>> subscriber) {
for (int i = 0; i < mCache.size(); i++) {
Category category = mCache.get(i);
category.setSort(i);
mCategoryDB.update(category);
}
subscriber.onNext(mCache);
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}
use of rx.Subscriber in project PhotoNoter by yydcdut.
the class RxFeedBack method doObservable.
public Observable<Map<String, String>> doObservable() {
return Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
if (TextUtils.isEmpty(mLocalStorageUtils.getUmengUid())) {
try {
StringBuilder sb = new StringBuilder("http://fb.umeng.com/api/v2/user/getuid");
sb.append("?");
Iterator iterator = mDeviceInfo.keys();
String uid;
while (iterator.hasNext()) {
String entry = (String) iterator.next();
uid = mDeviceInfo.get(entry).toString();
sb.append(URLEncoder.encode(entry, "UTF-8") + "=" + URLEncoder.encode(uid, "UTF-8") + "&");
}
if (38 == sb.charAt(sb.length() - 1)) {
sb.deleteCharAt(sb.length() - 1);
}
JSONObject json = httpConnection(sb.toString());
if (judgeStatus(json)) {
uid = json.getJSONObject("data").getString("uid");
mLocalStorageUtils.setUmengUid(uid);
subscriber.onNext(uid);
}
} catch (JSONException e) {
YLog.e(e);
subscriber.onError(e);
} catch (UnsupportedEncodingException e) {
YLog.e(e);
subscriber.onError(e);
} catch (IOException e) {
YLog.e(e);
subscriber.onError(e);
} finally {
subscriber.onCompleted();
}
} else {
subscriber.onNext(mLocalStorageUtils.getUmengUid());
subscriber.onCompleted();
}
}
}).subscribeOn(Schedulers.io()).lift(new Observable.Operator<JSONObject, String>() {
@Override
public Subscriber<? super String> call(Subscriber<? super JSONObject> subscriber) {
return new Subscriber<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
@Override
public void onNext(String s) {
StringBuilder sb = new StringBuilder(mEmail);
sb.append("<---联系方式 ").append(mType).append(" 反馈内容--->").append(mContent);
try {
mDeviceInfo.put("content", sb.toString());
mDeviceInfo.put("feedback_id", mFeedbackId);
mDeviceInfo.put("reply_id", System.currentTimeMillis() + "");
mDeviceInfo.put("device_uuid", mLocalStorageUtils.getDeviceUuid());
mDeviceInfo.put("type", "new_feedback");
mDeviceInfo.put("uid", s);
subscriber.onNext(mDeviceInfo);
} catch (JSONException e) {
YLog.e(e);
subscriber.onError(e);
}
}
};
}
}).lift(new Observable.Operator<JSONObject, JSONObject>() {
@Override
public Subscriber<? super JSONObject> call(Subscriber<? super JSONObject> subscriber) {
return new Subscriber<JSONObject>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
subscriber.onError(e);
}
@Override
public void onNext(JSONObject jsonObject) {
try {
JSONObject json = httpConnection(jsonObject, "http://fb.umeng.com/api/v2/feedback/reply/new");
subscriber.onNext(json);
} catch (IOException e) {
YLog.e(e);
subscriber.onError(e);
}
}
};
}
}).map(jsonObject -> setData(jsonObject));
}
Aggregations