Skip to content

Commit

Permalink
🚧 Bottom Sheet webview is now in used for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
schachi5000 committed Jun 4, 2024
1 parent bb62568 commit 826f3ca
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 98 deletions.
2 changes: 1 addition & 1 deletion iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ContentView: View {
.onOpenURL(perform: { url in
if(loginBridge.isCallbackUrl(url: url.absoluteString)){
showingSheet = false
loginBridge.onLoginSuccessful(callbackUrl: url.absoluteString)
loginBridge.handleCallbackUrl(callbackUrl: url.absoluteString)
}
})
.edgesIgnoringSafeArea(.all)
Expand Down
5 changes: 2 additions & 3 deletions shared/src/androidMain/kotlin/main.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.koin.android.ext.koin.androidContext
@Composable
fun MainView() {
val context = LocalContext.current
App(DatabaseDao(DatabaseDriverFactory(LocalContext.current)), {}) {
androidContext(context)
}
App(databaseDao = DatabaseDao(DatabaseDriverFactory(LocalContext.current)),
onKoinStart = { androidContext(context) })
}
49 changes: 30 additions & 19 deletions shared/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import net.schacher.mcc.shared.repositories.DeckRepository
import net.schacher.mcc.shared.repositories.PackRepository
import net.schacher.mcc.shared.screens.app.AppScreen
import net.schacher.mcc.shared.screens.app.AppViewModel
import net.schacher.mcc.shared.screens.login.LoginScreenViewModel
import net.schacher.mcc.shared.screens.main.MainViewModel
import net.schacher.mcc.shared.screens.mydecks.MyDecksViewModel
import net.schacher.mcc.shared.screens.newdeck.NewDeckViewModel
Expand All @@ -40,7 +39,6 @@ val repositories = module {

val viewModels = module {
singleOf(::AppViewModel)
singleOf(::LoginScreenViewModel)
singleOf(::MainViewModel)
singleOf(::MyDecksViewModel)
singleOf(::NewDeckViewModel)
Expand All @@ -53,31 +51,44 @@ val viewModels = module {
@Composable
fun App(
databaseDao: DatabaseDao,
onLoginClicked: (LoginBridge) -> Unit = {},
onLoginClicked: ((LoginBridge) -> Unit)? = null,
onKoinStart: KoinApplication.() -> Unit = {}
) {
val authHandler = AuthRepository(databaseDao as SettingsDao)
KoinApplication(application = {
onKoinStart()
modules(platformModule, module {
single<CardDatabaseDao> { databaseDao }
single<DeckDatabaseDao> { databaseDao }
single<PackDatabaseDao> { databaseDao }
single<SettingsDao> { databaseDao }
}, module {
single<AuthRepository> { authHandler }
}, network, repositories, viewModels
modules(
platformModule,
module {
single<CardDatabaseDao> { databaseDao }
single<DeckDatabaseDao> { databaseDao }
single<PackDatabaseDao> { databaseDao }
single<SettingsDao> { databaseDao }
},
module {
single<AuthRepository> { authHandler }
},
network,
repositories,
viewModels
)
}) {
MccTheme {
AppScreen(onLogInClicked = {
onLoginClicked(object : LoginBridge {
override val url: String = BuildConfig.OAUTH_URL
override fun onLoginSuccessful(callbackUrl: String) {
authHandler.handleCallbackUrl(callbackUrl)
AppScreen(
onLogInClicked = if (onLoginClicked != null) {
{
onLoginClicked.invoke(
object : LoginBridge {
override val url: String = BuildConfig.OAUTH_URL
override fun handleCallbackUrl(callbackUrl: String) {
authHandler.handleCallbackUrl(callbackUrl)
}
})
}
})
})
} else {
null
}
)
}
}
}
Expand All @@ -90,7 +101,7 @@ interface LoginBridge {

val url: String

fun onLoginSuccessful(callbackUrl: String)
fun handleCallbackUrl(callbackUrl: String)

fun isCallbackUrl(url: String): Boolean = url.startsWith("mccapp://callback")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private const val LOG_OUT_MILLIS = 450
@Composable
fun AppScreen(
appViewModel: AppViewModel = koinInject(),
onLogInClicked: () -> Unit = {}
onLogInClicked: (() -> Unit)? = null
) {
val loggedIn = appViewModel.state.collectAsState()

Expand All @@ -42,9 +42,9 @@ fun AppScreen(
if (it) {
MainScreen()
} else {
LoginScreen(onLogInClicked = onLogInClicked) {
appViewModel.onGuestLoginClicked()
}
LoginScreen(
onLogInClicked = onLogInClicked,
onGuestLogin = { appViewModel.onGuestLoginClicked() })
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.compose.material.icons.filled.Close
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -61,22 +60,21 @@ import net.schacher.mcc.shared.design.compose.BackHandler
import net.schacher.mcc.shared.design.compose.ConfirmationDialog
import net.schacher.mcc.shared.design.theme.DefaultShape
import net.schacher.mcc.shared.repositories.AuthRepository
import net.schacher.mcc.shared.screens.login.LoginScreenViewModel.UiState.CONFIRMATION
import net.schacher.mcc.shared.screens.login.LoginScreenViewModel.UiState.ENTER_CREDENTIALS
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.koinInject
import pro.schacher.mcc.BuildConfig

@OptIn(ExperimentalResourceApi::class)
internal var confirmationSeen = false

@Composable
fun LoginScreen(
viewModel: LoginScreenViewModel = koinInject(),
onLogInClicked: () -> Unit,
onLogInClicked: (() -> Unit)? = null,
onGuestLogin: () -> Unit,
) {
val state = viewModel.state.collectAsState().value
var showingConfirmation by remember { mutableStateOf(false) }
var showingLoginView by remember { mutableStateOf(false) }

Box(modifier = Modifier.fillMaxSize()) {
Image(
Expand Down Expand Up @@ -107,8 +105,15 @@ fun LoginScreen(
TextButton(
modifier = Modifier.fillMaxWidth(),
onClick = {
onLogInClicked.invoke()
// viewModel.onLoginClicked()
if (confirmationSeen) {
if (onLogInClicked != null) {
onLogInClicked()
} else {
showingLoginView = true
}
} else {
showingConfirmation = true
}
},
shape = DefaultShape,
colors = ButtonDefaults.textButtonColors(
Expand Down Expand Up @@ -141,25 +146,29 @@ fun LoginScreen(
}
}

when (state) {
CONFIRMATION -> {
ConfirmationDialog(
title = stringResource(Res.string.login_info_title),
message = stringResource(Res.string.login_info_message),
onConfirm = {
viewModel.onDismissInfoClicked()
},
)
}
if (showingConfirmation) {
confirmationSeen = true
ConfirmationDialog(
title = stringResource(Res.string.login_info_title),
message = stringResource(Res.string.login_info_message),
onConfirm = {
showingConfirmation = false

ENTER_CREDENTIALS -> {
ModalBottomLoginSheet(
onDismiss = {
viewModel.onDismissLoginClicked()
})
}
if (onLogInClicked != null) {
onLogInClicked.invoke()
} else {
showingLoginView = true
}
},
)
}

else -> {}
if (showingLoginView) {
ModalBottomLoginSheet(
onDismiss = {
showingLoginView = false
}
)
}
}

Expand Down

This file was deleted.

0 comments on commit 826f3ca

Please sign in to comment.