Skip to content

Commit

Permalink
#17 in progress - coping assets when main screen is being presented
Browse files Browse the repository at this point in the history
  • Loading branch information
mjureczko committed Sep 26, 2024
1 parent 4bd1479 commit 76c73c0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "pl.marianjureczko.poszukiwacz"
minSdkVersion 23
targetSdkVersion 34
versionCode 8
versionName "0.8"
versionCode 9
versionName "0.9"
testInstrumentationRunner "pl.marianjureczko.poszukiwacz.CustomTestRunner"
manifestPlaceholders = [facebookToken: FACEBOOK_TOKEN]
javaCompileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowForward
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
Expand Down Expand Up @@ -45,6 +46,9 @@ const val START_BUTTON = "Start button"
fun MainScreenBody(goToSearching: GoToSearching) {
val viewModel: MainViewModel = hiltViewModel()
val state = viewModel.state.value
LaunchedEffect(key1 = "on start"){
viewModel.initializeAssets()
}
Column(Modifier.background(colorResource(R.color.colorBackgroundVariant))) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -93,7 +97,7 @@ fun MainScreenBody(goToSearching: GoToSearching) {
modifier = Modifier
.weight(0.01f)
)
LargeButton(R.string.custom_lets_start, START_BUTTON) {
LargeButton(R.string.custom_lets_start, START_BUTTON, enabled = state.assetsCopied) {
viewModel.restartMessages()
goToSearching.invoke(CustomInitializerForRoute.routeName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import pl.marianjureczko.poszukiwacz.R

data class MainState(
private val resources: Resources,
var messageIndex: Int = 0,
val messageIndex: Int = 0,
val assetsCopied: Boolean = false,
val messages : List<Message> = listOf(
Message(resources.getString(R.string.custom_lead1), R.drawable.al),
Message(resources.getString(R.string.custom_lead2), R.drawable.kalinowice_wita),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(
resources: Resources,
val dispatcher: CoroutineDispatcher,
customInitializerForRoute: CustomInitializerForRoute
private val dispatcher: CoroutineDispatcher,
private val customInitializerForRoute: CustomInitializerForRoute
) : ViewModel() {
private var _state = mutableStateOf(MainState(resources))

init {
val state: State<MainState>
get() = _state

fun initializeAssets() {
viewModelScope.launch(dispatcher) {
customInitializerForRoute.copyRouteToLocalStorage()
_state.value = _state.value.copy(assetsCopied = true)
}
}

val state: State<MainState>
get() = _state

fun nextLeadMessage() {
if (_state.value.messageIndex + 1 < _state.value.messages.size) {
_state.value = _state.value.copy(messageIndex = _state.value.messageIndex + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@ import androidx.compose.ui.unit.dp
import pl.marianjureczko.poszukiwacz.ui.theme.Shapes

@Composable
fun LargeButton(title: Int, description: String = "", onClick: () -> Unit) {
fun LargeButton(title: Int, description: String = "", enabled: Boolean = true, onClick: () -> Unit) {
val contentColor = if (enabled) {
Color.Black
} else {
Color.Gray
}
OutlinedButton(
enabled = enabled,
shape = Shapes.large,
modifier = Modifier.fillMaxWidth().semantics { contentDescription = description },
modifier = Modifier
.fillMaxWidth()
.semantics { contentDescription = description },
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.White,
contentColor = Color.Black
contentColor = contentColor
),
border = BorderStroke(2.dp, Color.LightGray),
elevation = ButtonDefaults.elevation(4.dp),
onClick = onClick
) {
Text(
stringResource(title),
color = Color.Black
color = contentColor
)
}
}

0 comments on commit 76c73c0

Please sign in to comment.