Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2656] : Implemented Biometric Authentication in Compose Multi Platform #61

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
72 changes: 72 additions & 0 deletions androidApp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins{
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.compose.compiler)
}

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
signingConfigs {
release {
storeFile file("../default_key_store.jks")
storePassword "mifos1234"
keyAlias "mifos-passcode"
keyPassword "mifos1234"
}
}
compileSdk 35
defaultConfig {
namespace "com.mifos.passcode"
minSdk 24
targetSdk 35
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.2"
}
kotlinOptions {
jvmTarget = '17'
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation(project(":compose"))
implementation project(':shared')
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.material3)
implementation(libs.androidx.activity.compose)
implementation libs.androidx.appcompat
androidTestImplementation libs.testng
androidTestImplementation libs.androidx.monitor
androidTestImplementation libs.runner
androidTestImplementation libs.junit
androidTestImplementation libs.runner
androidTestImplementation libs.androidx.monitor
debugImplementation(libs.compose.ui.tooling)
implementation (libs.androidx.navigation.compose)
implementation (libs.androidx.biometric)
}
repositories {
mavenCentral()
}

configurations.implementation {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.mifos.passcode;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

Expand All @@ -24,4 +21,4 @@ public void useAppContext() {

assertEquals("com.mifos.passcode", appContext.getPackageName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".MifosApplication"
android:theme="@style/AppTheme" >
<activity android:name=".PassCodeActivity"
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
81 changes: 81 additions & 0 deletions androidApp/src/main/java/com/mifos/passcode/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.mifos.passcode

import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.fragment.app.FragmentActivity
import com.mifos.shared.BiometricUtilAndroidImpl
import com.mifos.shared.CipherUtilAndroidImpl
import com.mifos.shared.utility.PreferenceManager
import com.mifos.shared.PasscodeRepository
import com.mifos.shared.PasscodeRepositoryImpl
import com.mifos.shared.viewmodels.BiometricAuthorizationViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import com.mifos.shared.component.PasscodeScreen


class MainActivity : FragmentActivity() {

private val bioMetricUtil by lazy {
BiometricUtilAndroidImpl(this, CipherUtilAndroidImpl())
}
private lateinit var passcodeRepository: PasscodeRepository

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

bioMetricUtil.preparePrompt(
title= getString(R.string.biometric_auth_title),
subtitle = "",
description = getString(R.string.biometric_auth_description)
)
passcodeRepository = PasscodeRepositoryImpl(PreferenceManager())

setContent {
PasscodeScreen(
onForgotButton = { onPasscodeForgot() },
onSkipButton = { onPasscodeSkip() },
onPasscodeConfirm = { onPassCodeReceive(it) },
onPasscodeRejected = { onPasscodeReject() },
enableBiometric = true,
bioMetricUtil = bioMetricUtil,
onBiometricAuthSuccess = { launchNextActivity() },
)
}
}

private fun onPassCodeReceive(passcode: String) {
if (passcodeRepository.getSavedPasscode() == passcode) {
launchNextActivity()
}
}

private fun onPasscodeReject() {}

private fun onPasscodeForgot() {
// Add logic to redirect user to login page
}

private fun onPasscodeSkip() {
finish()
}

private fun launchNextActivity() {
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
}
@Composable
fun GreetingView(text: String) {
Text(text = text)
}

//@Preview
//@Composable
//fun DefaultPreview() {
// MyApplicationTheme {
// GreetingView("Hello, Android!")
// }
//}
6 changes: 6 additions & 0 deletions androidApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<string name="app_name">mobile_passcode</string>
<string name="fingerprint_dialog_title">Login</string>
<string name="biometric_auth_title">Unlock Mifos</string>
<string name="biometric_auth_description">Confirm your screen lock pattern, PIN, password, or fingerprint to unlock</string>
</resources>
81 changes: 0 additions & 81 deletions app/build.gradle

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/java/com/mifos/passcode/BaseActivity.kt

This file was deleted.

18 changes: 0 additions & 18 deletions app/src/main/java/com/mifos/passcode/MifosApplication.kt

This file was deleted.

57 changes: 0 additions & 57 deletions app/src/main/java/com/mifos/passcode/PassCodeActivity.kt

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/values/strings.xml

This file was deleted.

Loading
Loading