|
|
package com.br_technology.securitytrain_master.ui.view.home.activity
|
|
|
|
|
|
import android.Manifest
|
|
|
import android.app.Activity
|
|
|
import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.text.TextUtils
|
|
|
import android.view.View
|
|
|
import androidx.fragment.app.FragmentPagerAdapter
|
|
|
import com.br_technology.securitytrain_master.base.view.BasePagerAdapter
|
|
|
import com.br_technology.securitytrain_master.databinding.ActivitySearchBinding
|
|
|
import com.br_technology.securitytrain_master.ext.initPermissions
|
|
|
import com.br_technology.securitytrain_master.ui.bean.SearchEvent
|
|
|
import com.br_technology.securitytrain_master.ui.bean.SearchLog
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.adapter.HistoryAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.event.CheckSearchFace
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.fragment.ResultFragment
|
|
|
import com.br_technology.securitytrain_master.ui.view.home.viewmodel.SearchViewModel
|
|
|
import com.br_technology.securitytrain_master.util.CameraUtil
|
|
|
import com.br_technology.securitytrain_master.util.FaceUtil
|
|
|
import com.br_technology.securitytrain_master.util.company_is_check
|
|
|
import com.br_technology.securitytrain_master.view.DialogCheckIDCard
|
|
|
import com.br_technology.securitytrain_master.view.DialogSureCancel
|
|
|
import com.br_technology.securitytrain_master.view.DialogTrainLoading
|
|
|
import com.br_technology.securitytrain_master.view.listener.DialogListener
|
|
|
import com.br_technology.securitytrain_master.view.listener.OnItemClickListener
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
import java.io.File
|
|
|
|
|
|
/**
|
|
|
* createTime:2021/7/28 11:13
|
...
|
...
|
@@ -23,6 +36,81 @@ import org.greenrobot.eventbus.EventBus |
|
|
*/
|
|
|
class SearchActivity :
|
|
|
BaseLifeCycleActivity<SearchViewModel, ActivitySearchBinding>(ActivitySearchBinding::inflate) {
|
|
|
private var isCheckFace: Boolean = false
|
|
|
private var dialogId: DialogCheckIDCard? = null
|
|
|
private var permissionCount = 0
|
|
|
private var fileUploadTemp: File? = null
|
|
|
private val faceUtil = FaceUtil()
|
|
|
private var dialogLoading: DialogTrainLoading? = null
|
|
|
|
|
|
fun hasCheckFace(): Boolean {
|
|
|
return isCheckFace || company_is_check
|
|
|
}
|
|
|
|
|
|
private fun dialogLoading() {
|
|
|
if (dialogLoading == null) {
|
|
|
dialogLoading = DialogTrainLoading(this)
|
|
|
}
|
|
|
dialogLoading!!.show()
|
|
|
}
|
|
|
|
|
|
private fun dismissLoading() {
|
|
|
if (dialogLoading != null && dialogLoading!!.isShowing) {
|
|
|
dialogLoading!!.dismiss()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
if (requestCode == FaceUtil.FRONT_CAPTURE_CODE) {
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
permissionCount = 0
|
|
|
fileUploadTemp?.let {
|
|
|
faceUtil.compressFile(this, fileUploadTemp!!, object : FaceUtil.ICompress {
|
|
|
override fun compress(file: File) {
|
|
|
dialogLoading()
|
|
|
mViewModel.uploadFace(file.path)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
dismissLoading()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private fun showDialogId() {
|
|
|
if (dialogId == null) {
|
|
|
dialogId = DialogCheckIDCard(this)
|
|
|
dialogId!!.setListener({
|
|
|
dialogId!!.dismiss()
|
|
|
finish()
|
|
|
}, {
|
|
|
initPermissions(
|
|
|
Manifest.permission.CAMERA,
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
onGranted = {
|
|
|
if (permissionCount == 0) {
|
|
|
permissionCount++
|
|
|
if (CameraUtil.isSupportFrontCamera()) {
|
|
|
faceUtil.startCaptureFace(this, object : FaceUtil.ICapture {
|
|
|
override fun capture(file: File) {
|
|
|
fileUploadTemp = file
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
onDenied = {
|
|
|
dialogId!!.dismiss()
|
|
|
}, onDeniedNever = {
|
|
|
dialogId!!.dismiss()
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
dialogId!!.show()
|
|
|
}
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
binding.apply {
|
...
|
...
|
@@ -49,7 +137,8 @@ class SearchActivity : |
|
|
search.setOnClickListener {
|
|
|
// 点击搜索时隐藏历史记录
|
|
|
showData(true)
|
|
|
EventBus.getDefault().post(SearchEvent(searchEdit.text.toString()))
|
|
|
EventBus.getDefault()
|
|
|
.post(SearchEvent(searchEdit.text.toString(), viewPager.currentItem))
|
|
|
}
|
|
|
|
|
|
searchEdit.setOnClickListener {
|
...
|
...
|
@@ -75,6 +164,12 @@ class SearchActivity : |
|
|
viewPager.offscreenPageLimit = 3
|
|
|
tabLayout.setupWithViewPager(viewPager)
|
|
|
}
|
|
|
EventBus.getDefault().register(this)
|
|
|
}
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
|
EventBus.getDefault().unregister(this)
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
...
|
...
|
@@ -103,15 +198,55 @@ class SearchActivity : |
|
|
historyAdapter.addList(it.data.list)
|
|
|
historyAdapter.addListener(object : OnItemClickListener<SearchLog> {
|
|
|
override fun onClick(position: Int, data: SearchLog) {
|
|
|
EventBus.getDefault().post(SearchEvent(data.keyword))
|
|
|
binding.searchEdit.setText(data.keyword)
|
|
|
EventBus.getDefault()
|
|
|
.post(SearchEvent(data.keyword, binding.viewPager.currentItem))
|
|
|
showData(true)
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
mViewModel.clearData.observe(this, {
|
|
|
mViewModel.searchLog()
|
|
|
EventBus.getDefault().post(SearchEvent(""))
|
|
|
showData(true)
|
|
|
// EventBus.getDefault().post(SearchEvent("", binding.viewPager.currentItem))
|
|
|
// showData(true)
|
|
|
})
|
|
|
mViewModel.mFaceFile.observe(this, {
|
|
|
it.let {
|
|
|
if (!TextUtils.isEmpty(it.data.fullurl)) {
|
|
|
mViewModel.checkFace(it.data.fullurl)
|
|
|
} else {
|
|
|
showTip(it.msg)
|
|
|
if (dialogLoading != null) {
|
|
|
dialogLoading!!.dismiss()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
mViewModel.mFaceCheck.observe(this, {
|
|
|
if (dialogLoading != null) {
|
|
|
dialogLoading!!.dismiss()
|
|
|
}
|
|
|
it.let {
|
|
|
if (it.code == 1) {
|
|
|
if (dialogId != null) {
|
|
|
dialogId!!.dismiss()
|
|
|
}
|
|
|
isCheckFace = true
|
|
|
} else {
|
|
|
finish()
|
|
|
showTip(it.msg)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
fun getCurrentIndex(): SearchEvent {
|
|
|
return SearchEvent(binding.searchEdit.text.toString(), binding.viewPager.currentItem)
|
|
|
}
|
|
|
|
|
|
@Subscribe
|
|
|
public fun searchFace(data: CheckSearchFace) {
|
|
|
showDialogId()
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|