Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workshop improvements #63

Merged
merged 12 commits into from
Oct 11, 2024
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
composeWheelPicker = "1.0.0-beta05"
leakcanaryAndroid = "2.14"
modo = "0.10.0-alpha3"
modo = "0.10.0"
androidGradlePlugin = "8.4.0"
detektComposeVersion = "0.3.20"
detektVersion = "1.23.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ val rootModule = module {
viewModel { EnhancedProfileViewModel(get()) }
viewModel { EnhancedProfileViewModelFinal(it.get(), get()) }
viewModel { ClimberPersonalInfoViewModel(get()) }
// TODO: Workshop 5.1.2 - di define ProfileSetupViewModel
// TODO: Workshop 5.1.1 - di define ProfileSetupViewModel
// viewModel { ProfileSetupFlowViewModel(get()) }
// TODO: Workshop 5.1.4 - di pass arguments to ProfileSetupViewModel
// viewModel { ProfileSetupFlowViewModel(it.get(), it.get(), get()) }
viewModel { ProfileSetupFlowViewModelFinal(it.get(), it.get(), it.get(), get()) }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
package io.github.ikarenkov.workshop.screens.main

import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Face
import androidx.compose.material.icons.sharp.Home
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

// TODO: Workshop 3.1.1 - create main tab screen inheriting from MultiScreen
// TODO: Workshop 3.1.2 - define initial state in constructor and pass it as argument tu super
// TODO: Workshop 3.1.3 - use @Parcelize annotation to make MainTabScreen class Parcelable
Expand All @@ -8,4 +31,69 @@ package io.github.ikarenkov.workshop.screens.main
// TODO: Workshop 3.2.2 - display selected screen inside MainTabContent using SelectedScreen composable
// TODO: Workshop 3.3 - navigate between tabs using selectContainer function
// TODO: Workshop 3.4 - use navigation state to access selected tab position
// TODO: Workshop 3.5 - support animation using build-in SlideTransition
// TODO: Workshop 3.5 - support animation using build-in SlideTransition

@Composable
fun MainTabContent(
selectedTabPos: Int,
onTabClick: (Int) -> Unit,
modifier: Modifier = Modifier,
content: @Composable (PaddingValues) -> Unit,
) {
Scaffold(
modifier = modifier,
bottomBar = {
BottomAppBar {
for ((pos, tab) in MainTabs.entries.withIndex()) {
IconButton(
modifier = Modifier.weight(1f),
onClick = {
onTabClick(pos)
},
) {
val contentColor = LocalContentColor.current
val color by animateColorAsState(
contentColor.copy(
alpha = if (pos == selectedTabPos) contentColor.alpha else 0.5f
)
)
Icon(
rememberVectorPainter(tab.icon),
tint = color,
contentDescription = tab.title
)
}
}
}
}
) { paddingValues ->
content(paddingValues)
}
}

enum class MainTabs(
val icon: ImageVector,
val title: String
) {
HOME(Icons.Sharp.Home, "Home"),
PROFILE(Icons.Default.Face, "Profile")
}

@Preview
@Composable
private fun PreviewMainTabsContent() {
MainTabContent(
selectedTabPos = 0,
onTabClick = {},
modifier = Modifier.fillMaxSize()
) { paddingValues ->
Box(
Modifier
.fillMaxSize()
.padding(paddingValues),
contentAlignment = Alignment.Center
) {
Text("Selected screen", Modifier.padding(16.dp))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberDatePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand All @@ -30,13 +29,12 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.github.terrakok.modo.ScreenKey
import com.github.terrakok.modo.generateScreenKey
import io.github.ikarenkov.workshop.screens.profile_setup.SetupStepScreen
import io.github.ikarenkov.workshop.ui.InputNumRow
import io.github.ikarenkov.workshop.ui.TitleCell
import io.github.ikarenkov.workshop.utils.OnLifecycleEvent
import kotlinx.parcelize.Parcelize
import org.koin.androidx.compose.koinViewModel
import java.util.Date
Expand All @@ -55,18 +53,16 @@ class ClimberPersonalInfoScreen(
val viewModel = koinViewModel<ClimberPersonalInfoViewModel>()
val state by viewModel.state.collectAsState()
val focusRequester = remember { FocusRequester() }
val lifecycleOwner = LocalLifecycleOwner.current
// TODO: Workshop 6.1 - use ON_RESUME and ON_PAUSE events to show and hide the keyboard
// TODO: Workshop 6.1.1 - get keyboard controller
// val keyboardController = LocalSoftwareKeyboardController.current
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
// TODO: Workshop 6.1 - use ON_RESUME and ON_PAUSE events to show and hide the keyboard
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
OnLifecycleEvent(
onResume = {
// TODO: Workshop 6.1.2 - show the keyboard
},
onPause = {
// TODO: Workshop 6.1.3 - hide the keyboard
}
}
)
ClimberProfileSetupScreenContent(
modifier = modifier,
heightTextFieldModifier = Modifier.focusRequester(focusRequester),
Expand Down

This file was deleted.

Loading