RxJava zip鎿嶄綔绗﹀湪Android涓殑瀹為檯浣跨敤鍦烘櫙
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RxJava zip鎿嶄綔绗﹀湪Android涓殑瀹為檯浣跨敤鍦烘櫙相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
姒傝堪
Returns an Observable that emits the results of a specified combiner function applied to combinations of two items emitted,
in sequence, by two other Observables.
娴佺▼鍥撅細
绠€鍗曟潵璇磟ip鎿嶄綔绗﹀氨鏄悎骞跺涓暟鎹祦锛?
鐒跺悗鍙戦€?Emit)鏈€缁堝悎骞剁殑鏁版嵁銆?/p>
闇€姹傛弿杩帮細
- 鍦ㄥ緢澶歛pp绉嶉兘浼氭湁鍥剧墖涓婁紶鐨勫姛鑳斤紝姣斿鍟嗗搧鐨勮瘎浠凤紝
- 瀹㈡埛绔厑璁哥敤鎴锋媿鐓т笂浼?鍙兘澶氬紶)锛?/li>
- 鎶婂浘鐗囦笂浼犲埌鍙堟媿浜?鐜板湪寰堝涓皬鍨嬪叕鍙搁兘鏄敤鍙堟媿浜戜綔涓哄浘鐗囨湇鍔″櫒)锛?/li>
- 鐒跺悗鑾峰彇鍥剧墖鐨剈rl锛屽啀鎶婂浘鐗囩殑淇℃伅锛堝浘鐗噓rl锛屽浘鐗囧ぇ灏忥級鍙戦€佺粰鍥剧墖銆?/li>
涓昏閫昏緫锛?/p>
- 鍏堟妸鎵€鏈夌殑鍥剧墖涓婁紶鍒板張鎷嶄簯锛堟瘮濡?寮犲浘鐗囷級
- 鑾峰彇鍥剧墖鐨剈rl璺緞锛屽浘鐗囧ぇ灏忕瓑
- 鏈€鍚庢妸鏁版嵁鍏ㄩ儴鎻愪氦缁欐湇鍔″櫒
//闇€瑕佷笂浼犵殑鍥剧墖
Picture[] ps = xxx;
Observable.zip(
Observable.from(ps),
getUpYunAddress(ps.length),//鑾峰彇涓婁紶鐨剈rl
new Func2<Picture, UpYunAddress, Picture>() {
@Override
public Picture call(Picture picture, UpYunAddress upYunAddress) {
//濡傛灉璇ュ浘鐗囧凡缁忎笂浼犲垯涓嶅簲璇ヤ笂浼? if (TextUtils.isEmpty(picture.getSource())) {
try {
//浣跨敤鍙堟媿浜戞彁渚涚殑宸ュ叿绫伙紝涓婁紶鍥剧墖
String path = UpYunUtil.uploadImage(upYunAddress, picture.getLocalUrl());
//鑾峰彇鏈€缁堢殑url
String finalUrl = upYunAddress.getPrefix() + path;
picture.setSource(finalUrl);
} catch (Exception e) {
e.printStackTrace();
}
}
return picture;
}
})
.subscribeOn(Schedulers.io())
.observeOn(androidSchedulers.mainThread())
//涓婁紶鎴愬姛鍚庤幏鍙栧浘鐗囧ぇ灏? .flatMap(new Func1<Picture, Observable<Picture>>() {
@Override
public Observable<Picture> call(Picture picture) {
if (TextUtils.isEmpty(picture.getHeight()) || TextUtils.isEmpty(picture.getWidth())) {
BitmapFactory.Options options;
if (!TextUtils.isEmpty(picture.getLocalUrl())) {
options = ImageUtil.getBitmapOptions(picture.getLocalUrl());
picture.setLocalUrl(null);
} else {
options = ImageUtil.getBitmapOptions(picture.getSource());
}
picture.setWidth(String.valueOf(options.outWidth));
picture.setHeight(String.valueOf(options.outHeight));
}
return Observable.just(picture);
}
});
//鏈€鍚庡鐞嗘渶缁堢殑鏁版嵁銆?/code>
鏂囩珷杞嚜锛?a href="http://blog.csdn.net/johnny901114/article/details/51614927">http://blog.csdn.net/johnny901114/article/details/51614927
鎰熻阿鍘熶綔鑰呯殑鍒嗕韩!
以上是关于RxJava zip鎿嶄綔绗﹀湪Android涓殑瀹為檯浣跨敤鍦烘櫙的主要内容,如果未能解决你的问题,请参考以下文章
涓€瀵逛竴鍏宠仈鏌ヨ鏃朵娇鐢╮elation杩炶疮鎿嶄綔鏌ヨ鍚庯紝璋冪敤getLastSql()鏂规硶杈撳嚭鐨剆ql璇彞
鏁版嵁搴撶瑪璁?馃搾 MySQL鍩虹鎿嶄綔鍛戒护 鍒嗙被娓呮櫚