Skip to content

Commit

Permalink
Improve description for tag deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Faltenreich committed Jan 6, 2024
1 parent b468931 commit d87262f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ fun TagDeleteDialog(
Text(getString(MR.strings.cancel))
}
},

title = { Text(getString(MR.strings.tag_delete)) },
text = {
when (state) {
null -> Unit
else -> Text(getString(MR.strings.tag_delete_description, state.entryCount))
else -> Text(
getString(
MR.strings.tag_delete_description,
state.entryCount,
state.tag.name,
)
)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.faltenreich.diaguard.tag.delete

import com.faltenreich.diaguard.tag.Tag

data class TagDeleteState(
val tag: Tag,
val entryCount: Long,
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.faltenreich.diaguard.tag.delete

import com.faltenreich.diaguard.navigation.CloseModalUseCase
import com.faltenreich.diaguard.navigation.NavigateToScreenUseCase
import com.faltenreich.diaguard.navigation.screen.EntrySearchScreen
import com.faltenreich.diaguard.shared.architecture.ViewModel
import com.faltenreich.diaguard.shared.di.inject
import com.faltenreich.diaguard.tag.Tag
import com.faltenreich.diaguard.tag.list.DeleteTagUseCase
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOf

class TagDeleteViewModel(
private val tag: Tag,
countEntriesForTag: CountEntriesByTagUseCase = inject(),
private val closeModal: CloseModalUseCase = inject(),
private val navigateToScreen: NavigateToScreenUseCase = inject(),
private val deleteTag: DeleteTagUseCase = inject(),
) : ViewModel<TagDeleteState, TagDeleteIntent>() {

override val state: Flow<TagDeleteState> = countEntriesForTag(tag).map(::TagDeleteState)
override val state: Flow<TagDeleteState> = combine(
flowOf(tag),
countEntriesForTag(tag),
::TagDeleteState,
)

override fun onIntent(intent: TagDeleteIntent) {
when (intent) {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<string name="tags">Tags</string>
<string name="tag_already_taken">Tag is already taken</string>
<string name="tag_delete">Delete tag</string>
<string name="tag_delete_description">%d entries will lose this tag</string>
<string name="tag_delete_description">%d entries will lose the tag "%s"</string>
<string name="tag_new">Create new tag</string>
<string name="terms_and_conditions">Terms and conditions</string>
<string name="terms_and_conditions_url">https://github.com/Faltenreich/Diaguard/tree/master/resource/legal/terms/TERMS_AND_CONDITIONS_EN.md</string>
Expand Down

0 comments on commit d87262f

Please sign in to comment.