improvement(Android): If credentials feature is not supported then show a note to a user
This commit is contained in:
parent
74ef9a34ef
commit
bee31a26ed
|
@ -1,6 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Passkeys -->
|
||||
<uses-feature
|
||||
android:name="android.software.credentials"
|
||||
android:required="false" />
|
||||
<!--
|
||||
I need this permission to be able to check if linked app is installed on the
|
||||
system or not. -->
|
||||
|
|
|
@ -1,26 +1,32 @@
|
|||
package com.artemchep.keyguard.feature.home.settings.component
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Key
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.credentials.CredentialManager
|
||||
import com.artemchep.keyguard.common.io.ioEffect
|
||||
import com.artemchep.keyguard.common.io.launchIn
|
||||
import com.artemchep.keyguard.common.usecase.WindowCoroutineScope
|
||||
import com.artemchep.keyguard.res.Res
|
||||
import com.artemchep.keyguard.res.*
|
||||
import com.artemchep.keyguard.ui.FlatItem
|
||||
import com.artemchep.keyguard.ui.FlatSimpleNote
|
||||
import com.artemchep.keyguard.ui.SimpleNote
|
||||
import com.artemchep.keyguard.ui.icons.ChevronIcon
|
||||
import com.artemchep.keyguard.ui.icons.icon
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import com.artemchep.keyguard.ui.theme.Dimens
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.kodein.di.DirectDI
|
||||
import org.kodein.di.instance
|
||||
|
||||
|
@ -58,12 +64,22 @@ fun settingCredentialProviderProvider(
|
|||
.create(context)
|
||||
.createSettingsPendingIntent()
|
||||
}
|
||||
val hasFeature = remember(context) {
|
||||
val pm = context.packageManager
|
||||
pm.hasSystemFeature(PackageManager.FEATURE_CREDENTIALS)
|
||||
}
|
||||
SettingCredentialProvider(
|
||||
onClick = {
|
||||
ioEffect(Dispatchers.Main.immediate) {
|
||||
pi.send()
|
||||
}.launchIn(windowCoroutineScope)
|
||||
onClick = if (hasFeature) {
|
||||
// lambda
|
||||
{
|
||||
ioEffect(Dispatchers.Main.immediate) {
|
||||
pi.send()
|
||||
}.launchIn(windowCoroutineScope)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
hasFeature = hasFeature,
|
||||
)
|
||||
}
|
||||
flowOf(item)
|
||||
|
@ -72,6 +88,7 @@ fun settingCredentialProviderProvider(
|
|||
@Composable
|
||||
private fun SettingCredentialProvider(
|
||||
onClick: (() -> Unit)?,
|
||||
hasFeature: Boolean,
|
||||
) {
|
||||
FlatItem(
|
||||
leading = icon<RowScope>(Icons.Outlined.Key),
|
||||
|
@ -90,4 +107,16 @@ private fun SettingCredentialProvider(
|
|||
},
|
||||
onClick = onClick,
|
||||
)
|
||||
if (!hasFeature) {
|
||||
FlatSimpleNote(
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = 8.dp,
|
||||
bottom = 8.dp,
|
||||
start = Dimens.horizontalPadding * 1 + 24.dp,
|
||||
),
|
||||
type = SimpleNote.Type.INFO,
|
||||
text = stringResource(Res.string.pref_item_credential_provider_no_feature_note),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1007,6 +1007,7 @@
|
|||
<string name="pref_item_crash_title">Crash</string>
|
||||
<string name="pref_item_credential_provider_title">Credential provider</string>
|
||||
<string name="pref_item_credential_provider_text">Passkeys, passwords and data services</string>
|
||||
<string name="pref_item_credential_provider_no_feature_note">The device doesn't support retrieval of user credentials via integration with credential providers. Contact the manufacturer for more information.</string>
|
||||
<string name="pref_item_privacy_policy_title">Privacy policy</string>
|
||||
<string name="pref_item_contact_us_title">Contact us</string>
|
||||
<string name="pref_item_experimental_title">Experimental</string>
|
||||
|
|
Loading…
Reference in New Issue