Как добавить biometric authentication в приложение на kotlin?

Рейтинг: 0Ответов: 0Опубликовано: 22.01.2023

Это майн активити

package ua.com.lomtal.view.main

import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_home.*
import ua.com.lomtal.R
import ua.com.lomtal.core.model.localization.Language
import ua.com.lomtal.core.model.localization.Translation
import ua.com.lomtal.view.base.BaseActivity
import ua.com.lomtal.view.login.LoginActivity
import ua.com.lomtal.viewmodel.MainViewModel

class MainActivity : BaseActivity<MainViewModel>(MainViewModel::class) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bottomNavigate(FragmentHome::class.java, bottom_bar_home)
        bottom_bar_home.setOnClickListener{
            bottomNavigate(FragmentHome::class.java, bottom_bar_home)
        }
        bottom_bar_calculate.setOnClickListener{
            bottomNavigate(FragmentCalculate::class.java, bottom_bar_calculate)
        }
        bottom_bar_contracts.setOnClickListener{
            bottomNavigate(FragmentContractList::class.java, bottom_bar_contracts)
        }
        bottom_bar_more.setOnClickListener {
            bottomNavigate(FragmentOther::class.java, bottom_bar_more)
        }
        bottom_button.setOnClickListener {
            openCardFragment()
        }

        viewModel.loadContracts()
        viewModel.loadPawnshops()

        viewModel.myCardClick.observe(this, Observer {
            openCardFragment()
        })

        viewModel.loggedOut.observe(this, Observer {
            startActivity(Intent(this, LoginActivity::class.java))
            finish()
        })
    }

    override fun onFragmentClick() {
        viewModel.calculateTechFragmentClick.call()
    }

    override fun onDisplayTranslation(translation: Language) {
        bottom_bar_calculate.text = translation[Translation.Main.TITLE_CALCULATE]
        bottom_bar_contracts.text = translation[Translation.Main.TITLE_CONTRACTS]
        bottom_bar_home.text = translation[Translation.Main.TITLE_HOME]
        bottom_bar_more.text = translation[Translation.Main.TITLE_OTHER]
    }

    private fun openCardFragment(){
        setFragment(FragmentCard::class.java, R.id.main_frame)
        bottom_button.isClickable = false
        disableButtons()
    }

    private fun bottomNavigate(fragment: Class<out Fragment>?, view: TextView, args: Bundle? = null){
        if(fragment != null) {
            setFragment(fragment, R.id.main_frame, args)
        }
        disableButtons()
        view.setTextColor(Color.WHITE)
        view.isClickable = false
        view.compoundDrawables[1].alpha = 255
        bottom_button.isClickable = true
    }

    override fun onDestroy() {
        super.onDestroy()
        viewModel.dispose()
    }

    private fun disableButtons(){
        bottom_bar_calculate.setTextColor(ContextCompat.getColor(this@MainActivity, R.color.colorTextInactive))
        bottom_bar_home.setTextColor(ContextCompat.getColor(this@MainActivity, R.color.colorTextInactive))
        bottom_bar_contracts.setTextColor(ContextCompat.getColor(this@MainActivity, R.color.colorTextInactive))
        bottom_bar_more.setTextColor(ContextCompat.getColor(this@MainActivity, R.color.colorTextInactive))
        bottom_bar_contracts.compoundDrawables[1].alpha = 120
        bottom_bar_home.compoundDrawables[1].alpha = 120
        bottom_bar_calculate.compoundDrawables[1].alpha = 120
        bottom_bar_more.compoundDrawables[1].alpha = 120
        bottom_bar_home.isClickable = true
        bottom_bar_calculate.isClickable = true
        bottom_bar_contracts.isClickable = true
        bottom_bar_more.isClickable = true
    }


Ответы

Ответов пока нет.