Skip to content

Commit d4f7b2f

Browse files
committed
added pinlock view
1 parent abf57ee commit d4f7b2f

File tree

19 files changed

+436
-15
lines changed

19 files changed

+436
-15
lines changed

.DS_Store

6 KB
Binary file not shown.

animations/lottie/src/main/assets/success.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

animations/lottie/src/main/java/com/guru/composecookbook/lottie/LottieLoadingView.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,43 @@ package com.guru.composecookbook.lottie
22

33
import android.animation.ValueAnimator
44
import android.content.Context
5+
import androidx.compose.foundation.layout.defaultMinSize
6+
import androidx.compose.foundation.layout.size
57
import androidx.compose.runtime.Composable
68
import androidx.compose.runtime.remember
79
import androidx.compose.ui.Modifier
810
import androidx.compose.ui.viewinterop.AndroidView
911
import com.airbnb.lottie.LottieAnimationView
12+
import com.airbnb.lottie.compose.LottieCompositionSpec
13+
import com.airbnb.lottie.compose.rememberLottieComposition
14+
import androidx.compose.runtime.getValue
15+
import androidx.compose.ui.unit.dp
16+
import com.airbnb.lottie.compose.LottieAnimation
17+
1018

1119
@Composable
1220
fun LottieLoadingView(
1321
context: Context,
1422
file: String,
15-
modifier: Modifier = Modifier
23+
modifier: Modifier = Modifier,
24+
iterations: Int = 10
1625
) {
17-
val lottieView = remember {
18-
LottieAnimationView(context).apply {
19-
setAnimation(file)
20-
repeatCount = ValueAnimator.INFINITE
21-
}
22-
}
23-
AndroidView(
24-
{ lottieView },
25-
modifier = modifier
26-
) {
27-
it.playAnimation()
28-
}
26+
val composition by rememberLottieComposition(LottieCompositionSpec.Asset(file))
27+
LottieAnimation(composition, modifier = modifier.defaultMinSize(300.dp), iterations = iterations)
28+
29+
// OLD ANDROID VIEW IMPLEMENTATION
30+
// val lottieView = remember {
31+
// LottieAnimationView(context).apply {
32+
// setAnimation(file)
33+
// repeatCount = ValueAnimator.INFINITE
34+
// }
35+
// }
36+
// AndroidView(
37+
// { lottieView },
38+
// modifier = modifier
39+
// ) {
40+
// it.playAnimation()
41+
// }
42+
43+
2944
}

app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ dependencies {
8080
implementation(project(":demos:moviesapp:app"))
8181
implementation(project(":templates:onboarding"))
8282
implementation(project(":templates:paymentcard"))
83+
implementation(project(":templates:pinlock"))
8384
implementation(project(":templates:profile"))
8485
implementation(project(":templates:login"))
8586
implementation(project(":components:fab"))
@@ -112,4 +113,5 @@ dependencies {
112113
addThirdPartyUnitTestsDependencies()
113114

114115
addAndroidInstrumentationTestsDependencies()
116+
addBiometricDependency()
115117
}

app/src/main/java/com/guru/composecookbook/ui/templates/TemplateScreen.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.guru.composecookbook.ui.templates
22

3+
import androidx.compose.foundation.ExperimentalFoundationApi
34
import androidx.compose.foundation.layout.fillMaxSize
45
import androidx.compose.foundation.layout.fillMaxWidth
56
import androidx.compose.foundation.layout.padding
@@ -13,6 +14,7 @@ import androidx.compose.ui.platform.testTag
1314
import androidx.compose.ui.unit.dp
1415
import com.guru.composecookbook.ui.utils.TestTags
1516

17+
@ExperimentalFoundationApi
1618
@Composable
1719
fun TemplateScreen(darkTheme: Boolean) {
1820
val context = LocalContext.current
@@ -45,6 +47,7 @@ val templates = listOf(
4547
"On-boarding",
4648
"Charts",
4749
"Adding Payment Card",
50+
"Pin Lock/BioMetric",
4851
"Empty Screens",
4952
"Settings",
5053
"Loaders",

app/src/main/java/com/guru/composecookbook/ui/templates/TemplatesActivity.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
package com.guru.composecookbook.ui.templates
22

3+
import android.app.Activity
34
import android.content.Context
45
import android.content.Intent
56
import android.os.Bundle
67
import android.view.WindowManager
78
import androidx.activity.ComponentActivity
89
import androidx.activity.compose.setContent
10+
import androidx.biometric.BiometricPrompt
911
import androidx.compose.animation.ExperimentalAnimationApi
12+
import androidx.compose.foundation.ExperimentalFoundationApi
1013
import androidx.compose.material.ExperimentalMaterialApi
1114
import androidx.compose.runtime.Composable
15+
import androidx.core.content.ContextCompat
16+
import androidx.fragment.app.FragmentActivity
1217
import com.guru.composecookbook.charts.Charts
1318
import com.guru.composecookbook.comingsoon.ComingSoon
1419
import com.guru.composecookbook.login.LoginOnboarding
1520
import com.guru.composecookbook.onboarding.OnBoardingScreen
1621
import com.guru.composecookbook.paymentcard.AddPaymentScreen
1722
import com.guru.composecookbook.profile.ProfileScreen
1823
import com.guru.composecookbook.theme.ComposeCookBookTheme
24+
import com.guru.pinlock.PinLockView
1925

26+
@ExperimentalFoundationApi
2027
class TemplatesActivity : ComponentActivity() {
2128

2229
private val templateType: String by lazy { intent.getStringExtra(TYPE) ?: "Profiles" }
@@ -27,6 +34,7 @@ class TemplatesActivity : ComponentActivity() {
2734
override fun onCreate(savedInstanceState: Bundle?) {
2835
super.onCreate(savedInstanceState)
2936
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
37+
// val prompt = createBiometricPrompt(this as FragmentActivity)
3038
setContent {
3139
ComposeCookBookTheme(darkTheme = darkTheme) {
3240
TemplateApp(templateType)
@@ -46,6 +54,7 @@ class TemplatesActivity : ComponentActivity() {
4654
}
4755
}
4856

57+
@ExperimentalFoundationApi
4958
@ExperimentalAnimationApi
5059
@ExperimentalMaterialApi
5160
@Composable
@@ -56,6 +65,34 @@ fun TemplateApp(templateType: String) {
5665
"On-boarding" -> OnBoardingScreen { }
5766
"Charts" -> Charts()
5867
"Adding Payment Card" -> AddPaymentScreen()
68+
"Pin Lock/BioMetric" -> PinLockView()
5969
else -> ComingSoon()
6070
}
6171
}
72+
73+
private fun createBiometricPrompt(activity: FragmentActivity): BiometricPrompt {
74+
val executor = ContextCompat.getMainExecutor(activity)
75+
76+
val callback = object : BiometricPrompt.AuthenticationCallback() {
77+
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
78+
super.onAuthenticationError(errorCode, errString)
79+
if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
80+
//loginWithPassword() // Because in this app, the negative button allows the user
81+
// to enter an account password. This is completely optional and your app doesn’t have to do it.
82+
}
83+
}
84+
85+
override fun onAuthenticationFailed() {
86+
super.onAuthenticationFailed()
87+
}
88+
89+
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
90+
super.onAuthenticationSucceeded(result)
91+
// Proceed with viewing the private encrypted message.
92+
// showEncryptedMessage(result.cryptoObject)
93+
}
94+
}
95+
val biometricPrompt = BiometricPrompt(activity, executor, callback)
96+
97+
return biometricPrompt
98+
}

buildSrc/src/main/kotlin/com/guru/composecookbook/build/dependencies/Dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ object Dependencies {
7979
const val kotlinTest = "org.jetbrains.kotlin:kotlin-test:${Versions.kotlin}"
8080
const val androidXJunit = "androidx.test.ext:junit:${Versions.androidXJunit}"
8181

82+
const val biometric = "androidx.biometric:biometric:${Versions.biometric}"
83+
8284
}

buildSrc/src/main/kotlin/com/guru/composecookbook/build/dependencies/DependencyHandlerExtensions.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,7 @@ fun DependencyHandler.addThirdPartyUiDependencies() {
8686
add("implementation", it)
8787
}
8888
}
89+
90+
fun DependencyHandler.addBiometricDependency() {
91+
add("implementation", Dependencies.biometric)
92+
}

buildSrc/src/main/kotlin/com/guru/composecookbook/build/dependencies/GroupedDependencies.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,7 @@ internal val androidInstrumentationTestsDependencies = listOf(
9191
internal val thirdPartyUiDependencies = listOf(
9292
Dependencies.coilAccompanist,
9393
Dependencies.coilCompose,
94-
Dependencies.lottie
94+
Dependencies.lottie,
95+
Dependencies.composeLottie
9596
)
97+

buildSrc/src/main/kotlin/com/guru/composecookbook/build/dependencies/Versions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal object Versions {
1515
const val androidLifecycleGrouped = "2.3.1"
1616
const val flinger = "1.0.5"
1717
const val paging = "3.0.1"
18-
const val lottie = "4.0.0"
18+
const val lottie = "4.1.0"
1919
const val room = "2.4.0-alpha03"
2020
const val coreKtx = "1.6.0"
2121
const val appcompat = "1.3.1"
@@ -34,4 +34,5 @@ internal object Versions {
3434
const val junitJupiterEngine = "5.7.0"
3535
const val truth = "1.1.3"
3636
const val androidXJunit = "1.1.2"
37+
const val biometric = "1.2.0-alpha03"
3738
}

0 commit comments

Comments
 (0)