From 7be66bc9663c1106ebc78748dc22f394680ac86b Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 29 十二月 2020 09:57:09 +0800
Subject: [PATCH] 1. 修复场景地图界面选择场景点时可能由于列表下标越界导致崩溃问题; 2. 修复自定义PagerAdapter时,没有重写destroyItem可能会导致的崩溃问题; 3. 修改数据库实体类MediaTypeAlias的主键id类型从龙变更为Long,否则无法自增; 4. 新增部分列表相关的工具函数;
---
app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuCameraActivity.kt | 122 ++++++++++++++++++++++++++++++----------
1 files changed, 91 insertions(+), 31 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 674d3b6..59f991a 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,7 +44,7 @@
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)
@@ -46,6 +53,10 @@
private var currentType = MediaFileType.RoutineRecord
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 +77,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?) {
@@ -106,19 +121,34 @@
}
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 {
@@ -153,22 +183,36 @@
}
}))
+
+ 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
@@ -192,21 +236,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