Skip to content

Commit

Permalink
Merge pull request #3108 from CruGlobal/toolModelCleanup
Browse files Browse the repository at this point in the history
GT-1796 Rename Tool.isAdded to Tool.isFavorite
  • Loading branch information
frett authored Sep 19, 2023
2 parents 926a1a6 + 9f8a06a commit c461929
Show file tree
Hide file tree
Showing 19 changed files with 1,433 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,22 @@ internal fun ToolDetailsActions(
) { Text(stringResource(R.string.action_tools_open_training)) }
}

val isAdded by remember { derivedStateOf { tool?.isAdded == true } }
val isFavorite by remember { derivedStateOf { tool?.isFavorite == true } }
OutlinedButton(
onClick = { if (isAdded) toolViewModel.unpinTool() else toolViewModel.pinTool() },
onClick = { if (isFavorite) toolViewModel.unpinTool() else toolViewModel.pinTool() },
colors = ButtonDefaults.outlinedButtonColors(
contentColor = if (isAdded) GodToolsTheme.GT_RED else MaterialTheme.colorScheme.primary
contentColor = if (isFavorite) GodToolsTheme.GT_RED else MaterialTheme.colorScheme.primary
),
modifier = Modifier.fillMaxWidth()
) {
Icon(
painterResource(if (isAdded) R.drawable.ic_favorite_border_24dp else R.drawable.ic_favorite_24dp),
painterResource(if (isFavorite) R.drawable.ic_favorite_border_24dp else R.drawable.ic_favorite_24dp),
contentDescription = null
)
Text(
stringResource(if (isAdded) R.string.action_tools_remove_favorite else R.string.action_tools_add_favorite),
stringResource(
if (isFavorite) R.string.action_tools_remove_favorite else R.string.action_tools_add_favorite
),
modifier = Modifier.padding(start = 4.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ internal fun FavoriteAction(
confirmRemoval: Boolean = true
) {
val tool by viewModel.tool.collectAsState()
val isAdded by remember { derivedStateOf { tool?.isAdded == true } }
val isFavorite by remember { derivedStateOf { tool?.isFavorite == true } }
var showRemovalConfirmation by rememberSaveable { mutableStateOf(false) }

Surface(
onClick = {
when {
!isAdded -> viewModel.pinTool()
!isFavorite -> viewModel.pinTool()
confirmRemoval -> showRemovalConfirmation = true
else -> viewModel.unpinTool()
}
Expand All @@ -47,7 +47,9 @@ internal fun FavoriteAction(
modifier = modifier
) {
Icon(
painter = painterResource(if (isAdded) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp),
painter = painterResource(
if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp
),
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FavoriteActionTest {
@Test
fun `FavoriteAction() - add to favorites`() {
composeTestRule.setContent { FavoriteAction(toolViewModel) }
toolFlow.value = Tool().apply { isAdded = false }
toolFlow.value = Tool().apply { isFavorite = false }

composeTestRule.onRoot().performClick()
verifyAll { toolViewModel.pinTool() }
Expand All @@ -59,7 +59,7 @@ class FavoriteActionTest {
@Test
fun `FavoriteAction() - remove from favorites`() {
composeTestRule.setContent { FavoriteAction(toolViewModel, confirmRemoval = false) }
toolFlow.value = Tool().apply { isAdded = true }
toolFlow.value = Tool().apply { isFavorite = true }

composeTestRule.onRoot().performClick()
composeTestRule.onNode(isDialog()).assertDoesNotExist()
Expand All @@ -69,7 +69,7 @@ class FavoriteActionTest {
@Test
fun `FavoriteAction() - remove from favorites - confirmRemoval - confirm`() {
composeTestRule.setContent { FavoriteAction(toolViewModel, confirmRemoval = true) }
toolFlow.value = Tool().apply { isAdded = true }
toolFlow.value = Tool().apply { isFavorite = true }

composeTestRule.onRoot().performClick()
composeTestRule.onNode(isDialog()).assertIsDisplayed()
Expand All @@ -83,7 +83,7 @@ class FavoriteActionTest {
@Test
fun `FavoriteAction() - remove from favorites - confirmRemoval - cancel`() {
composeTestRule.setContent { FavoriteAction(toolViewModel, confirmRemoval = true) }
toolFlow.value = Tool().apply { isAdded = true }
toolFlow.value = Tool().apply { isFavorite = true }

composeTestRule.onRoot().performClick()
composeTestRule.onNode(isDialog()).assertIsDisplayed()
Expand Down
Loading

0 comments on commit c461929

Please sign in to comment.