feiyu02
2020-09-01 43242c8e7915b968bb7a6f3f22bded7704f0e40f
app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuEvidenceActivity.kt
@@ -27,12 +27,11 @@
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
@@ -44,6 +43,7 @@
    var lat = 0.0
    var lng = 0.0
    protected var submitTime = 0L//提交时间,防止连续提交,多次记录
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
@@ -53,46 +53,25 @@
        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() {
@@ -122,8 +101,11 @@
        }
        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 {
@@ -131,7 +113,33 @@
        }
    }
    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)
            }
        })
    }
    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
@@ -141,6 +149,10 @@
    }
    private fun putProblem() {
        if (inspection == null || subTask == null || scene == null) {
            toast("当前巡查状态错误,无法上传问题,请尝试重新启动")
        }
        val problemType = sp_take_evidence_select_problem_type.selectedItem.toString()
        val pro = Problemlist().apply {
@@ -150,6 +162,7 @@
            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
@@ -191,7 +204,7 @@
        if (problemType != "态度" && pathTempList.isNotEmpty()) {
            viewModel.putProblem(pro)
            putMediaFile(pro)
        }else if (problemType == "态度") {
        } else if (problemType == "态度") {
            viewModel.putProblem(pro)
        } else {
            application.toast("至少拍一张照片")
@@ -199,7 +212,7 @@
        }
    }
    private fun putMediaFile(problem: Problemlist) {
    protected fun putMediaFile(problem: Problemlist) {
        //保存照片到对应文件夹
        val savePathList = ArrayList<File>()
        val calendar = java.util.Calendar.getInstance()
@@ -223,7 +236,11 @@
        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()
@@ -261,11 +278,14 @@
    }
    //清除拍照取证的缓存
    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()
                }
            }
        }
    }