mirror of
https://github.com/bitwarden/android.git
synced 2026-02-04 03:05:28 -06:00
Rendering konami code QRCode for testing purposes; UI cleanup;
This commit is contained in:
parent
6d196b5214
commit
605e0ef023
@ -8,8 +8,6 @@ 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.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@ -21,7 +19,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@ -30,13 +28,13 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.cardStyle
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
|
||||
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
|
||||
import com.x8bit.bitwarden.ui.platform.components.dropdown.BitwardenMultiSelectButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.CardStyle
|
||||
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
|
||||
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.ui.vault.feature.viewasqrcode.handlers.ViewAsQrCodeHandlers
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@ -77,30 +75,28 @@ fun ViewAsQrCodeScreen(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
.verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(height = 12.dp))
|
||||
|
||||
// QR Code display
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(250.dp)
|
||||
.background(Color.White)
|
||||
.padding(8.dp),
|
||||
.standardHorizontalMargin()
|
||||
.cardStyle(CardStyle.Full)
|
||||
.fillMaxSize()
|
||||
.background(Color.White),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Image(
|
||||
//TODO set qrcode image
|
||||
painter = rememberVectorPainter(id = R.drawable.bitwarden_logo),
|
||||
colorFilter = ColorFilter.tint(BitwardenTheme.colorScheme.icon.secondary),
|
||||
|
||||
//bitmap = contentState.qrCodeBitmap.asImageBitmap(),
|
||||
bitmap = state.qrCodeBitmap.asImageBitmap(),
|
||||
contentDescription = stringResource(id = R.string.qr_code),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
// QR Code type selector
|
||||
val resources = LocalContext.current.resources
|
||||
@ -114,7 +110,7 @@ fun ViewAsQrCodeScreen(
|
||||
}
|
||||
viewModel.trySendAction(ViewAsQrCodeAction.QrCodeTypeSelect(selectedType))
|
||||
},
|
||||
supportingText = stringResource(id = R.string.default_uri_match_detection_description),
|
||||
//supportingText = stringResource(id = R.string.default_uri_match_detection_description),
|
||||
cardStyle = CardStyle.Full,
|
||||
modifier = Modifier
|
||||
.testTag("QRCodeType")
|
||||
@ -123,7 +119,7 @@ fun ViewAsQrCodeScreen(
|
||||
)
|
||||
|
||||
//QR Code Type dropdowns
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
viewState.qrCodeTypeFields.forEachIndexed { i, field ->
|
||||
val cipherFieldsTextList =
|
||||
viewState.cipherFields.map { it() }.toImmutableList()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.viewasqrcode
|
||||
|
||||
//import com.x8bit.bitwarden.ui.vault.feature.viewasqrcode.util.toViewState
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@ -14,6 +15,7 @@ import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.util.SELECT_TEXT
|
||||
import com.x8bit.bitwarden.ui.vault.feature.viewasqrcode.model.QrCodeType
|
||||
import com.x8bit.bitwarden.ui.vault.feature.viewasqrcode.model.QrCodeTypeField
|
||||
import com.x8bit.bitwarden.ui.vault.feature.viewasqrcode.util.QrCodeGenerator
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultItemCipherType
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@ -43,10 +45,10 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
ViewAsQrCodeState(
|
||||
cipherId = args.vaultItemId,
|
||||
cipherType = args.vaultItemCipherType,
|
||||
qrCodeBitmap = QrCodeGenerator.generateQrCodeBitmap("↑, ↑, ↓, ↓, ←, →, ←, →, B, A,↑, ↑, ↓, ↓, ←, →, ←, →, B, A,↑, ↑, ↓, ↓, ←, →, ←, →, B, A,↑, ↑, ↓, ↓, ←, →, ←, →, B, A,↑, ↑, ↓, ↓, ←, →, ←, →, B, A,"),
|
||||
selectedQrCodeType = selectedQrCodeType,
|
||||
qrCodeTypes = qrCodeTypes,
|
||||
qrCodeTypeFields = selectedQrCodeType.fields,
|
||||
// selectedCipherFields = autoMapByQr
|
||||
cipherFields = emptyList(),
|
||||
cipher = null,
|
||||
|
||||
@ -61,7 +63,7 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
//TODO get args.vaultItemCipherType and auto-map
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
cipherFields = cipherFieldsFor(it.cipherType),
|
||||
cipherFields = cipherFieldsFor(it.cipherType, null),
|
||||
)
|
||||
}
|
||||
vaultRepository
|
||||
@ -94,7 +96,7 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
when (val dataState = action.cipherDataState) {
|
||||
is DataState.Loaded -> {
|
||||
val cipher = dataState.data
|
||||
val cipherFields = cipherFieldsFor(state.cipherType)
|
||||
val cipherFields = cipherFieldsFor(state.cipherType, cipher)
|
||||
|
||||
val updatedQrCodeFields = autoMapFields(
|
||||
state.qrCodeTypeFields,
|
||||
@ -246,8 +248,10 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
//TODO create list with common fields first like SELECT_TEXT
|
||||
private fun cipherFieldsFor(cipherType: VaultItemCipherType): List<Text> =
|
||||
when (cipherType) {
|
||||
private fun cipherFieldsFor(cipherType: VaultItemCipherType, cipher: CipherView?): List<Text> {
|
||||
//TODO add additional cipher fields like web links and custom fields
|
||||
//TODO filter base list depending on the cipher data
|
||||
return when (cipherType) {
|
||||
VaultItemCipherType.LOGIN -> listOf(
|
||||
SELECT_TEXT,
|
||||
R.string.name.asText(),
|
||||
@ -282,6 +286,7 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
//TODO finish
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -292,7 +297,7 @@ class ViewAsQrCodeViewModel @Inject constructor(
|
||||
data class ViewAsQrCodeState(
|
||||
val cipherId: String,
|
||||
val cipherType: VaultItemCipherType,
|
||||
// val qrCodeBitmap: Bitmap,
|
||||
val qrCodeBitmap: Bitmap,
|
||||
val selectedQrCodeType: QrCodeType,
|
||||
val qrCodeTypes: List<QrCodeType>,
|
||||
val qrCodeTypeFields: List<QrCodeTypeField>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user