mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
add a switch in Settings to enable or disable auth
This commit is contained in:
@@ -101,16 +101,21 @@ fun Auth(activity: FragmentActivity, callback: AuthenticationCallback, promptInf
|
||||
Button(
|
||||
onClick = {
|
||||
val bioManager = BiometricManager.from(context)
|
||||
when(BiometricManager.BIOMETRIC_SUCCESS){
|
||||
bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) ->
|
||||
promptInfo
|
||||
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG)
|
||||
.setNegativeButtonText("Use password")
|
||||
bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) ->
|
||||
promptInfo
|
||||
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK)
|
||||
.setNegativeButtonText("Use password")
|
||||
else -> promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
||||
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(sharedPref.getBoolean("bio_auth", false)){
|
||||
when(BiometricManager.BIOMETRIC_SUCCESS){
|
||||
bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) ->
|
||||
promptInfo
|
||||
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG)
|
||||
.setNegativeButtonText("Use password")
|
||||
bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) ->
|
||||
promptInfo
|
||||
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK)
|
||||
.setNegativeButtonText("Use password")
|
||||
else -> promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
||||
}
|
||||
}else{
|
||||
promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
||||
}
|
||||
authWithBiometricPrompt(activity, promptInfo.build(), callback)
|
||||
}
|
||||
|
||||
@@ -60,9 +60,14 @@ class MainActivity : FragmentActivity() {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.base)
|
||||
val sharedPref = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val fragmentManager = supportFragmentManager
|
||||
val transaction = fragmentManager.beginTransaction()
|
||||
transaction.add(R.id.base, AuthFragment(), "auth")
|
||||
if(sharedPref.getBoolean("auth", false)){
|
||||
transaction.add(R.id.base, AuthFragment(), "auth")
|
||||
}else{
|
||||
transaction.add(R.id.base, homeFragment, "home")
|
||||
}
|
||||
transaction.commit()
|
||||
val locale = applicationContext.resources?.configuration?.locale
|
||||
zhCN = locale==Locale.SIMPLIFIED_CHINESE||locale==Locale.CHINESE||locale==Locale.CHINA
|
||||
|
||||
@@ -14,9 +14,7 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -56,9 +54,10 @@ fun AppSetting(navCtrl:NavHostController, materialYou: MutableState<Boolean>, bl
|
||||
popExitTransition = Animations.navHostPopExitTransition,
|
||||
modifier = Modifier.padding(top = it.calculateTopPadding())
|
||||
){
|
||||
composable(route = "Home"){Home(localNavCtrl)}
|
||||
composable(route = "Settings"){Settings(materialYou, blackTheme)}
|
||||
composable(route = "About"){About()}
|
||||
composable(route = "Home"){ Home(localNavCtrl) }
|
||||
composable(route = "Theme"){ ThemeSettings(materialYou, blackTheme) }
|
||||
composable(route = "Auth"){ AuthSettings() }
|
||||
composable(route = "About"){ About() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,13 +65,14 @@ fun AppSetting(navCtrl:NavHostController, materialYou: MutableState<Boolean>, bl
|
||||
@Composable
|
||||
private fun Home(navCtrl: NavHostController){
|
||||
Column(modifier = Modifier.fillMaxSize()){
|
||||
SubPageItem(R.string.setting,"",R.drawable.settings_fill0){navCtrl.navigate("Settings")}
|
||||
SubPageItem(R.string.setting,"",R.drawable.settings_fill0){navCtrl.navigate("Theme")}
|
||||
SubPageItem(R.string.security,"",R.drawable.settings_fill0){navCtrl.navigate("Auth")}
|
||||
SubPageItem(R.string.about,"",R.drawable.info_fill0){navCtrl.navigate("About")}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Settings(materialYou:MutableState<Boolean>, blackTheme:MutableState<Boolean>){
|
||||
private fun ThemeSettings(materialYou:MutableState<Boolean>, blackTheme:MutableState<Boolean>){
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
|
||||
if(VERSION.SDK_INT>=31){
|
||||
@@ -98,6 +98,31 @@ private fun Settings(materialYou:MutableState<Boolean>, blackTheme:MutableState<
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AuthSettings(){
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
var auth by remember{ mutableStateOf(sharedPref.getBoolean("auth",false)) }
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
|
||||
if(VERSION.SDK_INT>=30){
|
||||
SwitchItem(
|
||||
R.string.lock_owndroid, "", null,
|
||||
{ auth },
|
||||
{
|
||||
sharedPref.edit().putBoolean("auth",it).apply()
|
||||
auth = sharedPref.getBoolean("auth",false)
|
||||
}
|
||||
)
|
||||
}
|
||||
if(auth){
|
||||
SwitchItem(
|
||||
R.string.enable_bio_auth, "", null,
|
||||
{ sharedPref.getBoolean("bio_auth",false) },
|
||||
{ sharedPref.edit().putBoolean("bio_auth",it).apply() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun About(){
|
||||
val myContext = LocalContext.current
|
||||
|
||||
Reference in New Issue
Block a user