package cn.flightfeather.thirdapp.module.inspection
|
|
import android.arch.lifecycle.Observer
|
import android.arch.lifecycle.ViewModelProviders
|
import android.os.Bundle
|
import android.os.Environment
|
import android.view.View
|
import android.view.WindowManager
|
import android.widget.AdapterView
|
import android.widget.ArrayAdapter
|
import android.widget.ImageView
|
import cn.flightfeather.thirdapp.R
|
import cn.flightfeather.thirdapp.adapter.DomainItemListAdapter
|
import cn.flightfeather.thirdapp.adapter.ProblemTypeListAdapter
|
import cn.flightfeather.thirdapp.bean.*
|
import cn.flightfeather.thirdapp.model.event.ProblemEvent
|
import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity
|
import cn.flightfeather.thirdapp.util.DateFormatter
|
import cn.flightfeather.thirdapp.util.Domain
|
import cn.flightfeather.thirdapp.util.UUIDGenerator
|
import cn.flightfeather.thirdapp.util.file.FileUtil
|
import kotlinx.android.synthetic.main.dialog_take_evidence.*
|
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.Subscribe
|
import org.jetbrains.anko.toast
|
import java.io.File
|
import java.io.IOException
|
import java.util.*
|
|
class MenuEvidenceActivity : BaseTakePicActivity() {
|
|
override fun getLayoutId(): Int = R.layout.dialog_take_evidence
|
|
override fun getImageViews(): MutableList<ImageView>
|
= mutableListOf(iv_take_evidence_add_photo1, iv_take_evidence_add_photo2, iv_take_evidence_add_photo3)
|
|
override val picDeletable: Boolean = true
|
|
lateinit var viewModel: MenuEvidenceViewModel
|
|
var subTask: Subtask? = null
|
var inspection: Inspection? = null
|
var scene: Scense? = null
|
var lat = 0.0
|
var lng = 0.0
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
|
EventBus.getDefault().register(this)
|
|
viewModel = ViewModelProviders.of(this).get(MenuEvidenceViewModel::class.java)
|
|
subTask = intent.getSerializableExtra("subTask") as Subtask?
|
inspection = intent.getSerializableExtra("inspection") as Inspection?
|
scene = intent.getSerializableExtra("scene") as Scense?
|
lat = intent.getDoubleExtra("lat", 0.0)
|
lng = intent.getDoubleExtra("lng", 0.0)
|
|
|
initUI()
|
|
viewModel.locationList.observe(this, Observer {
|
it?.let {
|
sp_take_evidence_select_location.adapter = DomainItemListAdapter(it, this)
|
}
|
})
|
|
viewModel.problemFatherType.observe(this, Observer {
|
it?.let {
|
sp_take_evidence_select_problem_type.adapter = ArrayAdapter(this, R.layout.item_spinner_drop_down, it)
|
}
|
})
|
|
viewModel.problemType.observe(this, Observer {
|
it?.let {
|
sp_take_evidence_select_problem.adapter = ProblemTypeListAdapter(it, this)
|
}
|
})
|
|
viewModel.suggestionList.observe(this, Observer {
|
it.let {
|
sp_take_evidence_select_suggestion.adapter = ArrayAdapter(this, R.layout.item_spinner_drop_down, it)
|
}
|
})
|
|
viewModel.getLocationList()
|
subTask?.let {t ->
|
scene?.let {s ->
|
viewModel.getProblemType(t.typeno, t.citycode, t.districtcode, s.typeid)
|
}
|
}
|
|
}
|
|
private fun initUI() {
|
sp_take_evidence_select_problem_type.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
viewModel.refreshProblems(viewModel.problemFatherType.value?.get(position))
|
|
viewModel.problemFatherType.value?.let {
|
if (it[position] == "态度") {
|
updateUIByProblemType(View.GONE)
|
} else {
|
updateUIByProblemType(View.VISIBLE)
|
}
|
}
|
sp_take_evidence_select_problem.setSelection(0)
|
|
viewModel.problemType.value?.get(0)?.guid?.let { viewModel.getSuggestionList(it) }
|
}
|
}
|
|
sp_take_evidence_select_problem.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
override fun onNothingSelected(parent: AdapterView<*>?) = Unit
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
viewModel.problemType.value?.get(position)?.guid?.let { viewModel.getSuggestionList(it) }
|
}
|
}
|
|
fab_take_evidence_ok.setOnClickListener {
|
it.isClickable = false
|
putProblem()
|
}
|
|
fab_take_evidence_close.setOnClickListener {
|
finish()
|
}
|
}
|
|
private fun updateUIByProblemType(visible: Int) {
|
sp_take_evidence_select_location.visibility = visible
|
et_take_evidence_location.visibility = visible
|
iv_take_evidence_add_photo1.visibility = visible
|
iv_take_evidence_add_photo2.visibility = visible
|
iv_take_evidence_add_photo3.visibility = visible
|
tv_location.visibility = visible
|
}
|
|
private fun putProblem() {
|
val problemType = sp_take_evidence_select_problem_type.selectedItem.toString()
|
|
val pro = Problemlist().apply {
|
guid = UUIDGenerator.generate16ShortUUID()
|
iguid = inspection?.guid
|
stguid = subTask?.stguid
|
sguid = scene?.guid
|
sensename = scene?.name
|
senseaddress = "${scene?.cityname ?: ""}${scene?.districtname ?: ""}${scene?.townname ?: ""}${scene?.location ?: ""}"
|
val p = sp_take_evidence_select_problem.selectedItem
|
if (p is Problemtype) {
|
ptguid = p.guid
|
var problemDes = et_take_evidence_problem_des.text.toString()
|
if (problemDes.isNotEmpty()) {
|
problemDes = "($problemDes)"
|
}
|
problemname = p.name + problemDes
|
}
|
|
var adviceDes = et_take_evidence_suggestion.text.toString()
|
if (adviceDes.isNotEmpty()) {
|
adviceDes = "($adviceDes)"
|
}
|
advise = sp_take_evidence_select_suggestion.selectedItem.toString() + adviceDes
|
latitude = lat
|
longitude = lng
|
|
val l = sp_take_evidence_select_location.selectedItem
|
if (l is Domainitem) {
|
if (problemType != "态度") {
|
var locationRemark = et_take_evidence_location.text.toString()
|
if (locationRemark.isNotEmpty()) {
|
locationRemark = "($locationRemark)"
|
}
|
locationid = l.index.toByte()
|
location = l.text + locationRemark
|
} else {
|
location = "无位置"
|
}
|
}
|
|
time = Date()
|
isrechecked = false
|
ischanged = false
|
extension3 = Domain.PROBLEM_UNCHECKED// 2020/4/2 添加问题默认状态为未审核,此时被监管企业不会看到问题
|
}
|
|
if (problemType != "态度" && pathTempList.isNotEmpty()) {
|
viewModel.putProblem(pro)
|
putMediaFile(pro)
|
}else if (problemType == "态度") {
|
viewModel.putProblem(pro)
|
} else {
|
application.toast("至少拍一张照片")
|
fab_take_evidence_ok.isClickable = true
|
}
|
}
|
|
private fun putMediaFile(problem: Problemlist) {
|
//保存照片到对应文件夹
|
val savePathList = ArrayList<File>()
|
val calendar = java.util.Calendar.getInstance()
|
calendar.time = subTask?.executionstarttime ?: Date()
|
val path = "FlightFeather/Photo/" + scene?.districtname + "/" + calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONTH) + 1) + "月/" + (calendar.get(Calendar.MONTH) + 1) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日/" + scene?.name + "/"
|
val fileName1 = problem.problemname + " " + problem.location + " " + UUIDGenerator.generateUUID(4) + ".jpg"
|
val fileName2 = problem.problemname + " " + problem.location + " " + UUIDGenerator.generateUUID(4) + ".jpg"
|
val fileName3 = problem.problemname + " " + problem.location + " " + UUIDGenerator.generateUUID(4) + ".jpg"
|
val photo1 = File(Environment.getExternalStorageDirectory(), path + fileName1)
|
val photo2 = File(Environment.getExternalStorageDirectory(), path + fileName2)
|
val photo3 = File(Environment.getExternalStorageDirectory(), path + fileName3)
|
photo1.parentFile.mkdirs()
|
|
savePathList.add(photo1)
|
savePathList.add(photo2)
|
savePathList.add(photo3)
|
|
val fileNameList = ArrayList<String>()
|
fileNameList.add(fileName1)
|
fileNameList.add(fileName2)
|
fileNameList.add(fileName3)
|
|
for (i in pathTempList.indices) {
|
val oldFile = pathTempList[i]
|
val newFile = savePathList[i]
|
//保存到mediaFile数据库
|
val mediaFile = Mediafile()
|
mediaFile.guid = UUIDGenerator.generate16ShortUUID()
|
mediaFile.iguid = inspection?.guid
|
mediaFile.businessguid = problem.guid
|
mediaFile.longitude = lng
|
mediaFile.latitude = lat
|
mediaFile.address = problem.senseaddress
|
mediaFile.filetype = 1
|
mediaFile.businesstype = "问题"
|
mediaFile.businesstypeid = 1
|
mediaFile.path = path
|
mediaFile.description = fileNameList[i]
|
mediaFile.savetime = Date()
|
mediaFile.ischanged = false
|
val exetension1 = scene?.citycode + "/" + scene?.districtcode + "/" + DateFormatter.dateFormat2.format(calendar.time) + "/" + scene?.guid + "/"
|
mediaFile.extension1 = exetension1
|
mediaFile.remark = "未上传"
|
|
viewModel.putMediaFile(mediaFile)
|
|
try {
|
FileUtil.copyFile(oldFile, newFile)
|
} catch (e: IOException) {
|
e.printStackTrace()
|
}
|
}
|
}
|
|
@Subscribe
|
fun onPutProblem(problemEvent: ProblemEvent) {
|
clearTemp()
|
finish()
|
}
|
|
//清除拍照取证的缓存
|
fun clearTemp() {
|
for (i in pathTempList.indices) {
|
val file = pathTempList[i]
|
if (file.exists()) {
|
file.delete()
|
}
|
}
|
}
|
}
|