Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
- Use boolean to decide on skipping startPage
- Move login type selection logic to login types provider
  • Loading branch information
sunkup committed May 17, 2024
1 parent 3fb7053 commit 488642a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,17 @@ class LoginActivity @Inject constructor(): AppCompatActivity() {

}

@Inject lateinit var loginTypesProvider: LoginTypesProvider

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

var initialLoginType: LoginType = UrlLogin
var startPage: LoginScreenModel.Page = LoginScreenModel.Page.LoginType

// Login flow from nextcloud app, via intent
if (intent.hasExtra(EXTRA_LOGIN_FLOW)) {
initialLoginType = NextcloudLogin
startPage = LoginScreenModel.Page.LoginDetails
}
val (initialLoginType, skipLoginTypePage) = loginTypesProvider.intentToInitialLoginType(intent)

setContent {
LoginScreen(
startPage = startPage,
initialLoginType = initialLoginType,
skipLoginTypePage = skipLoginTypePage,
initialLoginInfo = loginInfoFromIntent(intent),
onNavUp = { onSupportNavigateUp() },
onFinish = { newAccount ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import at.bitfire.davdroid.ui.AppTheme

@Composable
fun LoginScreen(
startPage: LoginScreenModel.Page = LoginScreenModel.Page.LoginType,
initialLoginInfo: LoginInfo = LoginInfo(),
skipLoginTypePage: Boolean = false,
initialLoginType: LoginType = UrlLogin,
onNavUp: () -> Unit,
onFinish: (Account?) -> Unit
) {
val model: LoginScreenModel = hiltViewModel { factory: LoginScreenModel.Factory ->
factory.create(startPage, initialLoginInfo, initialLoginType)
factory.create(skipLoginTypePage, initialLoginInfo, initialLoginType)
}

// handle back/up navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import kotlinx.coroutines.withContext

@HiltViewModel(assistedFactory = LoginScreenModel.Factory::class)
class LoginScreenModel @AssistedInject constructor(
@Assisted val startPage: Page,
@Assisted val skipLoginTypePage: Boolean,
@Assisted val initialLoginInfo: LoginInfo,
@Assisted val initialLoginType: LoginType,
val context: Application,
Expand All @@ -45,7 +45,7 @@ class LoginScreenModel @AssistedInject constructor(
@AssistedFactory
interface Factory {
fun create(
startPage: Page,
skipLoginTypePage: Boolean,
initialLoginInfo: LoginInfo,
initialLoginType: LoginType
): LoginScreenModel
Expand All @@ -58,6 +58,11 @@ class LoginScreenModel @AssistedInject constructor(
AccountDetails
}

private val startPage = if (skipLoginTypePage)
Page.LoginDetails
else
Page.LoginType

var page by mutableStateOf(startPage)
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ interface LoginTypesProvider {

val defaultLoginType: LoginType

fun intentToInitialLoginType(intent: Intent): LoginType
/**
* Which login type to use and whether to skip the login type selection page. Used for Nextcloud
* login flow. May be used by other login flows.
*/
fun intentToInitialLoginType(intent: Intent): Pair<LoginType, Boolean> = Pair(defaultLoginType, false)

/** Whether the [LoginTypePage] may be non-interactive. This causes it to be skipped in back navigation. */
val maybeNonInteractive: Boolean
Expand Down
6 changes: 3 additions & 3 deletions app/src/ose/kotlin/at/bitfire/davdroid/OseFlavorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import at.bitfire.davdroid.ui.AboutActivity
import at.bitfire.davdroid.ui.AccountsDrawerHandler
import at.bitfire.davdroid.ui.OpenSourceLicenseInfoProvider
import at.bitfire.davdroid.ui.OseAccountsDrawerHandler
import at.bitfire.davdroid.ui.intro.BatteryOptimizationsPage
import at.bitfire.davdroid.ui.intro.IntroPage
import at.bitfire.davdroid.ui.intro.IntroPageFactory
import at.bitfire.davdroid.ui.setup.LoginTypesProvider
import at.bitfire.davdroid.ui.setup.StandardLoginTypesProvider
Expand All @@ -19,7 +17,6 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.components.SingletonComponent
import dagger.multibindings.IntoSet

interface OseFlavorModules {

Expand All @@ -28,6 +25,9 @@ interface OseFlavorModules {
interface ForActivities {
@Binds
fun accountsDrawerHandler(impl: OseAccountsDrawerHandler): AccountsDrawerHandler

@Binds
fun loginTypesProvider(impl: StandardLoginTypesProvider): LoginTypesProvider
}

@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class StandardLoginTypesProvider @Inject constructor() : LoginTypesProvider {

override fun intentToInitialLoginType(intent: Intent) =
if (intent.hasExtra(LoginActivity.EXTRA_LOGIN_FLOW))
NextcloudLogin
Pair(NextcloudLogin, true)
else
UrlLogin
Pair(defaultLoginType, false)

@Composable
override fun LoginTypePage(
Expand Down

0 comments on commit 488642a

Please sign in to comment.