Skip to content

Commit

Permalink
build structure
Browse files Browse the repository at this point in the history
  • Loading branch information
klokidis committed May 1, 2024
1 parent 6893f73 commit 62cfddd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.charactersheet.data.Datasource
import com.example.charactersheet.ui.ArtistList
import com.example.charactersheet.ui.CharacterViewModel

enum class CharacterScreen(@StringRes var title: Int) {
Start(title = R.string.app_name)
Start(title = R.string.app_name),
Artist(title = R.string.app_name),
}

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -85,7 +85,17 @@ fun CharacterSheetApp(
modifier = Modifier.padding(innerPadding)
){
composable(route = CharacterScreen.Start.name) {
ArtistList(Datasource().loadArtists())
ArtistList(
onButtonCard = {
CharacterScreen.Artist.title = it.stringResourceId
viewModel.selectedArtist(it)
navController.navigate(CharacterScreen.Artist.name)
},
uiState.listOfArtists,
)
}
composable(route = CharacterScreen.Artist.name) {

}
}
}
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/example/charactersheet/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.example.charactersheet.ui.theme.CharacterSheetTheme

private const val TAG = "com.example.charactersheet.MainActivity"
Expand All @@ -12,8 +14,7 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
CharacterSheetTheme {
// A surface container using the 'background' color from the theme
CharacterSheetApp()
CharacterSheetApp()
}
}
}
Expand Down Expand Up @@ -46,3 +47,11 @@ class MainActivity : ComponentActivity() {
Log.d(TAG, "onDestroy Called")
}
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
CharacterSheetTheme {
CharacterSheetApp()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import androidx.annotation.StringRes

data class Character(
@StringRes val stringResourceId: Int,
@DrawableRes val imageResourceId: Int
@DrawableRes val imageResourceId: Int,
@StringRes val artist: Int,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.charactersheet.ui

import androidx.lifecycle.ViewModel
import com.example.charactersheet.model.Artist
import com.example.charactersheet.ui.UiState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class CharacterViewModel : ViewModel(){
private val _uiState = MutableStateFlow(UiState())
Expand All @@ -13,4 +15,13 @@ class CharacterViewModel : ViewModel(){
init {

}

fun selectedArtist(artist: Artist){
_uiState.update { currentState ->
currentState.copy(
artistChosen = artist,
listOfCharacters = _uiState.value.listOfCharacters.filter { it.artist == artist.stringResourceId }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import com.example.charactersheet.data.Datasource
import com.example.charactersheet.model.Artist

@Composable
fun ArtistList(artistList: List<Artist>, modifier: Modifier = Modifier) {
fun ArtistList(
onButtonCard: (Artist) -> Unit,
artistList: List<Artist>,
modifier: Modifier = Modifier
) {
LazyColumn {
items(artistList) { artist ->
ArtistCard(
Expand All @@ -55,7 +59,7 @@ fun ArtistCard(artist: Artist, modifier: Modifier = Modifier) {
.clickable {
},
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surface,
containerColor = MaterialTheme.colorScheme.inverseOnSurface,
),
elevation = CardDefaults.cardElevation(
defaultElevation = dimensionResource(R.dimen.elevation_image),
Expand Down Expand Up @@ -88,6 +92,6 @@ fun ArtistCard(artist: Artist, modifier: Modifier = Modifier) {
@Composable
fun GreetingPreview() {
CharacterSheetTheme {
ArtistList(Datasource().loadArtists())
ArtistList({},Datasource().loadArtists())
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/example/charactersheet/ui/UiState.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package com.example.charactersheet.ui

import androidx.annotation.StringRes
import com.example.charactersheet.data.Datasource
import com.example.charactersheet.model.Artist
import com.example.charactersheet.model.Character

data class UiState(
@StringRes
val titleBar: Int = 0,

val artistChosen : Artist = Artist(0,0),
val characterChosen : Character = Character(0,0,0),

val listOfCharacters: List<Character> = listOf(Character(0, 0,0)),
val listOfArtists: List<Artist> = Datasource().loadArtists(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val md_theme_light_secondary = Color(0xFF1A60A5)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFD4E3FF)
val md_theme_light_onSecondaryContainer = Color(0xFF001C39)
val md_theme_light_tertiary = Color(0xFF00639C)
val md_theme_light_tertiary = Color(0xFFC3E0FF)
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFFCEE5FF)
val md_theme_light_onTertiaryContainer = Color(0xFF001D33)
Expand All @@ -24,7 +24,7 @@ val md_theme_light_onSurface = Color(0xFF1A1C1E)
val md_theme_light_surfaceVariant = Color(0xFFDFE2EB)
val md_theme_light_onSurfaceVariant = Color(0xFF43474E)
val md_theme_light_outline = Color(0xFF73777F)
val md_theme_light_inverseOnSurface = Color(0xFFF1F0F4)
val md_theme_light_inverseOnSurface = Color(0xFFEBF1FE)
val md_theme_light_inverseSurface = Color(0xFF2F3033)
val md_theme_light_inversePrimary = Color(0xFFA3C9FF)
val md_theme_light_shadow = Color(0xFF000000)
Expand Down Expand Up @@ -55,7 +55,7 @@ val md_theme_dark_onSurface = Color(0xFFE3E2E6)
val md_theme_dark_surfaceVariant = Color(0xFF43474E)
val md_theme_dark_onSurfaceVariant = Color(0xFFC3C6CF)
val md_theme_dark_outline = Color(0xFF8D9199)
val md_theme_dark_inverseOnSurface = Color(0xFF1A1C1E)
val md_theme_dark_inverseOnSurface = Color(0xFF35414B)
val md_theme_dark_inverseSurface = Color(0xFFE3E2E6)
val md_theme_dark_inversePrimary = Color(0xFF1760A5)
val md_theme_dark_shadow = Color(0xFF000000)
Expand Down

0 comments on commit 62cfddd

Please sign in to comment.