Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev
This commit is contained in:
@ -7,10 +7,13 @@ import com.halo.assistant.HaloApp
|
||||
object ToastUtils {
|
||||
/** 之前显示的内容 */
|
||||
private var mOldMsg: String? = null
|
||||
|
||||
/** Toast对象 */
|
||||
private var mToast: Toast? = null
|
||||
|
||||
/** 第一次时间 */
|
||||
private var mOneTime: Long = 0
|
||||
|
||||
/** 第二次时间 */
|
||||
private var mTwoTime: Long = 0
|
||||
|
||||
@ -19,19 +22,31 @@ object ToastUtils {
|
||||
* @param message
|
||||
*/
|
||||
fun showToast(message: String) {
|
||||
showToast(message, -1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示Toast
|
||||
* @param message
|
||||
* @param gravity
|
||||
*/
|
||||
fun showToast(message: String, gravity: Int = -1) {
|
||||
if (mToast == null) {
|
||||
mToast = Toast.makeText(HaloApp.getInstance().application, message, Toast.LENGTH_SHORT)
|
||||
if (gravity != -1) mToast!!.setGravity(gravity, 0, 0)
|
||||
mToast!!.show()
|
||||
mOneTime = System.currentTimeMillis()
|
||||
} else {
|
||||
mTwoTime = System.currentTimeMillis()
|
||||
if (message == mOldMsg) {
|
||||
if (mTwoTime - mOneTime > Toast.LENGTH_SHORT) {
|
||||
if (gravity != -1) mToast!!.setGravity(gravity, 0, 0)
|
||||
mToast!!.show()
|
||||
}
|
||||
} else {
|
||||
mOldMsg = message
|
||||
mToast!!.setText(message)
|
||||
if (gravity != -1) mToast!!.setGravity(gravity, 0, 0)
|
||||
mToast!!.show()
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.webkit.*
|
||||
@ -340,16 +341,16 @@ class RatingEditActivity : ToolBarActivity() {
|
||||
mBinding.mWebView.callHandler("getComment", OnReturnValue<String> { content ->
|
||||
val rating = mBinding.ratingScore.rating
|
||||
if (rating == 0F) {
|
||||
toast("请先给游戏打分")
|
||||
ToastUtils.showToast("请先给游戏打分", Gravity.CENTER)
|
||||
return@OnReturnValue
|
||||
}
|
||||
if (content.isEmpty()) {
|
||||
toast("评论内容不能为空喔~")
|
||||
ToastUtils.showToast("评论内容不能为空喔~", Gravity.CENTER)
|
||||
return@OnReturnValue
|
||||
}
|
||||
|
||||
if (content.length > 10000) {
|
||||
toast("评论最多10000个字")
|
||||
ToastUtils.showToast("评论最多10000个字", Gravity.CENTER)
|
||||
return@OnReturnValue
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,11 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Message
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import butterknife.OnClick
|
||||
@ -357,17 +359,19 @@ class AnswerEditActivity : BaseRichEditorActivity(), KeyboardHeightObserver {
|
||||
// filter rule
|
||||
val answerLength = HtmlUtils.stripHtml(answerContent).length
|
||||
if (answerLength < MIN_ANSWER_TEXT_LENGTH) {
|
||||
toast(R.string.answer_beneath_length_limit)
|
||||
// toast(R.string.answer_beneath_length_limit)
|
||||
ToastUtils.showToast(getString(R.string.answer_beneath_length_limit), Gravity.CENTER)
|
||||
return@postDelayed
|
||||
} else if (answerLength > MAX_ANSWER_TEXT_LENGTH) {
|
||||
DialogUtils.showAlertDialog(this,
|
||||
getString(R.string.answer_post_failed),
|
||||
getString(R.string.answer_exceed_length_limit,
|
||||
MAX_ANSWER_TEXT_LENGTH,
|
||||
answerLength - MAX_ANSWER_TEXT_LENGTH),
|
||||
getString(R.string.answer_resume_edit), "", {
|
||||
// do nothing
|
||||
}, null)
|
||||
/* DialogUtils.showAlertDialog(this,
|
||||
getString(R.string.answer_post_failed),
|
||||
getString(R.string.answer_exceed_length_limit,
|
||||
MAX_ANSWER_TEXT_LENGTH,
|
||||
answerLength - MAX_ANSWER_TEXT_LENGTH),
|
||||
getString(R.string.answer_resume_edit), "", {
|
||||
// do nothing
|
||||
}, null)*/
|
||||
ToastUtils.showToast("回答最多输入10000个字", Gravity.CENTER)
|
||||
return@postDelayed
|
||||
}
|
||||
mViewModel.postAnswer(answerContent)
|
||||
|
||||
@ -3,6 +3,7 @@ package com.gh.gamecenter.qa.article.edit
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
@ -39,6 +40,7 @@ class ArticleEditViewModel(application: Application) : AndroidViewModel(applicat
|
||||
private val mApi = RetrofitManager.getInstance(getApplication()).api
|
||||
|
||||
val MIN_ARTICLE_TEXT_LENGTH = 6
|
||||
val MAX_ARTICLE_TEXT_LENGTH = 10000
|
||||
|
||||
val processDialog = MediatorLiveData<WaitingDialogFragment.WaitingDialogData>()
|
||||
val postImageLiveData = MediatorLiveData<Resource<LinkedHashMap<String, String>>>()
|
||||
@ -86,12 +88,12 @@ class ArticleEditViewModel(application: Application) : AndroidViewModel(applicat
|
||||
*/
|
||||
fun checkDataAndLoadTitleTag() {
|
||||
if (mSelectCommunityData == null) {
|
||||
Utils.toast(getApplication(), "请选择游戏")
|
||||
ToastUtils.showToast("请选择游戏", Gravity.CENTER)
|
||||
return
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(title)) {
|
||||
Utils.toast(getApplication(), "标题不能为空")
|
||||
ToastUtils.showToast("标题不能为空", Gravity.CENTER)
|
||||
return
|
||||
}
|
||||
|
||||
@ -100,13 +102,17 @@ class ArticleEditViewModel(application: Application) : AndroidViewModel(applicat
|
||||
// title = title?.replace(" ", "")?.replace("\n", "")
|
||||
title = title?.replace("\n", "")
|
||||
if (title!!.length < QuestionEditViewModel.QUESTION_TITLE_MIN_LENGTH) {
|
||||
Utils.toast(getApplication(), "标题至少${QuestionEditViewModel.QUESTION_TITLE_MIN_LENGTH}个字")
|
||||
ToastUtils.showToast("标题至少${QuestionEditViewModel.QUESTION_TITLE_MIN_LENGTH}个字", Gravity.CENTER)
|
||||
return
|
||||
}
|
||||
|
||||
val articleContent = HtmlUtils.stripHtml(content).length
|
||||
if (articleContent < MIN_ARTICLE_TEXT_LENGTH) {
|
||||
Utils.toast(getApplication(), "正文至少${QuestionEditViewModel.QUESTION_TITLE_MIN_LENGTH}个字")
|
||||
ToastUtils.showToast("正文至少${QuestionEditViewModel.QUESTION_TITLE_MIN_LENGTH}个字", Gravity.CENTER)
|
||||
return
|
||||
}
|
||||
if (articleContent > MAX_ARTICLE_TEXT_LENGTH) {
|
||||
ToastUtils.showToast("文章最多输入${MAX_ARTICLE_TEXT_LENGTH}个字", Gravity.CENTER)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user