Merge branch 'dev' of gitlab.ghzhushou.com:halo/assistant-android into dev
This commit is contained in:
@ -34,9 +34,8 @@ object ErrorHelper {
|
||||
if (customizedHandler(errorEntity.code ?: 0)) {
|
||||
return
|
||||
} else {
|
||||
ErrorHelper.handleError(context, important, errorEntity)
|
||||
handleError(context, important, errorEntity)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +55,7 @@ object ErrorHelper {
|
||||
return
|
||||
}
|
||||
|
||||
ErrorHelper.handleError(context, important, errorEntity)
|
||||
handleError(context, important, errorEntity)
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
@ -115,6 +115,14 @@ fun View.debounceActionWithInterval(interval: Long = 300, action: (() -> Unit)?
|
||||
debounceActionWithInterval(this.id, interval, action)
|
||||
}
|
||||
|
||||
/**
|
||||
* 告诉需要返回 true or false 的外层这个事件已经被消费(即返回 true)
|
||||
*/
|
||||
inline fun consume(f: () -> Unit): Boolean {
|
||||
f()
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* String related
|
||||
*/
|
||||
|
||||
@ -322,18 +322,14 @@ class AnswerDetailFragment : NormalFragment() {
|
||||
showFollowHint()
|
||||
}
|
||||
} else if (apiResponse.httpException != null) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(requireContext(), apiResponse.httpException.response().errorBody()!!.string(), false) {
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(requireContext(), apiResponse.httpException.response().errorBody()?.string(), false) {
|
||||
when (it) {
|
||||
403008 -> {
|
||||
403008 -> consume {
|
||||
toast(R.string.ask_vote_hint)
|
||||
answerDetail.me.isAnswerVoted = true
|
||||
updateLikeView(answerDetail.me.isAnswerVoted, answerDetail.vote)
|
||||
true
|
||||
}
|
||||
403036 -> {
|
||||
toast(R.string.ask_vote_limit_hint)
|
||||
true
|
||||
}
|
||||
403036 -> consume { toast(R.string.ask_vote_limit_hint) }
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,16 +240,11 @@ class AnswerEditActivity : BaseRichEditorActivity() {
|
||||
startActivity(intent)
|
||||
}
|
||||
finish()
|
||||
|
||||
} else if (it?.status == Status.ERROR) {
|
||||
var errorString: String? = null
|
||||
val e = it.exception
|
||||
if (e != null && e.code() == 403) {
|
||||
try {
|
||||
errorString = e.response().errorBody()!!.string()
|
||||
val string = JSONObject(errorString)
|
||||
val code = string.getInt("code")
|
||||
if (code == 403037) {
|
||||
val errorString = it.exception?.response()?.errorBody()?.string()
|
||||
ErrorHelper.handleErrorWithCustomizedHandler(this, errorString, customizedHandler = { code ->
|
||||
when (code) {
|
||||
403037 -> consume {
|
||||
if (TextUtils.isEmpty(mViewModel?.draftId)) {
|
||||
DialogUtils.showAlertDialog(this, "发布失败"
|
||||
, "问题已被删除,无法发布回答", "好吧", "", {
|
||||
@ -262,16 +257,10 @@ class AnswerEditActivity : BaseRichEditorActivity() {
|
||||
finish()
|
||||
})
|
||||
}
|
||||
return@Observer
|
||||
} else {
|
||||
ErrorHelper.handleError(this, errorString, false)
|
||||
return@Observer
|
||||
}
|
||||
} catch (e1: Exception) {
|
||||
e1.printStackTrace()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
ErrorHelper.handleError(this, errorString, false)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user