Fix tab name update

This commit is contained in:
Fred 2024-08-30 13:21:52 +02:00
parent 9d46baef90
commit 2a80d7548d
2 changed files with 14 additions and 1 deletions

View File

@ -120,7 +120,7 @@ class ArrangeTabsFragment: DialogFragment() {
fun callbackOnClickListener(tabNew: Tab, isCheckedNew: Boolean, hashtag: String? = null) {
tabNew.filter = hashtag?.split("#")?.filter { it.isNotBlank() }?.get(0)?.trim()
model.tabsCheckReplace(position, Pair(tabNew, isCheckedNew))
checkBox.isChecked = isCheckedNew
checkBox.isChecked = model.uiState.value.tabsChecked[position].second
val hashtagWithHashtag = tabNew.filter?.let {
StringBuilder("#").append(it).toString()
@ -176,6 +176,7 @@ class ArrangeTabsFragment: DialogFragment() {
fun onItemMove(from: Int, to: Int) {
val previous = model.tabsCheckedRemove(from)
model.tabsCheckedAdd(to, previous)
model.swapTabsButtons(from, to)
notifyItemMoved(from, to)
notifyItemChanged(to) // necessary to avoid checkBox issues
}

View File

@ -118,6 +118,18 @@ class ArrangeTabsViewModel @Inject constructor(
fun getTabsButtons(position: Int): String? {
return _uiState.value.tabsButtons[position]
}
fun swapTabsButtons(from: Int, to: Int) {
oldTabsButtons = _uiState.value.tabsButtons.toMutableList()
val fromText = oldTabsButtons[from]
oldTabsButtons[from] = oldTabsButtons[to]
oldTabsButtons[to] = fromText
_uiState.update { currentUiState ->
currentUiState.copy(
tabsButtons = oldTabsButtons.toList()
)
}
}
}
data class ArrangeTabsUiState(