Pin setup with fake lock

This commit is contained in:
ganfra 2023-10-11 16:25:27 +02:00
parent 9ded4284b2
commit 2d5a3a473c
12 changed files with 211 additions and 40 deletions

View file

@ -0,0 +1,22 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* 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.pin.api
sealed interface PinState {
data object Unlocked : PinState
data object Locked : PinState
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* 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.pin.api
import kotlinx.coroutines.flow.StateFlow
interface PinStateDataSource {
val pinState: StateFlow<PinState>
fun lock()
fun unlock()
}

View file

@ -17,5 +17,5 @@
package io.element.android.features.pin.impl.auth
sealed interface PinAuthenticationEvents {
object MyEvent : PinAuthenticationEvents
data object Unlock : PinAuthenticationEvents
}

View file

@ -17,20 +17,21 @@
package io.element.android.features.pin.impl.auth
import androidx.compose.runtime.Composable
import io.element.android.features.pin.api.PinStateDataSource
import io.element.android.libraries.architecture.Presenter
import javax.inject.Inject
class PinAuthenticationPresenter @Inject constructor() : Presenter<PinAuthenticationState> {
class PinAuthenticationPresenter @Inject constructor(
private val pinStateDataSource: PinStateDataSource,
) : Presenter<PinAuthenticationState> {
@Composable
override fun present(): PinAuthenticationState {
fun handleEvents(event: PinAuthenticationEvents) {
when (event) {
PinAuthenticationEvents.MyEvent -> Unit
PinAuthenticationEvents.Unlock -> pinStateDataSource.unlock()
}
}
return PinAuthenticationState(
eventSink = ::handleEvents
)

View file

@ -22,7 +22,6 @@ open class PinAuthenticationStateProvider : PreviewParameterProvider<PinAuthenti
override val values: Sequence<PinAuthenticationState>
get() = sequenceOf(
aPinAuthenticationState(),
// Add other states here
)
}

View file

@ -16,29 +16,64 @@
package io.element.android.features.pin.impl.auth
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.MaterialTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lock
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import io.element.android.libraries.designsystem.atomic.molecules.IconTitleSubtitleMolecule
import io.element.android.libraries.designsystem.atomic.pages.HeaderFooterPage
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.Surface
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
@Composable
fun PinAuthenticationView(
state: PinAuthenticationState,
modifier: Modifier = Modifier,
) {
Box(modifier, contentAlignment = Alignment.Center) {
Text(
"PinAuthentication feature view",
color = MaterialTheme.colorScheme.primary,
Surface(modifier) {
HeaderFooterPage(
modifier = Modifier
.systemBarsPadding()
.fillMaxSize(),
header = { PinAuthenticationHeader(modifier = Modifier.padding(top = 60.dp, bottom = 12.dp)) },
footer = { PinAuthenticationFooter(state) },
)
}
}
@Composable
private fun PinAuthenticationHeader(
modifier: Modifier = Modifier,
) {
IconTitleSubtitleMolecule(
modifier = modifier,
title = "Element X is locked",
subTitle = null,
iconImageVector = Icons.Default.Lock,
)
}
@Composable
private fun PinAuthenticationFooter(state: PinAuthenticationState) {
Button(
modifier = Modifier.fillMaxWidth(),
text = "Unlock",
onClick = {
state.eventSink(PinAuthenticationEvents.Unlock)
}
)
}
@Composable
@PreviewsDayNight
fun PinAuthenticationViewLightPreview(@PreviewParameter(PinAuthenticationStateProvider::class) state: PinAuthenticationState) =

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* 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.pin.impl.state
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.pin.api.PinState
import io.element.android.features.pin.api.PinStateDataSource
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.SingleIn
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject
@SingleIn(AppScope::class)
@ContributesBinding(AppScope::class)
class DefaultPinStateDataSource @Inject constructor() : PinStateDataSource {
private val _pinState = MutableStateFlow<PinState>(PinState.Locked)
override val pinState: StateFlow<PinState> = _pinState
override fun unlock() {
_pinState.value = PinState.Unlocked
}
override fun lock() {
_pinState.value = PinState.Locked
}
}