| | |
| | | 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.bean.entity.* |
| | | import cn.flightfeather.thirdapp.model.event.ProblemEvent |
| | | import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity |
| | | import cn.flightfeather.thirdapp.util.DateFormatter |
| | |
| | | import java.io.IOException |
| | | import java.util.* |
| | | |
| | | class MenuEvidenceActivity : BaseTakePicActivity() { |
| | | open 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 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 |
| | | |
| | |
| | | var lat = 0.0 |
| | | var lng = 0.0 |
| | | |
| | | protected var submitTime = 0L//提交时间,防止连续提交,多次记录 |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | |
| | | |
| | | viewModel = ViewModelProviders.of(this).get(MenuEvidenceViewModel::class.java) |
| | | |
| | | getExtra() |
| | | initUI() |
| | | initObserver() |
| | | |
| | | viewModel.getLocationList() |
| | | subTask?.let { t -> |
| | | scene?.let { s -> |
| | | viewModel.getProblemType(t.typeno, t.citycode, t.districtcode, s.typeid) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | open fun getExtra() { |
| | | 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() { |
| | |
| | | } |
| | | |
| | | fab_take_evidence_ok.setOnClickListener { |
| | | it.isClickable = false |
| | | putProblem() |
| | | val now = Date() |
| | | if (now.time - submitTime >= 1000) { |
| | | submitTime = now.time |
| | | putProblem() |
| | | } |
| | | } |
| | | |
| | | fab_take_evidence_close.setOnClickListener { |
| | |
| | | } |
| | | } |
| | | |
| | | private fun updateUIByProblemType(visible: Int) { |
| | | open fun initObserver() { |
| | | 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) |
| | | onSuggestionLoaded() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | open fun onSuggestionLoaded() { |
| | | |
| | | } |
| | | |
| | | protected fun updateUIByProblemType(visible: Int) { |
| | | sp_take_evidence_select_location.visibility = visible |
| | | et_take_evidence_location.visibility = visible |
| | | iv_take_evidence_add_photo1.visibility = visible |
| | |
| | | } |
| | | |
| | | private fun putProblem() { |
| | | val problemType = sp_take_evidence_select_problem_type.selectedItem.toString() |
| | | if (inspection == null || subTask == null || scene == null) { |
| | | toast("当前巡查状态错误,无法上传问题,请尝试重新启动") |
| | | } |
| | | |
| | | val problemType = sp_take_evidence_select_problem_type.selectedItem?.toString() |
| | | |
| | | val pro = Problemlist().apply { |
| | | guid = UUIDGenerator.generate16ShortUUID() |
| | |
| | | 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() |
| | | 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() |
| | | var adviceDes = et_take_evidence_suggestion?.text.toString() |
| | | if (adviceDes.isNotEmpty()) { |
| | | adviceDes = "($adviceDes)" |
| | | } |
| | | advise = sp_take_evidence_select_suggestion.selectedItem.toString() + 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()) { |
| | | var locationRemark = et_take_evidence_location.text?.toString() |
| | | if (locationRemark?.isNotEmpty() == true) { |
| | | locationRemark = "($locationRemark)" |
| | | } |
| | | locationid = l.index.toByte() |
| | |
| | | if (problemType != "态度" && pathTempList.isNotEmpty()) { |
| | | viewModel.putProblem(pro) |
| | | putMediaFile(pro) |
| | | }else if (problemType == "态度") { |
| | | } else if (problemType == "态度") { |
| | | viewModel.putProblem(pro) |
| | | } else { |
| | | application.toast("至少拍一张照片") |
| | |
| | | } |
| | | } |
| | | |
| | | private fun putMediaFile(problem: Problemlist) { |
| | | protected fun putMediaFile(problem: Problemlist) { |
| | | //保存照片到对应文件夹 |
| | | val savePathList = ArrayList<File>() |
| | | val calendar = java.util.Calendar.getInstance() |
| | |
| | | fileNameList.add(fileName3) |
| | | |
| | | for (i in pathTempList.indices) { |
| | | val oldFile = pathTempList[i] |
| | | //过滤不需要上传的图片 |
| | | if (!pathTempList[i].second) { |
| | | continue |
| | | } |
| | | val oldFile = pathTempList[i].first |
| | | val newFile = savePathList[i] |
| | | //保存到mediaFile数据库 |
| | | val mediaFile = Mediafile() |
| | |
| | | } |
| | | |
| | | //清除拍照取证的缓存 |
| | | fun clearTemp() { |
| | | private fun clearTemp() { |
| | | for (i in pathTempList.indices) { |
| | | val file = pathTempList[i] |
| | | if (file.exists()) { |
| | | file.delete() |
| | | //需要上传的图片才是在本地拍摄的,带有缓存 |
| | | if (pathTempList[i].second) { |
| | | val file = pathTempList[i].first |
| | | if (file.exists()) { |
| | | file.delete() |
| | | } |
| | | } |
| | | } |
| | | } |