如何在观察发布者时设置不同的字段



在观察为某些表中的图片设置Id的上传函数时,我需要为profilePictreIdwallpaperPictureId属性设置这些Id。我没有找到任何解决方案,flatMap或其他功能太难理解了。我可以获得下面提到的ID,但我需要对它们进行皂化,这样我就可以把它们放在不同的领域。要么给我一个解决方案,要么一份好的文件。不用担心代码中的其他函数,我只需要订阅时Rx的分离函数。谢谢

更多解释:上传后,我需要设置两个属性,但我只应该在订阅方法onSuccessUpload中设置。我尝试了很多方法,但我将两个Id都设置为profilePictureIdwallpaperPictureId,这是一个应该将它们分开的问题。

s1变量的响应:

E/PictureIds@@@>>>: [4e6a3956bf8743b78fe4ffa546f627f0.png]
E/Utils: {"attachments":"4e6a3956bf8743b78fe4ffa546f627f0.png","status":"SUCCESS","message":"-"}
E/PictureIds@@@>>>: [7712b7f081d045e8b94f077e40994290.png]
E/Utils: {"attachments":"7712b7f081d045e8b94f077e40994290.png","status":"SUCCESS","message":"-"}
private Disposable picture; // this varaibale is set in onSuccessUpload to subscribe 
private void onSuccessUpload(){
setPicture(RxBus.sendResponseUploadLink()
.subscribe(s1 -> {
String[] id = new String[]{s1.getString("attachments")};
Timber.tag("PictureIds@@@>>>").e(Arrays.toString(id));
setProfilePictureId(id[0]);  // problem is here
setWallpaperPictureId(id[1]); // problem is here
}));
}
private void uploadPicture(String path){
Upload uploadPicture = new Upload();
uploadPicture.upload(getToken(), path);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.channel_profile_image:
selectProfileImage();
break;
case R.id.channel_cover_image:
selectCoverImage();
break;
case R.id.submit_social_channel:
onSuccessUpload();
uploadPicture(getProfileFilePath());
uploadPicture(getWallpaperFilePath());

}
}

subscribe函数返回一个Subscription对象,该对象允许您管理可观察对象和订阅者之间创建的关系。

你只有一个订阅者,所以你能做的最好的事情就是在API响应中添加imageType,比如

{
"attachments":"4e6a3956bf8743b78fe4ffa546f627f0.png",
"imageType":"Wallpaper"
"status":"SUCCESS",
"message":"-"
}

因此,在订阅者中,您可以区分上传的图像,并相应地调用不同的功能。

最新更新