From 979d9cff22806f213b420452ab4a68fcbaf021b6 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 31 五月 2021 17:43:49 +0800
Subject: [PATCH] 1. 修复多项可能引起空指针崩溃的bug; 2. 新建子任务时默认执行人员从全体人员改为当前用户; 3. 新建子任务时默认执行时间强制固定为总任务对应的时段内,确保子任务执行时间不会超出总任务范围。
---
app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt | 131 ++++++++++++++++++++++++++++++++-----------
1 files changed, 97 insertions(+), 34 deletions(-)
diff --git a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt
index 44ef3d9..82a55a5 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt
@@ -1,5 +1,6 @@
package cn.flightfeather.thirdapp.module.inspection
+import android.annotation.SuppressLint
import android.app.Activity
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
@@ -8,15 +9,18 @@
import android.os.Environment
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
+import android.view.LayoutInflater
import android.view.View
+import android.widget.ImageView
+import android.widget.TextView
import cn.flightfeather.thirdapp.R
import cn.flightfeather.thirdapp.activity.PhotoViewerActivity
import cn.flightfeather.thirdapp.adapter.PhotoListAdapter
import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener
-import cn.flightfeather.thirdapp.bean.Inspection
-import cn.flightfeather.thirdapp.bean.Mediafile
-import cn.flightfeather.thirdapp.bean.Scense
-import cn.flightfeather.thirdapp.bean.Subtask
+import cn.flightfeather.thirdapp.bean.entity.Inspection
+import cn.flightfeather.thirdapp.bean.entity.Mediafile
+import cn.flightfeather.thirdapp.bean.entity.Scense
+import cn.flightfeather.thirdapp.bean.entity.Subtask
import cn.flightfeather.thirdapp.model.enumreation.MediaFileType
import cn.flightfeather.thirdapp.module.base.BaseActivity
import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity
@@ -26,7 +30,10 @@
import cn.flightfeather.thirdapp.util.UUIDGenerator
import cn.flightfeather.thirdapp.util.file.FileUtil
import cn.flightfeather.thirdapp.util.photo.PhotoUtil
+import cn.flightfeather.thirdapp.view.SearchView
import kotlinx.android.synthetic.main.dialog_camera.*
+import kotlinx.android.synthetic.main.dialog_camera.fab_problem_list_close
+import kotlinx.android.synthetic.main.dialog_camera_3.*
import org.jetbrains.anko.toast
import java.io.File
import java.io.IOException
@@ -37,15 +44,20 @@
const val BUSINESS_TYPE_CAMERA = 5
class MenuCameraActivity : BaseActivity() {
- override fun getLayoutId(): Int = R.layout.dialog_camera
+ override fun getLayoutId(): Int = R.layout.dialog_camera_3
//椤甸潰鏀寔鐨勬媿鎽勫浘鐗囩被鍨�
private val typeList = listOf(MediaFileType.RoutineRecord, MediaFileType.Nameplate, MediaFileType.MonitorDevice)
//褰撳墠閫夋嫨鐨勬媿鐓х被鍨�
private var currentType = MediaFileType.RoutineRecord
+ private var currentTypeName = currentType.des
lateinit var viewModel: MenuCameraViewModel
+
+ private val viewList = mutableListOf<View>()
+
+ private val listMap = mutableMapOf<MediaFileType, RecyclerView>()
var subTask: Subtask? = null
var inspection: Inspection? = null
@@ -66,7 +78,11 @@
initUI()
initObserver()
- inspection?.guid?.let { viewModel.getMediaFile(it) }
+ inspection?.guid?.let {guid ->
+ scene?.typeid?.let { typeId ->
+ viewModel.getMediaFile(guid, typeId.toInt())
+ }
+ }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -79,7 +95,9 @@
val oldFile = File(it)
val cal = Calendar.getInstance().apply { time = subTask?.executionstarttime }
scene?.run {
- val path = "FlightFeather/Photo/" + districtname + "/"+ cal.get(Calendar.YEAR) + "骞�" + (cal.get(Calendar.MONTH) + 1) + "鏈�/"+ (cal.get(Calendar.MONTH) + 1) + "鏈�" + cal.get(Calendar.DAY_OF_MONTH) + "鏃�/"+ name + "/浠绘剰鎷嶇収/"
+ val path = "FlightFeather/Photo/" + districtname + "/" + cal.get(Calendar.YEAR) + "骞�" + (cal.get(Calendar.MONTH) + 1) + "鏈�/" +
+ (cal.get(Calendar.MONTH) + 1) + "鏈�" + cal.get(Calendar.DAY_OF_MONTH) + "鏃�/" + name + "/浠绘剰鎷嶇収/" + currentTypeName + "/"
+
val fileName = UUIDGenerator.generateUUID(4) + ".jpg"
val newFile = File(Environment.getExternalStorageDirectory(), path + fileName)
if (!newFile.parentFile.exists()) {
@@ -106,24 +124,40 @@
}
private fun initUI() {
- typeList.forEach {
- getDataSet(it).run {
- initRecyclerView(first.value, second, it)
- }
- }
+// typeList.forEach {
+// getDataSet(it).run {
+// initRecyclerView(first.value, second, it)
+// }
+// }
fab_problem_list_close.setOnClickListener {
finish()
}
}
- private fun initRecyclerView(dataList: MutableList<Mediafile>?, recyclerView: RecyclerView, type: MediaFileType) {
- if (dataList==null) return
- recyclerView.run {
+ @SuppressLint("SetTextI18n")
+ private fun initRecyclerView(dataList: List<Mediafile>?, type: MediaFileType, alias: String?) {
+ if (dataList == null) return
+ val view = LayoutInflater.from(this).inflate(R.layout.item_take_photo, null)
+ val searchView = view.findViewById<SearchView>(R.id.search_view)
+ val title = view.findViewById<TextView>(R.id.txt_title)
+ searchView.onConfirm = { str ->
+ scene?.typeid?.let {
+ viewModel.updateAlias(it.toInt(), type, str) { alias ->
+ title.text = if (alias.isBlank()) type.des else "${alias}(${type.des})"
+ }
+ }
+ }
+ title.text = if (alias.isNullOrBlank()) type.des else "${alias}(${type.des})"
+ view.findViewById<ImageView>(R.id.img_edit).setOnClickListener {
+ searchView.show(type.des, alias ?: "")
+ }
+ view.findViewById<RecyclerView>(R.id.rv_photo_list).run {
layoutManager = GridLayoutManager(this@MenuCameraActivity, 4)
adapter = PhotoListAdapter(dataList, this@MenuCameraActivity)
addOnItemTouchListener(RecyclerItemClickListener(this@MenuCameraActivity, this, object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(view: View?, position: Int) {
currentType = type
+ currentTypeName = title.text.toString()
//鎷嶇収
if (dataList[position].guid == null) {
PhotoUtil.pickPhoto2(this@MenuCameraActivity, TAKE_PHOTO, 9)
@@ -153,29 +187,42 @@
}
}))
+
+ if (!listMap.containsKey(type)) {
+ listMap[type] = this
+ }
}
+
+ viewList.add(view)
}
private fun initObserver() {
- typeList.forEach {
- getDataSet(it).run {
- first.observe(this@MenuCameraActivity, Observer {list->
- list?.let {
- second.adapter?.notifyDataSetChanged()
- }
- })
+ viewModel.fileList.observe(this, Observer {
+ it?.forEach { m ->
+ initRecyclerView(m.dataList, m.type ?: MediaFileType.Others, m.alias)
}
- }
+ if (viewList.isNotEmpty()) {
+ banner.dataList = viewList
+ }
+ })
+// typeList.forEach {
+// getDataSet(it).run {
+// first.observe(this@MenuCameraActivity, Observer {list->
+// list?.let {
+// second.adapter?.notifyDataSetChanged()
+// }
+// })
+// }
+// }
}
- private fun putMediaFile(path: String, fileName: String, calendar: Calendar):Mediafile {
+ private fun putMediaFile(path: String, fileName: String, calendar: Calendar): Mediafile {
val mediaFile = Mediafile()
mediaFile.guid = UUIDGenerator.generate16ShortUUID()
mediaFile.iguid = inspection?.guid
mediaFile.longitude = lng
mediaFile.latitude = lat
- mediaFile.address = "${scene?.cityname ?: ""} + ${scene?.districtname
- ?: ""} + ${scene?.townname ?: ""} + ${scene?.location ?: ""}"
+ mediaFile.address = "${scene?.cityname ?: ""}${scene?.districtname ?: ""}${scene?.townname ?: ""}${scene?.location ?: ""}"
mediaFile.filetype = 1
mediaFile.businesstype = currentType.des
mediaFile.businesstypeid = currentType.value.toByte()
@@ -193,21 +240,37 @@
}
private fun addPhoto(mediaFile: Mediafile) {
- getDataSet(currentType).run {
- first.value?.add(mediaFile)
- second.adapter?.run {
- notifyDataSetChanged()
+ if (listMap.containsKey(currentType)) {
+ viewModel.fileList.value?.forEach {
+ if (it.type == currentType) {
+ it.dataList.add(mediaFile)//绗竴涓暟鎹负鎷嶇収鎸夐挳
+ listMap[currentType]?.adapter?.notifyDataSetChanged()
+ }
}
}
+// getDataSet(currentType).run {
+// first.value?.add(mediaFile)
+// second.adapter?.run {
+// notifyDataSetChanged()
+// }
+// }
}
private fun deletePhoto(pos: Int) {
- getDataSet(currentType).run {
- first.value?.removeAt(pos + 1)//绗竴涓暟鎹负鎷嶇収鎸夐挳
- second.adapter?.run {
- notifyDataSetChanged()
+ if (listMap.containsKey(currentType)) {
+ viewModel.fileList.value?.forEach {
+ if (it.type == currentType) {
+ it.dataList.removeAt(pos + 1)//绗竴涓暟鎹负鎷嶇収鎸夐挳
+ listMap[currentType]?.adapter?.notifyDataSetChanged()
+ }
}
}
+// getDataSet(currentType).run {
+// first.value?.removeAt(pos + 1)//绗竴涓暟鎹负鎷嶇収鎸夐挳
+// second.adapter?.run {
+// notifyDataSetChanged()
+// }
+// }
}
private fun getDataSet(type: MediaFileType) = when (type) {
--
Gitblit v1.9.3