【光环助手V5.5.0】游戏单广场(选择标签UI)https://git.ghzs.com/pm/halo-app-issues/-/issues/1598
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class GameCollectionTagEntity(
|
||||
@SerializedName("category_id")
|
||||
val categoryId: String = "",
|
||||
@SerializedName("name")
|
||||
val categoryName: String = "",
|
||||
val tagList: List<GameCollectionTag> = ArrayList()
|
||||
) : Parcelable {
|
||||
|
||||
@Parcelize
|
||||
data class GameCollectionTag(
|
||||
@SerializedName("tag_id")
|
||||
val tagId: String = "",
|
||||
@SerializedName("name")
|
||||
val tagName: String = ""
|
||||
) : Parcelable
|
||||
}
|
||||
@ -17,7 +17,7 @@ import com.gh.gamecenter.entity.TagInfoEntity
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.gamecollection.choose.ChooseGamesActivity
|
||||
import com.gh.gamecenter.gamecollection.choose.ChooseGamesViewModel
|
||||
import com.gh.gamecenter.gamecollection.square.GameCollectionTagSelectActivity
|
||||
import com.gh.gamecenter.gamecollection.tag.GameCollectionTagSelectActivity
|
||||
import com.gh.gamecenter.mvvm.Status
|
||||
import com.gh.gamecenter.qa.editor.LocalMediaActivity
|
||||
import com.zhihu.matisse.Matisse
|
||||
|
||||
@ -1,93 +0,0 @@
|
||||
package com.gh.gamecenter.gamecollection.square
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.databinding.FragmentGameCollectionTagSelectBinding
|
||||
import com.gh.gamecenter.databinding.ItemGameCollectionSelectedTagBinding
|
||||
import com.gh.gamecenter.normal.NormalFragment
|
||||
|
||||
class GameCollectionTagSelectFragment : NormalFragment() {
|
||||
|
||||
private var mBinding: FragmentGameCollectionTagSelectBinding? = null
|
||||
private var mAdapter: GameCollectionTagAdapter? = null
|
||||
private var firstVisibleItemPosition = 0
|
||||
|
||||
private val updateSelectedTagView: (() -> Unit) = {
|
||||
mAdapter?.multipleTagList?.let { list ->
|
||||
mBinding?.selectedTagContainer?.removeAllViews()
|
||||
for (name in list) {
|
||||
val selectedTagView = ItemGameCollectionSelectedTagBinding.inflate(layoutInflater)
|
||||
selectedTagView.run {
|
||||
tagTv.text = name
|
||||
root.setOnClickListener {
|
||||
list.remove(name)
|
||||
mBinding?.selectedTagContainer?.removeView(selectedTagView.root)
|
||||
mAdapter?.notifyDataSetChanged()
|
||||
mBinding?.selectedTagScrollView?.visibility = if (firstVisibleItemPosition == 0 || list.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
mBinding?.selectedTagContainer?.addView(selectedTagView.root)
|
||||
}
|
||||
mBinding?.selectedTagScrollView?.visibility = if (firstVisibleItemPosition == 0 || list.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int = 0
|
||||
|
||||
override fun getInflatedLayout() =
|
||||
FragmentGameCollectionTagSelectBinding.inflate(layoutInflater).apply {
|
||||
mBinding = this
|
||||
}.root
|
||||
|
||||
override fun onMenuItemClick(menuItem: MenuItem?) {
|
||||
// if (menuItem?.itemId == R.id.layout_menu_save) {
|
||||
// requireActivity().setResult(
|
||||
// GameCollectionSquareFragment.TAG_SELECT_REQUEST,
|
||||
// Intent().putExtra("tagName", mAdapter?.singleTagName)
|
||||
// )
|
||||
// requireActivity().finish()
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val data = arrayListOf(
|
||||
"游戏玩法",
|
||||
"body",
|
||||
"游戏题材",
|
||||
"body",
|
||||
"游戏题材",
|
||||
"body",
|
||||
"游戏玩法",
|
||||
"body",
|
||||
"游戏玩法",
|
||||
"body",
|
||||
"游戏玩法",
|
||||
"body",
|
||||
"游戏玩法",
|
||||
"body"
|
||||
)
|
||||
mAdapter = GameCollectionTagAdapter(requireContext(), true, data, updateSelectedTagView)
|
||||
mBinding?.tagRv?.run {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
adapter = mAdapter
|
||||
addOnScrollListener(object :RecyclerView.OnScrollListener(){
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
when (newState) {
|
||||
RecyclerView.SCROLL_STATE_IDLE -> firstVisibleItemPosition = (layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
RecyclerView.SCROLL_STATE_DRAGGING -> firstVisibleItemPosition = (layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
}
|
||||
mBinding?.selectedTagScrollView?.visibility = if (firstVisibleItemPosition == 0 || mAdapter?.multipleTagList?.isEmpty() == true) View.GONE else View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.gamecollection.square
|
||||
package com.gh.gamecenter.gamecollection.tag
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
@ -7,38 +7,36 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.util.DisplayUtils
|
||||
import com.gh.common.util.dip2px
|
||||
import com.gh.gamecenter.databinding.*
|
||||
import com.gh.gamecenter.entity.GameCollectionTagEntity
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter
|
||||
|
||||
class GameCollectionTagAdapter(
|
||||
context: Context,
|
||||
val singleChoice: Boolean = true,
|
||||
val data: ArrayList<String>,
|
||||
private val updateCallback: (() -> Unit)
|
||||
) :
|
||||
BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {
|
||||
|
||||
private var mTagViewList = arrayListOf<ItemGameCollectionTagBinding>()
|
||||
var singleTagName = ""
|
||||
var multipleTagList = arrayListOf<String>()
|
||||
var mTagList = arrayListOf<GameCollectionTagEntity>()
|
||||
var singleTag: GameCollectionTagEntity.GameCollectionTag? = null
|
||||
var multipleTagList = arrayListOf<GameCollectionTagEntity.GameCollectionTag>()
|
||||
|
||||
fun setTagList(tagList: ArrayList<GameCollectionTagEntity>) {
|
||||
mTagList = tagList
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (singleChoice) {
|
||||
if (position % 2 == 0) TAG_HEADER else TAG_BODY
|
||||
} else {
|
||||
if (position == 0) SELECTED_TAGS else if (position % 2 != 0) TAG_HEADER else TAG_BODY
|
||||
}
|
||||
return if (!singleChoice && position == 0) SELECTED_TAGS else TAG_ITEM
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType){
|
||||
SELECTED_TAGS -> GameCollectionSelectedTagViewHolder(
|
||||
GameCollectionSelectedTagItemBinding.inflate(mLayoutInflater, parent, false)
|
||||
)
|
||||
TAG_HEADER -> GameCollectionTagHeaderViewHolder(
|
||||
GameCollectionTagHeaderItemBinding.inflate(mLayoutInflater, parent, false)
|
||||
)
|
||||
else -> GameCollectionTagBodyViewHolder(
|
||||
GameCollectionTagBodyItemBinding.inflate(mLayoutInflater, parent, false)
|
||||
else -> GameCollectionTagItemViewHolder(
|
||||
GameCollectionTagItemBinding.inflate(mLayoutInflater, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
@ -47,13 +45,13 @@ class GameCollectionTagAdapter(
|
||||
is GameCollectionSelectedTagViewHolder -> {
|
||||
holder.binding.selectedTagFlexbox.removeAllViews()
|
||||
holder.binding.hintTv.visibility = if (multipleTagList.size == 0) View.VISIBLE else View.GONE
|
||||
for (name in multipleTagList) {
|
||||
for (tag in multipleTagList) {
|
||||
val selectedTagView =
|
||||
ItemGameCollectionSelectedTagBinding.inflate(mLayoutInflater)
|
||||
.apply {
|
||||
tagTv.text = name
|
||||
tagTv.text = tag.tagName
|
||||
root.setOnClickListener {
|
||||
multipleTagList.remove(name)
|
||||
multipleTagList.remove(tag)
|
||||
updateCallback.invoke()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@ -61,87 +59,70 @@ class GameCollectionTagAdapter(
|
||||
holder.binding.selectedTagFlexbox.addView(selectedTagView)
|
||||
}
|
||||
}
|
||||
is GameCollectionTagHeaderViewHolder -> {
|
||||
holder.binding.headerTv.text = data[position]
|
||||
if (position == 0) {
|
||||
holder.binding.root.setPadding(
|
||||
16F.dip2px(),
|
||||
40F.dip2px(),
|
||||
16F.dip2px(),
|
||||
10F.dip2px()
|
||||
)
|
||||
}
|
||||
}
|
||||
is GameCollectionTagBodyViewHolder -> {
|
||||
val dataList = arrayListOf(
|
||||
"ghgg",
|
||||
"das5555554a44",
|
||||
"dasda54544",
|
||||
"dsdasdasdas",
|
||||
"dasdsa8787",
|
||||
"58748sss"
|
||||
)
|
||||
is GameCollectionTagItemViewHolder -> {
|
||||
val data = mTagList[if (singleChoice) position else position - 1]
|
||||
holder.binding.tagFlexbox.removeAllViews()
|
||||
for (name in dataList) {
|
||||
val tag = if(singleChoice) getSingleTag(name) else getMultipleTag(name)
|
||||
holder.binding.titleTv.text = data.categoryName
|
||||
holder.binding.titleTv.setPadding(
|
||||
16F.dip2px(),
|
||||
if (position == 0) 40F.dip2px() else 10F.dip2px(),
|
||||
16F.dip2px(),
|
||||
10F.dip2px()
|
||||
)
|
||||
holder.binding.tagFlexbox.setPadding(
|
||||
12F.dip2px(),
|
||||
5F.dip2px(),
|
||||
12F.dip2px(),
|
||||
if (position == itemCount - 1) 97F.dip2px() else 15F.dip2px()
|
||||
)
|
||||
for (tagEntity in data.tagList) {
|
||||
val tag = if(singleChoice) getSingleTag(tagEntity) else getMultipleTag(tagEntity)
|
||||
mTagViewList.add(tag)
|
||||
holder.binding.tagFlexbox.addView(tag.root)
|
||||
}
|
||||
if (position == data.size - 1) {
|
||||
holder.binding.root.setPadding(
|
||||
12F.dip2px(),
|
||||
5F.dip2px(),
|
||||
12F.dip2px(),
|
||||
97F.dip2px()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSingleTag(name: String) = ItemGameCollectionTagBinding.inflate(mLayoutInflater).apply {
|
||||
tagTv.text = name
|
||||
private fun getSingleTag(tag: GameCollectionTagEntity.GameCollectionTag) = ItemGameCollectionTagBinding.inflate(mLayoutInflater).apply {
|
||||
tagTv.text = tag.tagName
|
||||
tagTv.layoutParams = tagTv.layoutParams.apply { width = (DisplayUtils.getScreenWidth() - 56F.dip2px()) / 4 }
|
||||
root.setOnClickListener {
|
||||
for (tag in mTagViewList) {
|
||||
if (tag.tagTv != tagTv) tag.tagTv.isChecked = false
|
||||
for (tagView in mTagViewList) {
|
||||
if (tagView.tagTv != tagTv) tagView.tagTv.isChecked = false
|
||||
}
|
||||
tagTv.isChecked = !tagTv.isChecked
|
||||
if (tagTv.isChecked) singleTagName = tagTv.text.toString()
|
||||
if (tagTv.isChecked) singleTag = tag
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMultipleTag(name: String) =
|
||||
private fun getMultipleTag(tag: GameCollectionTagEntity.GameCollectionTag) =
|
||||
ItemGameCollectionTagBinding.inflate(mLayoutInflater).apply {
|
||||
tagTv.layoutParams = tagTv.layoutParams.apply { width = (DisplayUtils.getScreenWidth() - 56F.dip2px()) / 4 }
|
||||
tagTv.text = name
|
||||
if (multipleTagList.contains(name)) tagTv.isChecked = true
|
||||
tagTv.text = tag.tagName
|
||||
if (multipleTagList.contains(tag)) tagTv.isChecked = true
|
||||
root.setOnClickListener {
|
||||
tagTv.isChecked = !tagTv.isChecked
|
||||
if (tagTv.isChecked) {
|
||||
multipleTagList.add(name)
|
||||
multipleTagList.add(tag)
|
||||
} else {
|
||||
if (multipleTagList.contains(name)) multipleTagList.remove(name)
|
||||
if (multipleTagList.contains(tag)) multipleTagList.remove(tag)
|
||||
}
|
||||
updateCallback.invoke()
|
||||
notifyItemChanged(0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = data.size
|
||||
override fun getItemCount() = if (singleChoice) mTagList.size else mTagList.size + 1
|
||||
|
||||
class GameCollectionSelectedTagViewHolder(var binding: GameCollectionSelectedTagItemBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
class GameCollectionTagBodyViewHolder(var binding: GameCollectionTagBodyItemBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
class GameCollectionTagHeaderViewHolder(var binding: GameCollectionTagHeaderItemBinding) :
|
||||
class GameCollectionTagItemViewHolder(var binding: GameCollectionTagItemBinding) :
|
||||
RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
companion object {
|
||||
const val SELECTED_TAGS = 100
|
||||
const val TAG_HEADER = 101
|
||||
const val TAG_BODY = 102
|
||||
const val TAG_ITEM = 101
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gh.gamecenter.gamecollection.square
|
||||
package com.gh.gamecenter.gamecollection.tag
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -15,9 +15,12 @@ class GameCollectionTagSelectActivity : NormalActivity() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY_IS_SINGLE_CHOICE = "single_choice"
|
||||
|
||||
@JvmStatic
|
||||
fun getIntent(context: Context): Intent {
|
||||
fun getIntent(context: Context, singleChoice: Boolean = false): Intent {
|
||||
val bundle = Bundle()
|
||||
bundle.putBoolean(KEY_IS_SINGLE_CHOICE, singleChoice)
|
||||
return getTargetIntent(
|
||||
context,
|
||||
GameCollectionTagSelectActivity::class.java,
|
||||
@ -0,0 +1,82 @@
|
||||
package com.gh.gamecenter.gamecollection.tag
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.util.viewModelProvider
|
||||
import com.gh.gamecenter.databinding.FragmentGameCollectionTagSelectBinding
|
||||
import com.gh.gamecenter.databinding.ItemGameCollectionSelectedTagBinding
|
||||
import com.gh.gamecenter.entity.GameCollectionTagEntity
|
||||
import com.gh.gamecenter.normal.NormalFragment
|
||||
|
||||
class GameCollectionTagSelectFragment : NormalFragment() {
|
||||
|
||||
private var mSingleChoice = false
|
||||
private lateinit var mBinding: FragmentGameCollectionTagSelectBinding
|
||||
private lateinit var mAdapter: GameCollectionTagAdapter
|
||||
private lateinit var mViewModel: GameCollectionTagViewModel
|
||||
private var firstVisibleItemPosition = 0
|
||||
|
||||
private val updateSelectedTagView: (() -> Unit) = {
|
||||
mAdapter.multipleTagList.let { list ->
|
||||
mBinding.selectedTagContainer.removeAllViews()
|
||||
for (tag in list) {
|
||||
val selectedTagView = ItemGameCollectionSelectedTagBinding.inflate(layoutInflater)
|
||||
selectedTagView.run {
|
||||
tagTv.text = tag.tagName
|
||||
root.setOnClickListener {
|
||||
list.remove(tag)
|
||||
mBinding.selectedTagContainer.removeView(selectedTagView.root)
|
||||
mAdapter.notifyDataSetChanged()
|
||||
mBinding.selectedTagScrollView.visibility = if (firstVisibleItemPosition == 0 || list.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
mBinding.selectedTagContainer.addView(selectedTagView.root)
|
||||
}
|
||||
mBinding.selectedTagScrollView.visibility = if (firstVisibleItemPosition == 0 || list.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int = 0
|
||||
|
||||
override fun getInflatedLayout() =
|
||||
FragmentGameCollectionTagSelectBinding.inflate(layoutInflater).apply {
|
||||
mBinding = this
|
||||
}.root
|
||||
|
||||
override fun onMenuItemClick(menuItem: MenuItem?) {
|
||||
// if (menuItem?.itemId == R.id.layout_menu_save) {
|
||||
// requireActivity().setResult(
|
||||
// GameCollectionSquareFragment.REQUEST_SELECT_TAG,
|
||||
// Intent().putExtra("tagName", mAdapter.singleTag?.tagName)
|
||||
// )
|
||||
// requireActivity().finish()
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mSingleChoice = arguments?.getBoolean(GameCollectionTagSelectActivity.KEY_IS_SINGLE_CHOICE) ?: false
|
||||
mAdapter = GameCollectionTagAdapter(requireContext(), mSingleChoice, updateSelectedTagView)
|
||||
mViewModel = viewModelProvider()
|
||||
mBinding.tagRv.run {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
adapter = mAdapter
|
||||
addOnScrollListener(object :RecyclerView.OnScrollListener() {
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
firstVisibleItemPosition = (layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
|
||||
mBinding.selectedTagScrollView.visibility = if (firstVisibleItemPosition == 0 || mAdapter.multipleTagList.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// mViewModel.tagListLiveData.observe(viewLifecycleOwner) {
|
||||
// mAdapter.setTagList(it)
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.gh.gamecenter.gamecollection.tag
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.gh.gamecenter.entity.GameCollectionTagEntity
|
||||
import com.gh.gamecenter.retrofit.BiResponse
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class GameCollectionTagViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
var tagListLiveData = MutableLiveData<ArrayList<GameCollectionTagEntity>>()
|
||||
private val mApi = RetrofitManager.getInstance(getApplication()).api
|
||||
|
||||
init {
|
||||
// getGameCollectionTagList()
|
||||
}
|
||||
|
||||
// @SuppressLint("CheckResult")
|
||||
// fun getGameCollectionTagList() {
|
||||
// mApi.gameCollectionTagList
|
||||
// .subscribeOn(Schedulers.io())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(object: BiResponse<ArrayList<GameCollectionTagEntity>>(){
|
||||
// override fun onSuccess(data: ArrayList<GameCollectionTagEntity>) {
|
||||
// tagListLiveData.postValue(data)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user