Skip to content

Commit

Permalink
require bio-metric based on bio-metric settings
Browse files Browse the repository at this point in the history
  • Loading branch information
maifeeulasad committed Mar 19, 2021
1 parent bed5ff0 commit 7331969
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -17,6 +18,8 @@ import dev.spikeysanju.expensetracker.databinding.ActivityMainBinding
import dev.spikeysanju.expensetracker.repo.TransactionRepo
import dev.spikeysanju.expensetracker.utils.viewModelFactory
import dev.spikeysanju.expensetracker.view.main.viewmodel.TransactionViewModel
import dev.spikeysanju.expensetracker.view.settings.SettingsViewModel
import kotlinx.coroutines.flow.first
import java.util.concurrent.Executor
import kotlin.system.exitProcess

Expand All @@ -34,6 +37,10 @@ class MainActivity : AppCompatActivity() {
viewModelFactory { TransactionViewModel(this.application, repo) }
}

private val settingsViewModel: SettingsViewModel by viewModels{
viewModelFactory { SettingsViewModel(this.application) }
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
Expand All @@ -45,7 +52,12 @@ class MainActivity : AppCompatActivity() {
*/
viewModel

authenticate()

// Set the item state
lifecycleScope.launchWhenStarted {
if(settingsViewModel.bioMetricPreference.first())
authenticate()
}

initViews(binding)
observeNavElements(binding, navHostFragment.navController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding, SettingsViewModel
}

private fun initViews() = with(binding) {
biometric.setOnCheckedChangeListener { _, isChecked ->
viewModel.setBioMetricLock(isChecked)
biometric.setOnCheckedChangeListener { _, biometricEnabled ->
viewModel.setBioMetricLock(biometricEnabled)
}

}
Expand Down

0 comments on commit 7331969

Please sign in to comment.