社区优化汇总(2020年5月)(4)https://gitlab.ghzs.com/pm/halo-app-issues/-/issues/872
This commit is contained in:
@ -20,6 +20,8 @@ import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
object UploadImageUtils {
|
||||
@ -109,6 +111,7 @@ object UploadImageUtils {
|
||||
fun compressAndUploadImageList(type: UploadType, imgs: List<String>, compressGif: Boolean, listener: OnUploadImageListListener): Disposable? {
|
||||
var subscription: Disposable? = null
|
||||
val postImageList = LinkedHashMap<String, String>()
|
||||
val errorMap = HashMap<String, Exception>()
|
||||
|
||||
Observable.create(ObservableOnSubscribe<Map<String, String>> {
|
||||
val compressList = compressImageList(imgs, compressGif)
|
||||
@ -145,11 +148,13 @@ object UploadImageUtils {
|
||||
onFailure(IllegalAccessException("HeHe"))
|
||||
}
|
||||
|
||||
|
||||
override fun onFailure(exception: Exception) {
|
||||
// 若遇到错误且 subscription?.isDisposed 为 true 时会抛出 io.reactivex.exceptions.UndeliverableException 异常
|
||||
// if (subscription?.isDisposed == true) return
|
||||
// it.onError(exception) // fuck
|
||||
it.onNext(Collections.emptyMap())
|
||||
// it.onNext(Collections.emptyMap())
|
||||
errorMap[img.path] = exception
|
||||
}
|
||||
})
|
||||
listProgress += img.length()
|
||||
@ -165,18 +170,18 @@ object UploadImageUtils {
|
||||
|
||||
override fun onComplete() {
|
||||
if (postImageList.size == 0) {
|
||||
listener.onError()
|
||||
listener.onError(errorMap)
|
||||
} else {
|
||||
listener.onSuccess(postImageList)
|
||||
listener.onSuccess(postImageList, errorMap)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNext(t: Map<String, String>) {
|
||||
if (!t.isEmpty()) postImageList.putAll(t)
|
||||
if (t.isNotEmpty()) postImageList.putAll(t)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
e.printStackTrace()
|
||||
override fun onError(ignore: Throwable) {
|
||||
|
||||
}
|
||||
})
|
||||
return subscription
|
||||
@ -285,8 +290,8 @@ object UploadImageUtils {
|
||||
}
|
||||
|
||||
interface OnUploadImageListListener {
|
||||
fun onSuccess(imageUrl: LinkedHashMap<String, String>) // key:sourceImage value:compressImage
|
||||
fun onError() // 全部上传失败时回调
|
||||
fun onSuccess(imageUrl: LinkedHashMap<String, String>, errorMap: Map<String, Exception>) // key:sourceImage value:compressImage
|
||||
fun onError(errorMap: Map<String, Exception>) // 全部上传失败时回调
|
||||
fun onProgress(total: Long, progress: Long)
|
||||
}
|
||||
|
||||
|
||||
@ -765,7 +765,7 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(@NotNull LinkedHashMap<String, String> imageUrl) {
|
||||
public void onSuccess(@NotNull LinkedHashMap<String, String> imageUrl, @NotNull Map<String, ? extends Exception> errorMap) {
|
||||
Utils.log("意见反馈:图片上传完成");
|
||||
final JSONArray picArray = new JSONArray();
|
||||
for (String s : imageUrl.keySet()) {
|
||||
@ -775,7 +775,7 @@ public class SuggestionActivity extends ToolBarActivity implements OnRequestCall
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
public void onError(@NotNull Map<String, ? extends Exception> errorMap) {
|
||||
if (postDialog != null) {
|
||||
postDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
@ -162,19 +162,32 @@ class AnswerEditViewModel(application: Application,
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("图片上传中 $percent%", true))
|
||||
}
|
||||
|
||||
override fun onSuccess(imageUrl: LinkedHashMap<String, String>) {
|
||||
override fun onSuccess(imageUrl: LinkedHashMap<String, String>, errorMap: Map<String, Exception>) {
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("上传中...", false))
|
||||
postImageLiveData.postValue(Resource.success(imageUrl))
|
||||
val errorSize = pictureList.size - imageUrl.size
|
||||
if (errorSize > 0) {
|
||||
for (error in errorMap.values) {
|
||||
if (error is HttpException && error.code() == 403) {
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张违规图片上传失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张图片上传失败")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
override fun onError(errorMap: Map<String, Exception>) {
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("上传中...", false))
|
||||
postImageLiveData.postValue(Resource.error(null))
|
||||
val errorSize = pictureList.size
|
||||
|
||||
for (error in errorMap.values) {
|
||||
if (error is HttpException && error.code() == 403) {
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张违规图片上传失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
if (errorSize == 1) {
|
||||
Utils.toast(getApplication(), "图片上传失败")
|
||||
} else {
|
||||
|
||||
@ -169,18 +169,31 @@ class ArticleEditViewModel(application: Application) : AndroidViewModel(applicat
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("图片上传中 $percent%", true))
|
||||
}
|
||||
|
||||
override fun onSuccess(imageUrl: LinkedHashMap<String, String>) {
|
||||
override fun onSuccess(imageUrl: LinkedHashMap<String, String>, errorMap: Map<String, Exception>) {
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("上传中...", false))
|
||||
postImageLiveData.postValue(Resource.success(imageUrl))
|
||||
val errorSize = pictureList.size - imageUrl.size
|
||||
if (errorSize > 0) {
|
||||
for (error in errorMap.values) {
|
||||
if (error is HttpException && error.code() == 403) {
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张违规图片上传失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张图片上传失败")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
override fun onError(errorMap: Map<String, Exception>) {
|
||||
processDialog.postValue(WaitingDialogFragment.WaitingDialogData("上传中...", false))
|
||||
val errorSize = pictureList.size
|
||||
|
||||
for (error in errorMap.values) {
|
||||
if (error is HttpException && error.code() == 403) {
|
||||
Utils.toast(getApplication(), errorSize.toString() + "张违规图片上传失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
if (errorSize == 1) {
|
||||
Utils.toast(getApplication(), "图片上传失败")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user