Skip to content

Commit

Permalink
fix categories in SingleCharacterFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
panasetskaya committed Jul 18, 2023
1 parent 9021ed7 commit 19acd2f
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SingleCharacterFragment :
override val viewModel by viewModels<ChineseCharacterViewModel> { viewModelFactory }

private var chineseCharacterId = NEW_CHAR_ID
private var selectedCategory = ""
private var newCategory = INITIAL_CAT

private val navArgs by navArgs<SingleCharacterFragmentArgs>()

Expand All @@ -46,9 +46,9 @@ class SingleCharacterFragment :

override fun onReady(savedInstanceState: Bundle?) {
binding.spinnerCat.onItemSelectedListener = this
collectCategories()
setupMenu()
parseParams()
collectCategories()
}

private fun parseParams() {
Expand All @@ -70,7 +70,7 @@ class SingleCharacterFragment :
val newCat = it.toString().trim()
if (newCat != "") {
viewModel.addNewCategory(newCat)
selectedCategory = newCat
addCharacter(newCat)
}
}
binding.newCatGroup.isVisible = false
Expand All @@ -85,8 +85,7 @@ class SingleCharacterFragment :
etPinyin.setText(it.pinyin)
etTranslation.setText(it.translation)
etUsages.setText(it.usages)
selectedCategory = it.category
//todo: проблема: перестал выставлять нужную категорию!
setSpinnerSelection(it.category)
tvBigCharacter.text = it.character
tvBigCharacter.animate().apply {
translationX(70f)
Expand All @@ -96,6 +95,8 @@ class SingleCharacterFragment :
}
}
}


}
}
}
Expand All @@ -108,8 +109,8 @@ class SingleCharacterFragment :
binding.etCategory.text?.let {
val newCat = it.toString().trim()
if (newCat != "") {
newCategory = newCat
viewModel.addNewCategory(newCat)
selectedCategory = newCat
}
}
binding.newCatGroup.isVisible = false
Expand Down Expand Up @@ -153,7 +154,9 @@ class SingleCharacterFragment :
viewModel
)
binding.spinnerCat.adapter = adapterForSpinner
setSpinnerSelection(selectedCategory)
if (newCategory!=INITIAL_CAT) {
setSpinnerSelection(newCategory)
}
}
}
}
Expand Down Expand Up @@ -189,6 +192,7 @@ class SingleCharacterFragment :
const val MODE_ADD = "add"
const val NEW_CHAR_ID = 0
private const val MIN_LENGTH = 1
private const val INITIAL_CAT = ""
}
}

0 comments on commit 19acd2f

Please sign in to comment.