-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from sh1mj1/ui/deck-list
UI/deck list add DeckItem, and refactor separating DeckItemDetail composeable
- Loading branch information
Showing
9 changed files
with
255 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/androidTest/java/tcg/pocket/dex/tierdecks/DeckListKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tcg.pocket.dex.tierdecks | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onAllNodesWithContentDescription | ||
import androidx.compose.ui.test.onFirst | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.performClick | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class DeckListKtTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val sampleDeckItemsState = | ||
fakeDecksInformation.map { | ||
DeckItemState(it) | ||
} | ||
|
||
@Test | ||
fun deckList_expandItem() { | ||
composeTestRule.setContent { | ||
DeckList( | ||
deckItemsState = sampleDeckItemsState, | ||
onExpandDeck = { itemState, expanded -> itemState.toggleExpanded() }, | ||
onDeckItemClick = {}, | ||
) | ||
} | ||
|
||
composeTestRule.onAllNodesWithContentDescription("not expanded icon").onFirst().performClick() | ||
|
||
composeTestRule.onNodeWithContentDescription("expanded icon").assertIsDisplayed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/tcg/pocket/dex/tierdecks/DeckInformation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package tcg.pocket.dex.tierdecks | ||
|
||
data class DeckInformation( | ||
val simple: DeckSimpleInformation, | ||
val detail: DeckDetailInformation, | ||
) | ||
|
||
data class DeckSimpleInformation( | ||
val deckId: String, | ||
val representativePokemonImageUrls: List<String>, | ||
val rank: Int, | ||
val deckName: String, | ||
val winRate: String, | ||
val share: String, | ||
) | ||
|
||
data class DeckDetailInformation( | ||
val cost: Int, | ||
val pokemonTypes: List<PokemonTypeChipData>, | ||
val description: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/tcg/pocket/dex/tierdecks/DeckItemState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package tcg.pocket.dex.tierdecks | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
|
||
class DeckItemState( | ||
val content: DeckInformation, | ||
initialExpanded: Boolean = false, | ||
) { | ||
var expanded: Boolean by mutableStateOf(initialExpanded) | ||
private set | ||
|
||
fun toggleExpanded() { | ||
expanded = !expanded | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package tcg.pocket.dex.tierdecks | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import tcg.pocket.dex.ui.theme.TcgPocketDexTheme | ||
|
||
@Composable | ||
fun DeckList( | ||
deckItemsState: List<DeckItemState>, | ||
onExpandDeck: (DeckItemState, Boolean) -> Unit, | ||
onDeckItemClick: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
LazyColumn( | ||
modifier = | ||
modifier | ||
.fillMaxWidth() | ||
.padding(8.dp), | ||
) { | ||
items( | ||
items = deckItemsState, | ||
key = { deckItem -> deckItem.content.simple.deckId }, | ||
) { deckItemState -> | ||
|
||
DeckItem( | ||
information = deckItemState.content, | ||
expanded = deckItemState.expanded, | ||
onExpandedChange = { expanded -> onExpandDeck(deckItemState, expanded) }, | ||
onCardClick = onDeckItemClick, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun DeckListPreview() { | ||
TcgPocketDexTheme { | ||
DeckList( | ||
deckItemsState = fakeDecksInformation.map(::DeckItemState), | ||
onDeckItemClick = { }, | ||
onExpandDeck = { deckItemStata, _ -> }, | ||
) | ||
} | ||
} |
Oops, something went wrong.