Skip to content

Commit

Permalink
fix: play Ui logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WisteFinch committed Aug 18, 2024
1 parent d743e5f commit ef1b8a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,20 @@ class PlayFragment : Fragment() {

// Set Uis and flags.
if (!isFreeInput) {
itemSelected = true
currentItem = data
stepAdapter.setData(data.steps)
stepsList = data.steps.toMutableList()
binding.playStratagemTitle.text = data.name
binding.playBlank.visibility = View.INVISIBLE
binding.playStratagemTitle.visibility = View.VISIBLE
binding.playStepsScrollView.visibility = View.VISIBLE
}
else {
itemSelected = false
binding.playStratagemTitle.visibility = View.INVISIBLE
binding.playStepsScrollView.visibility = View.INVISIBLE
if (itemSelected && currentItem == data) {
resetUi()
}
else {
itemSelected = true
currentItem = data
stepAdapter.clear()
stepAdapter.setData(data.steps)
stepsList = data.steps.toMutableList()
binding.playStratagemTitle.text = data.name
binding.playBlank.visibility = View.INVISIBLE
binding.playStratagemTitle.visibility = View.VISIBLE
binding.playStepsScrollView.visibility = View.VISIBLE
}
}
}

Expand Down Expand Up @@ -499,10 +500,17 @@ class PlayFragment : Fragment() {
lifecycleScope.launch {
activateStratagem(currentItem)
}
resetUi()
}

/**
* Reset Ui
*/
private fun resetUi() {
// Reset Uis and flags
itemSelected = false
currentStepPos = 0
stepAdapter.setData(listOf())
stepAdapter.clear()
binding.playBlank.visibility = View.VISIBLE
binding.playStratagemTitle.visibility = View.INVISIBLE
binding.playStepsScrollView.visibility = View.INVISIBLE
Expand All @@ -529,6 +537,7 @@ class PlayFragment : Fragment() {
lifecycleScope.launch {
activateStratagem(item)
}
resetUi()
}
}
val itemTouchHelper = ItemTouchHelper(callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ class StepPlayAdapter: RecyclerView.Adapter<StepPlayAdapter.ListViewHolder>() {
this.dataList = list
notifyDataSetChanged()
}

/**
* Clear the adapter data
*
* Because of the small amount of data, there is no need to compare the difference, ignore the warning.
*/
@SuppressLint("NotifyDataSetChanged")
fun clear() {
setData(listOf())
}
}

0 comments on commit ef1b8a0

Please sign in to comment.