|
|
package com.br_technology.securitytrain_master.ui.view.mine.activity
|
|
|
|
|
|
import android.graphics.Color
|
|
|
import android.view.View
|
|
|
import android.widget.TimePicker
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.bigkoo.pickerview.builder.TimePickerBuilder
|
|
|
import com.bigkoo.pickerview.configure.PickerOptions
|
|
|
import com.bigkoo.pickerview.listener.OnTimeSelectListener
|
|
|
import com.bigkoo.pickerview.view.TimePickerView
|
|
|
import com.br_technology.securitytrain_master.R
|
|
|
import com.br_technology.securitytrain_master.databinding.ActivityCredentialsUploadBinding
|
|
|
import com.br_technology.securitytrain_master.expand.dp2px
|
|
|
import com.br_technology.securitytrain_master.expand.loadPicNoCrop
|
|
|
import com.br_technology.securitytrain_master.expand.screenWidth
|
|
|
import com.br_technology.securitytrain_master.ui.bean.CertType
|
|
|
import com.br_technology.securitytrain_master.ui.bean.UserCertDetail
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.adapter.CertTypeAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.viewmodel.CredentialsUpLoadViewModel
|
|
|
import com.br_technology.securitytrain_master.util.GlideEnginePic
|
|
|
import com.br_technology.securitytrain_master.util.PoPWindowUtil
|
|
|
import com.br_technology.securitytrain_master.view.CenterToast
|
|
|
import com.google.gson.Gson
|
|
|
import com.luck.picture.lib.PictureSelector
|
|
|
import com.luck.picture.lib.config.PictureMimeType
|
|
|
import com.luck.picture.lib.entity.LocalMedia
|
|
|
import com.luck.picture.lib.listener.OnResultCallbackListener
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
|
|
|
import java.text.DateFormat
|
|
|
import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -28,39 +34,118 @@ import java.util.* |
|
|
class CredentialsUpLoadActivity :
|
|
|
BaseLifeCycleActivity<CredentialsUpLoadViewModel, ActivityCredentialsUploadBinding>(
|
|
|
ActivityCredentialsUploadBinding::inflate
|
|
|
), View.OnClickListener {
|
|
|
) {
|
|
|
|
|
|
private var path: String = ""
|
|
|
private var dateTime: String = ""
|
|
|
private var typeId: Int = 0
|
|
|
private var id: Int? = 0
|
|
|
private var endTime: String? = ""
|
|
|
private val certTypeAdapter: CertTypeAdapter by lazy {
|
|
|
CertTypeAdapter()
|
|
|
}
|
|
|
|
|
|
override fun initDataObserver() {
|
|
|
|
|
|
mViewModel.liveData.observe(this) {
|
|
|
certTypeAdapter.setNewInstance(it.data.list as MutableList<CertType>)
|
|
|
}
|
|
|
mViewModel.picLiveData.observe(this) {
|
|
|
// 图片地址
|
|
|
path = it.data.fullurl
|
|
|
}
|
|
|
mViewModel.certLiveData.observe(this) {
|
|
|
// 根据类型跳转
|
|
|
binding.tvUpload.isClickable = true
|
|
|
val title = CenterToast(this).setTitle("上传成功")
|
|
|
title.setOnDismissListener {
|
|
|
finish()
|
|
|
}
|
|
|
title.show()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
|
|
|
mViewModel.certClassify()
|
|
|
|
|
|
val json = intent.getStringExtra("json")
|
|
|
if (json?.isNotEmpty() == true) {
|
|
|
val user = Gson().fromJson<UserCertDetail>(json, UserCertDetail::class.java)
|
|
|
// 证件类型id
|
|
|
typeId = user.cert.id
|
|
|
// 证件照片地址
|
|
|
path = user.image_text
|
|
|
// 开始时间
|
|
|
dateTime = user.start_time
|
|
|
// 证件id
|
|
|
id = user.id
|
|
|
// 结束时间
|
|
|
endTime = user.end_time
|
|
|
// 适配宽度
|
|
|
val width = mRootView.screenWidth() - 64.dp2px()
|
|
|
binding.uploadPic.loadPicNoCrop(path, width, 208.dp2px())
|
|
|
// 开始时间
|
|
|
binding.uploadTime.text = dateTime
|
|
|
// 证件名称
|
|
|
binding.certTypeTv.text = user.cert.name
|
|
|
}
|
|
|
|
|
|
id = if (id == 0) {
|
|
|
null
|
|
|
} else {
|
|
|
id
|
|
|
}
|
|
|
endTime = if (endTime?.isEmpty() == true) {
|
|
|
null
|
|
|
} else {
|
|
|
endTime
|
|
|
}
|
|
|
binding.apply {
|
|
|
tvUpload.setOnClickListener(this@CredentialsUpLoadActivity)
|
|
|
// 上传照片
|
|
|
tvUpload.setOnClickListener {
|
|
|
tvUpload.isClickable = false
|
|
|
if (path.isEmpty()) {
|
|
|
showTip("请选择证件照片")
|
|
|
tvUpload.isClickable = true
|
|
|
return@setOnClickListener
|
|
|
}
|
|
|
if (typeId == 0) {
|
|
|
tvUpload.isClickable = true
|
|
|
showTip("请选择证件类型")
|
|
|
return@setOnClickListener
|
|
|
}
|
|
|
if (dateTime.isEmpty()) {
|
|
|
tvUpload.isClickable = true
|
|
|
showTip("请选择证件开始时间")
|
|
|
return@setOnClickListener
|
|
|
}
|
|
|
mViewModel.certAdd(id, typeId, path, dateTime, endTime)
|
|
|
}
|
|
|
|
|
|
// 选择图片
|
|
|
uploadPic.setOnClickListener {
|
|
|
|
|
|
selectPicture()
|
|
|
// PictureSelector.create(this@CredentialsUpLoadActivity)
|
|
|
}
|
|
|
// 选择时间
|
|
|
selectionPeriod.setOnClickListener {
|
|
|
selectTime()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// // 根据类型跳转
|
|
|
// CenterToast(this@MyCredentialsActivity).setTitle("上传成功").show()
|
|
|
// 选择证件类型
|
|
|
selectType.setOnClickListener {
|
|
|
val initPopWindow = PoPWindowUtil.get()
|
|
|
.initPopWindow(baseContext, selectType, R.layout.dialog_cert_type)
|
|
|
val certRv = initPopWindow.findViewById<RecyclerView>(R.id.cert_rv)
|
|
|
certRv.adapter = certTypeAdapter
|
|
|
}
|
|
|
|
|
|
override fun onClick(v: View?) {
|
|
|
when (v?.id) {
|
|
|
R.id.tv_upload -> {
|
|
|
|
|
|
}
|
|
|
|
|
|
certTypeAdapter.setOnItemClickListener { _, _, position ->
|
|
|
val certType = certTypeAdapter.data[position]
|
|
|
binding.certTypeTv.text = certType.name
|
|
|
typeId = certType.id
|
|
|
PoPWindowUtil.get().dismissPoPWindow()
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -71,24 +156,28 @@ class CredentialsUpLoadActivity : |
|
|
.imageEngine(GlideEnginePic.createGlideEngine())
|
|
|
.forResult(object : OnResultCallbackListener<LocalMedia> {
|
|
|
override fun onResult(result: MutableList<LocalMedia>?) {
|
|
|
path = result?.get(0)?.realPath ?: ""
|
|
|
val path = result?.get(0)?.realPath ?: ""
|
|
|
if (path.isNotEmpty()) {
|
|
|
binding.uploadPic.loadPicNoCrop(path, width, 208.dp2px())
|
|
|
mViewModel.uploadFile(path)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onCancel() {
|
|
|
}
|
|
|
override fun onCancel() {}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
private fun selectTime() {
|
|
|
TimePickerBuilder(baseContext, object : OnTimeSelectListener {
|
|
|
override fun onTimeSelect(date: Date?, v: View?) {
|
|
|
|
|
|
}
|
|
|
}).build().show()
|
|
|
TimePickerBuilder(this) { date, _ ->
|
|
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
|
|
val format = dateFormat.format(date)
|
|
|
dateTime = format
|
|
|
binding.uploadTime.text = format
|
|
|
}.setTitleText("选择日期")
|
|
|
.setTitleBgColor(Color.parseColor("#ffffff"))
|
|
|
.setCancelColor(Color.parseColor("#000000"))
|
|
|
.setSubmitColor(Color.parseColor("#000000"))
|
|
|
.build().show()
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|