优化创建游戏单

This commit is contained in:
jack
2021-11-15 09:36:26 +08:00
parent 58b37f8922
commit 32bc1a4a6f
4 changed files with 96 additions and 8 deletions

View File

@ -55,4 +55,24 @@ public class PatternUtils {
return newText;
}
/**
* 判断字符串中是否有连续2个以上的换行
*/
public static boolean isHasWrap(String text){
String pattern = "[\\n]{2,}";
Regex regex = new Regex(pattern);
return regex.find(text, 0) != null;
}
/**
* 替换字符串中连续2个以上的换行为一个换行
*/
public static String replaceWrap(String text) {
String pattern = "[\\n]{2,}";
String newText = text;
if (isHasSpace(text)) {
newText = text.replaceAll(pattern, "\n");
}
return newText;
}
}

View File

@ -563,10 +563,10 @@ data class GameEntity(
simpleGame.nameSuffix = nameSuffix
simpleGame.mIcon = mIcon
simpleGame.mRawIcon = mRawIcon
simpleGame.active=active
simpleGame.iconSubscript=iconSubscript
simpleGame.recommendStar=recommendStar
simpleGame.recommendText=recommendText
simpleGame.active = active
simpleGame.iconSubscript = iconSubscript
simpleGame.recommendStar = recommendStar
simpleGame.recommendText = recommendText
return simpleGame
}
@ -792,6 +792,10 @@ data class SimpleGame(
//游戏单推荐分数
@SerializedName("recommend_star")
var recommendStar: Int = 5,
@SerializedName("mirror_status")
var mirrorStatus: String? = "",
@SerializedName("mirror_data")
var mirrorData: SimpleGame? = null,
//游戏单推荐理由
@SerializedName("recommend_text")
var recommendText: String = "",
@ -815,6 +819,8 @@ data class SimpleGame(
gameEntity.icon = mIcon
gameEntity.rawIcon = mRawIcon
gameEntity.iconSubscript = iconSubscript
gameEntity.mirrorStatus = mirrorStatus
gameEntity.mirrorData = mirrorData?.toGameEntity()
gameEntity.recommendStar = recommendStar
gameEntity.recommendText = recommendText
return gameEntity

View File

@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.core.widget.doOnTextChanged
import androidx.recyclerview.widget.RecyclerView
import com.gh.base.BaseRecyclerViewHolder
import com.gh.common.util.PatternUtils
import com.gh.common.util.TextHelper
import com.gh.common.util.consume
import com.gh.common.util.toBinding
@ -39,6 +40,20 @@ class ChooseGamesAdapter(context: Context, val dragListener: ItemDragListener) :
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is ChooseGamesViewHolder) {
val gameEntity = mEntityList[position]
holder.binding.recommendReasonEt.run {
doOnTextChanged { text, start, _, _ ->
if(PatternUtils.isHasWrap(text.toString())){
setText(PatternUtils.replaceWrap(text.toString()))
setSelection(start)
return@doOnTextChanged
}
if (PatternUtils.isHasSpace(text.toString())) {
setText(PatternUtils.replaceSpace(text.toString()))
setSelection(start)
return@doOnTextChanged
}
}
}
holder.binding.gameNameTv.text = gameEntity.name
holder.binding.gameIcon.displayGameIcon(gameEntity)
holder.binding.recommendReasonEt.setText(gameEntity.recommendText)

View File

@ -13,7 +13,6 @@ import com.gh.gamecenter.CropImageActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.ActivityGameCollectionEditBinding
import com.gh.gamecenter.entity.GamesCollectionEntity
import com.gh.gamecenter.entity.SimpleGame
import com.gh.gamecenter.entity.TagInfoEntity
import com.gh.gamecenter.eventbus.EBReuse
import com.gh.gamecenter.gamecollection.choose.ChooseGamesActivity
@ -32,6 +31,7 @@ class GameCollectionEditActivity : ToolBarActivity() {
private lateinit var mViewModel: GameCollectionEditViewModel
private lateinit var mChooseGamesViewModel: ChooseGamesViewModel
private var mProcessingDialog: WaitingDialogFragment? = null
private var mPatchCommitCount = 0
override fun getLayoutId(): Int = R.layout.activity_game_collection_edit
@ -51,6 +51,34 @@ class GameCollectionEditActivity : ToolBarActivity() {
}
private fun initListener() {
mBinding.gameCollectionTitleEt.run {
doOnTextChanged { text, start, _, _ ->
if (text?.contains("\n") == true) {
setText(text.toString().replace("\n", ""))
setSelection(start)
return@doOnTextChanged
}
if (PatternUtils.isHasSpace(text.toString())) {
setText(PatternUtils.replaceSpace(text.toString()))
setSelection(start)
return@doOnTextChanged
}
}
}
mBinding.gameCollectionIntroduceEt.run {
doOnTextChanged { text, start, _, _ ->
if(PatternUtils.isHasWrap(text.toString())){
setText(PatternUtils.replaceWrap(text.toString()))
setSelection(start)
return@doOnTextChanged
}
if (PatternUtils.isHasSpace(text.toString())) {
setText(PatternUtils.replaceSpace(text.toString()))
setSelection(start)
return@doOnTextChanged
}
}
}
mBinding.uploadPictureBtn.setOnClickListener {
PermissionHelper.checkStoragePermissionBeforeAction(
this,
@ -96,7 +124,7 @@ class GameCollectionEditActivity : ToolBarActivity() {
mViewModel.gameCollectionPatch?.run {
mViewModel.imageUrl = cover
if (status.isNotEmpty() && status != "draft") {
if (status.isNotEmpty() && (status != "draft" || display == "self_only")) {
setNavigationTitle("编辑游戏单")
}
initPosterUI()
@ -262,12 +290,12 @@ class GameCollectionEditActivity : ToolBarActivity() {
}
val games = mChooseGamesViewModel.chooseGamesLiveData.value ?: arrayListOf()
val title = mBinding.gameCollectionTitleEt.text.toString()
val title = mBinding.gameCollectionTitleEt.text.toString().trim()
if (title.isEmpty()) {
toast("请填写游戏单的标题")
return
}
val introduce = mBinding.gameCollectionIntroduceEt.text.toString()
val introduce = mBinding.gameCollectionIntroduceEt.text.toString().trim()
if (introduce.length < 10) {
toast("介绍至少10个字")
return
@ -290,6 +318,25 @@ class GameCollectionEditActivity : ToolBarActivity() {
}.toList()
)
val patch = mViewModel.gameCollectionPatch
if (patch != null
&& patch.status.isNotEmpty()
&& patch.status != "draft"
&& games.size < 8
) {
if (mPatchCommitCount < 2) {
toast("游戏单收录的游戏不能少于8款")
mPatchCommitCount++
return
} else {
if (!mBinding.selfOnlyCb.isChecked) {
toast("没想好收录的游戏,开启仅自己可见试试")
mPatchCommitCount++
return
}
}
}
if (isSelfOnly) {
DialogHelper.showDialog(this, "温馨提示", "游戏单开启“仅自己可见”后,将不会对其他用户展示,是否继续提交", "确定", "取消", {
mViewModel.uploadContent(requestMap)