Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,17 @@ enum class Destinations(override val destinationName: String) : DestinationDefin
TERMS_AND_CONDITIONS_INITIAL("terms-and-conditions-initial")
}

// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class MainNavController(
private val viewModelCreator: () -> MainNavControllerViewModel,
private val plannerScreen: PlannerScreen,
private val diveConfigurationScreen: DiveConfigurationScreen,
private val settingsScreen: SettingsScreen,
private val termsAndConditionsScreen: TermsAndConditionsScreen,
private val aboutScreen: AboutScreen,
) {
@Composable
operator fun invoke() {
MainNavController(
viewModel = viewModel { viewModelCreator() },
plannerScreen = plannerScreen,
diveConfigurationScreen = diveConfigurationScreen,
settingsScreen = settingsScreen,
termsAndConditionsScreen = termsAndConditionsScreen,
aboutScreen = aboutScreen,
)
}
}

@Composable
fun MainNavController(
viewModel: MainNavControllerViewModel,
viewModelCreator: () -> MainNavControllerViewModel,
plannerScreen: PlannerScreen,
diveConfigurationScreen: DiveConfigurationScreen,
settingsScreen: SettingsScreen,
termsAndConditionsScreen: TermsAndConditionsScreen,
aboutScreen: AboutScreen,
) {
val viewModel = viewModel { viewModelCreator() }

val startDestination = when (viewModel.settings.value.termsAndConditionsAccepted) {
false -> Destinations.TERMS_AND_CONDITIONS_INITIAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import dev.zacsweers.metro.Assisted
import dev.zacsweers.metro.Inject
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
Expand Down Expand Up @@ -67,29 +68,12 @@ import kotlin.math.abs
import kotlin.math.roundToInt


// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class DiveConfigurationScreen(
private val planningRepository: PlanningRepository,
private val settingsRepository: SettingsRepository,
) {
@Composable
operator fun invoke(navController: NavHostController) {
DiveConfigurationScreen(
navController = navController,
planningRepository = planningRepository,
settingsRepository = settingsRepository,
)
}
}

@Composable
fun DiveConfigurationScreen(
navController: NavHostController,
planningRepository: PlanningRepository,
settingsRepository: SettingsRepository,
@Assisted navController: NavHostController,
) {
// TODO should be adding a ViewModel to this screen
val configuration by planningRepository.configuration.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import kotlinx.collections.immutable.toImmutableList
import org.neotech.app.abysner.domain.core.model.UnitSystem
import dev.zacsweers.metro.Assisted
import dev.zacsweers.metro.Inject
import org.neotech.app.abysner.domain.settings.SettingsRepository
import org.neotech.app.abysner.domain.settings.model.SettingsModel
Expand All @@ -48,26 +49,11 @@ import org.neotech.app.abysner.presentation.component.preferences.SingleChoicePr
import org.neotech.app.abysner.presentation.component.preferences.SwitchPreference
import org.neotech.app.abysner.presentation.theme.AbysnerTheme

// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class SettingsScreen(
private val settingsRepository: SettingsRepository,
) {
@Composable
operator fun invoke(navController: NavHostController) {
SettingsScreen(
navController = navController,
settingsRepository = settingsRepository
)
}
}

@Composable
private fun SettingsScreen(
navController: NavHostController,
fun SettingsScreen(
settingsRepository: SettingsRepository,
@Assisted navController: NavHostController,
) {
// TODO should be adding a ViewModel to this screen
val settings by settingsRepository.settings.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,17 @@ import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import dev.zacsweers.metro.Assisted
import dev.zacsweers.metro.Inject
import org.jetbrains.compose.resources.painterResource
import org.neotech.app.abysner.presentation.Destinations
import org.neotech.app.abysner.presentation.theme.AbysnerTheme
import org.neotech.app.abysner.version.VersionInfo

// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class AboutScreen {

@Composable
operator fun invoke(navController: NavHostController) {
AboutScreen(navController = navController)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutScreen(navController: NavHostController = rememberNavController()) {
fun AboutScreen(@Assisted navController: NavHostController = rememberNavController()) {
val uriHandler = LocalUriHandler.current

AbysnerTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import kotlinx.collections.immutable.toImmutableList
import dev.zacsweers.metro.Assisted
import dev.zacsweers.metro.Inject
import org.neotech.app.abysner.domain.core.model.Cylinder
import org.neotech.app.abysner.domain.core.model.DiveMode
Expand All @@ -76,27 +77,14 @@ import org.neotech.app.abysner.presentation.preview.DEVICE_PHONE_MAX_HEIGHT
import org.neotech.app.abysner.presentation.preview.PreviewData
import kotlin.time.Duration

// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class PlannerScreen(
private val viewModelCreator: () -> PlanScreenViewModel,
) {
@Composable
operator fun invoke(navController: NavHostController) {
PlannerScreen(
viewModel = viewModel { viewModelCreator() },
navController = navController,
)
}
}

@Inject
@Composable
private fun PlannerScreen(
viewModel: PlanScreenViewModel,
navController: NavHostController
fun PlannerScreen(
viewModelCreator: () -> PlanScreenViewModel,
@Assisted navController: NavHostController,
) {
val viewModel = viewModel { viewModelCreator() }
val uiState: PlanScreenViewModel.UiState by viewModel.uiState.collectAsState()

PlannerScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.mikepenz.markdown.compose.Markdown
import com.mikepenz.markdown.m3.markdownColor
import com.mikepenz.markdown.m3.markdownTypography
import com.mikepenz.markdown.model.markdownPadding
import dev.zacsweers.metro.Assisted
import dev.zacsweers.metro.Inject
import kotlinx.coroutines.runBlocking
import org.jetbrains.compose.resources.ExperimentalResourceApi
Expand All @@ -64,27 +65,13 @@ import org.neotech.app.abysner.presentation.utilities.EventEffect
import org.neotech.app.abysner.presentation.utilities.closeApp
import org.neotech.app.abysner.presentation.utilities.consumed

// Metro supports @Inject on top-level functions, but the generated types are not resolved by the
// IDE, causing "Unresolved reference" errors. This wrapper class avoids those IDE errors.
// See: https://zacsweers.github.io/metro/latest/installation/#ide-support
@Inject
class TermsAndConditionsScreen(
private val viewModelCreator: () -> TermsAndConditionsViewModel,
) {
@Composable
operator fun invoke(navController: NavHostController = rememberNavController()) {
TermsAndConditionsScreen(
navController = navController,
viewModel = viewModel { viewModelCreator() }
)
}
}

@Composable
private fun TermsAndConditionsScreen(
navController: NavHostController,
viewModel: TermsAndConditionsViewModel
fun TermsAndConditionsScreen(
viewModelCreator: () -> TermsAndConditionsViewModel,
@Assisted navController: NavHostController = rememberNavController(),
) {
val viewModel = viewModel { viewModelCreator() }
val uiState: UiState = viewModel.uiState.collectAsState().value
TermsAndConditionsScreen(
navController = navController,
Expand Down
Loading