Skip to content

Commit

Permalink
Initial schildifyed login flow
Browse files Browse the repository at this point in the history
Change-Id: I96ad63bfdbd7cf5dc9b615751db8fe7f56c0a1f3
  • Loading branch information
SpiritCroc committed Jan 20, 2024
1 parent 2743c20 commit 3469c2a
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AndroidWelcomeScreenState @Inject constructor(
}

override fun isWelcomeScreenNeeded(): Boolean {
return sharedPreferences.getBoolean(IS_WELCOME_SCREEN_SHOWN, false).not()
return false// sharedPreferences.getBoolean(IS_WELCOME_SCREEN_SHOWN, false).not()
}

override fun setWelcomeScreenShown() {
Expand Down
1 change: 1 addition & 0 deletions features/onboarding/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ anvil {
}

dependencies {
implementation(projects.schildi.lib)
implementation(projects.anvilannotations)
anvil(projects.anvilcodegen)
implementation(projects.libraries.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OnBoardingNode @AssistedInject constructor(
@Composable
override fun View(modifier: Modifier) {
val state = presenter.present()
OnBoardingView(
ScOnBoardingView(
state = state,
modifier = modifier,
onSignIn = ::onSignIn,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright (c) 2023 New Vector Ltd
* Copyright (c) 2024 SchildiChat
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.element.android.features.onboarding.impl

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.QrCode
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.libraries.designsystem.atomic.atoms.ElementLogoAtomSize
import io.element.android.libraries.designsystem.atomic.atoms.ScLogoAtom
import io.element.android.libraries.designsystem.atomic.molecules.ButtonColumnMolecule
import io.element.android.libraries.designsystem.atomic.pages.OnBoardingPage
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.IconButton
import io.element.android.libraries.designsystem.theme.components.IconSource
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.testtags.TestTags
import io.element.android.libraries.testtags.testTag
import io.element.android.libraries.ui.strings.CommonStrings

@Composable
fun ScOnBoardingView(
state: OnBoardingState,
onSignInWithQrCode: () -> Unit,
onSignIn: () -> Unit,
onCreateAccount: () -> Unit,
onOpenDeveloperSettings: () -> Unit,
modifier: Modifier = Modifier,
) {
OnBoardingPage(
modifier = modifier,
content = {
OnBoardingContent(
state = state,
onOpenDeveloperSettings = onOpenDeveloperSettings
)
},
footer = {
OnBoardingButtons(
state = state,
onSignInWithQrCode = onSignInWithQrCode,
onSignIn = onSignIn,
onCreateAccount = onCreateAccount,
)
}
)
}

@Composable
private fun OnBoardingContent(
state: OnBoardingState,
onOpenDeveloperSettings: () -> Unit,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier.fillMaxSize(),
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = BiasAlignment(
horizontalBias = 0f,
verticalBias = -0.4f
)
) {
ScLogoAtom(
size = ElementLogoAtomSize.Large,
modifier = Modifier.padding(top = ElementLogoAtomSize.Large.shadowRadius / 2)
)
}
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = BiasAlignment(
horizontalBias = 0f,
verticalBias = 0.6f
)
) {
Column(
modifier = Modifier
.fillMaxWidth(),
horizontalAlignment = CenterHorizontally,
) {
Text(
text = stringResource(id = chat.schildi.lib.R.string.sc_onboarding_welcome_title),
color = ElementTheme.materialColors.primary,
style = ElementTheme.typography.fontHeadingLgBold,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(id = chat.schildi.lib.R.string.sc_onboarding_welcome_summary),
color = ElementTheme.materialColors.secondary,
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = 17.sp),
textAlign = TextAlign.Center
)
}
}
if (state.isDebugBuild) {
IconButton(
modifier = Modifier.align(Alignment.TopEnd),
onClick = onOpenDeveloperSettings,
) {
Icon(
imageVector = CompoundIcons.SettingsSolid,
contentDescription = stringResource(CommonStrings.common_settings)
)
}
}
}
}

@Composable
private fun OnBoardingButtons(
state: OnBoardingState,
onSignInWithQrCode: () -> Unit,
onSignIn: () -> Unit,
onCreateAccount: () -> Unit,
modifier: Modifier = Modifier,
) {
ButtonColumnMolecule(modifier = modifier) {
val signInButtonStringRes = if (state.canLoginWithQrCode || state.canCreateAccount) {
R.string.screen_onboarding_sign_in_manually
} else {
CommonStrings.action_continue
}
if (state.canLoginWithQrCode) {
Button(
text = stringResource(id = R.string.screen_onboarding_sign_in_with_qr_code),
leadingIcon = IconSource.Vector(Icons.Default.QrCode),
onClick = onSignInWithQrCode,
modifier = Modifier.fillMaxWidth()
)
}
Button(
text = stringResource(id = signInButtonStringRes),
onClick = onSignIn,
modifier = Modifier
.fillMaxWidth()
.testTag(TestTags.onBoardingSignIn)
)
if (state.canCreateAccount) {
OutlinedButton(
text = stringResource(id = R.string.screen_onboarding_sign_up),
onClick = onCreateAccount,
enabled = true,
modifier = Modifier
.fillMaxWidth()
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}

@PreviewsDayNight
@Composable
internal fun ScOnBoardingScreenPreview(
@PreviewParameter(OnBoardingStateProvider::class) state: OnBoardingState
) = ElementPreview {
ScOnBoardingView(
state = state,
onSignInWithQrCode = {},
onSignIn = {},
onCreateAccount = {},
onOpenDeveloperSettings = {}
)
}
3 changes: 3 additions & 0 deletions graphics/icon_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export_files
file="$mydir/ic_launcher_foreground.svg"
dpi=32
export_files_custom "ic_launcher.png" --export-area="$non_adaptive_area"
dpi=96
base_folder="$mydir/../schildi/lib/src/main/res/drawable"
export_files_custom "sc_logo_atom.png" --export-area="$non_adaptive_area"


# Store icon:
Expand Down
1 change: 1 addition & 0 deletions libraries/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
}

dependencies {
implementation(projects.schildi.lib)
implementation(projects.schildi.theme)
api(libs.compound)
// Should not be there, but this is a POC
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.element.android.libraries.designsystem.atomic.atoms

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.res.painterResource
import chat.schildi.theme.ScBrandingColors

@Composable
fun ScLogoAtom(
size: ElementLogoAtomSize,
modifier: Modifier = Modifier,
darkTheme: Boolean = isSystemInDarkTheme(),
) {
val commonModifier = modifier.size(size.outerSize).clip(RoundedCornerShape(size.cornerRadius))
val themedModifier = if (darkTheme) {
commonModifier.border(size.borderWidth, ScBrandingColors.onboardingLogoOutlineDark, RoundedCornerShape(size.cornerRadius))
} else {
commonModifier.background(Brush.linearGradient(ScBrandingColors.onboardingIconBgColors))
}
Box(
modifier = themedModifier,
contentAlignment = Alignment.Center,
) {
Image(
modifier = Modifier
.size(size.logoSize),
painter = painterResource(id = chat.schildi.lib.R.drawable.sc_logo_atom),
contentDescription = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fun OnBoardingPage(
footer: @Composable () -> Unit = {},
content: @Composable () -> Unit = {},
) {
if (true) {
ScOnBoardingPage(modifier = modifier, contentAlignment = contentAlignment, footer = footer, content = content)
return
}
Box(
modifier = modifier
.fillMaxSize()
Expand Down
Loading

0 comments on commit 3469c2a

Please sign in to comment.