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 | 208 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 161 insertions(+), 47 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 c802e61..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
@@ -7,16 +8,20 @@
import android.os.Bundle
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.fragment.InspectionFragment.intToByte
+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
import cn.flightfeather.thirdapp.module.base.TAKE_PHOTO
@@ -25,20 +30,34 @@
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
import java.io.Serializable
import java.util.*
+import kotlin.collections.ArrayList
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
@@ -57,17 +76,13 @@
lng = intent.getDoubleExtra("lng", 0.0)
initUI()
+ initObserver()
- viewModel.mediaFileList.observe(this, Observer {
- it?.let {
- rv_photo_list.adapter?.notifyDataSetChanged()
-
- val t = "鍏�${it.size}寮犵収鐗�"
- tv_count.text = t
+ inspection?.guid?.let {guid ->
+ scene?.typeid?.let { typeId ->
+ viewModel.getMediaFile(guid, typeId.toInt())
}
- })
-
- inspection?.guid?.let { viewModel.getMediaFile(it) }
+ }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -80,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()) {
@@ -88,73 +105,127 @@
}
try {
FileUtil.copyFile(oldFile, newFile)
- putMediaFile(path, fileName, cal)
+ val mf = putMediaFile(path, fileName, cal)
+ addPhoto(mf)
} catch (e: IOException) {
e.printStackTrace()
application.toast("澶嶅埗鏂囦欢澶辫触")
}
}
}
- inspection?.guid?.let { viewModel.getMediaFile(it) }
}
VIEW_PHOTO -> {
//鏌ョ湅涓存椂鎷嶆憚鍥剧墖鍙互鍒犻櫎
data?.getIntExtra("position", -1)?.let {
- viewModel.mediaFileList.value?.removeAt(it)
- rv_photo_list.adapter?.run {
- notifyDataSetChanged()
- }
+ deletePhoto(it)
}
}
}
}
private fun initUI() {
- rv_photo_list.run {
+// typeList.forEach {
+// getDataSet(it).run {
+// initRecyclerView(first.value, second, it)
+// }
+// }
+ fab_problem_list_close.setOnClickListener {
+ finish()
+ }
+ }
+
+ @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(viewModel.mediaFileList.value, this@MenuCameraActivity)
+ adapter = PhotoListAdapter(dataList, this@MenuCameraActivity)
addOnItemTouchListener(RecyclerItemClickListener(this@MenuCameraActivity, this, object : RecyclerItemClickListener.OnItemClickListener {
override fun onItemClick(view: View?, position: Int) {
- val files = ArrayList<File>()
- for (m in viewModel.mediaFileList.value!!) {
- val f = File(Environment.getExternalStorageDirectory(), m.path + m.description)
- files.add(f)
+ currentType = type
+ currentTypeName = title.text.toString()
+ //鎷嶇収
+ if (dataList[position].guid == null) {
+ PhotoUtil.pickPhoto2(this@MenuCameraActivity, TAKE_PHOTO, 9)
}
- val intent = Intent(this@MenuCameraActivity, PhotoViewerActivity::class.java)
- .putExtra(PhotoViewerActivity.PARA_FILES, files as Serializable)
- .putExtra("type", PhotoViewerActivity.CAMERA_PHOTO)
- .putExtra("deletable", true)
- .putExtra("position", position)
- .putExtra(PhotoViewerActivity.PARA_MEDIAS, viewModel.mediaFileList.value as Serializable)
- startActivityForResult(intent, VIEW_PHOTO)
+ //鏌ョ湅鍥剧墖
+ else {
+ val files = ArrayList<File>()
+ val medias = ArrayList<Mediafile>()
+ for (m in dataList) {
+ if (m.guid != null) {
+ val f = File(Environment.getExternalStorageDirectory(), m.path + m.description)
+ files.add(f)
+ medias.add(m)
+ }
+ }
+ val intent = Intent(this@MenuCameraActivity, PhotoViewerActivity::class.java)
+ .putExtra(PhotoViewerActivity.PARA_FILES, files as Serializable)
+ .putExtra("type", PhotoViewerActivity.CAMERA_PHOTO)
+ .putExtra("deletable", true)
+ .putExtra("position", position - 1)
+ .putExtra(PhotoViewerActivity.PARA_MEDIAS, medias as Serializable)
+ startActivityForResult(intent, VIEW_PHOTO)
+ }
}
override fun onItemLongClick(view: View?, position: Int) {
}
}))
+
+ if (!listMap.containsKey(type)) {
+ listMap[type] = this
+ }
}
- iv_new_photo.setOnClickListener {
- PhotoUtil.pickPhoto2(this, TAKE_PHOTO, 9)
- }
-
- fab_problem_list_close.setOnClickListener {
- finish()
- }
+ viewList.add(view)
}
- private fun putMediaFile(path: String, fileName: String, calendar: Calendar) {
+ private fun initObserver() {
+ 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 {
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 = "甯歌璁板綍"
- mediaFile.businesstypeid = intToByte(5)
+ mediaFile.businesstype = currentType.des
+ mediaFile.businesstypeid = currentType.value.toByte()
mediaFile.path = path
mediaFile.description = fileName
mediaFile.savetime = Date()
@@ -164,5 +235,48 @@
mediaFile.remark = "鏈笂浼�"
viewModel.putMediaFile(mediaFile)
+
+ return mediaFile
+ }
+
+ private fun addPhoto(mediaFile: Mediafile) {
+ 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) {
+ 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) {
+ MediaFileType.RoutineRecord -> Pair(viewModel.routineRecordList, rv_photo_list_1)
+ MediaFileType.Nameplate -> Pair(viewModel.nameplateList, rv_photo_list_2)
+ MediaFileType.MonitorDevice -> Pair(viewModel.monitorDeviceList, rv_photo_list_3)
+ else -> Pair(viewModel.routineRecordList, rv_photo_list_1)
}
}
--
Gitblit v1.9.3