diff --git a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt b/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt deleted file mode 100644 index 74eaf29..0000000 --- a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.casic.br.operationsite.adapter - -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.casic.br.operationsite.R -import com.casic.br.operationsite.base.BaseApplication -import com.casic.br.operationsite.bean.PointBean -import com.casic.br.operationsite.service.CameraInspectionService -import com.casic.br.operationsite.utils.LocaleConstant -import com.pengxh.kt.lite.adapter.ViewHolder -import com.pengxh.kt.lite.extensions.convertColor - -class ManagePointAdapter( - private val context: Context, - private val points: MutableList, - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt b/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt deleted file mode 100644 index 74eaf29..0000000 --- a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.casic.br.operationsite.adapter - -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.casic.br.operationsite.R -import com.casic.br.operationsite.base.BaseApplication -import com.casic.br.operationsite.bean.PointBean -import com.casic.br.operationsite.service.CameraInspectionService -import com.casic.br.operationsite.utils.LocaleConstant -import com.pengxh.kt.lite.adapter.ViewHolder -import com.pengxh.kt.lite.extensions.convertColor - -class ManagePointAdapter( - private val context: Context, - private val points: MutableList, - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt b/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt deleted file mode 100644 index 74eaf29..0000000 --- a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.casic.br.operationsite.adapter - -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.casic.br.operationsite.R -import com.casic.br.operationsite.base.BaseApplication -import com.casic.br.operationsite.bean.PointBean -import com.casic.br.operationsite.service.CameraInspectionService -import com.casic.br.operationsite.utils.LocaleConstant -import com.pengxh.kt.lite.adapter.ViewHolder -import com.pengxh.kt.lite.extensions.convertColor - -class ManagePointAdapter( - private val context: Context, - private val points: MutableList, - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt index 9b92e5e..d23ca7a 100644 --- a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt +++ b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt @@ -4,10 +4,15 @@ import android.content.Context import android.graphics.Color import android.os.Bundle -import com.casic.br.operationsite.adapter.ManagePointAdapter +import com.casic.br.operationsite.R import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.DialogManagePointBinding import com.casic.br.operationsite.extensions.initDialogLayoutParams +import com.casic.br.operationsite.service.CameraInspectionService +import com.casic.br.operationsite.utils.LocaleConstant +import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter +import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.divider.RecyclerViewItemDivider import com.pengxh.kt.lite.extensions.binding @@ -15,7 +20,6 @@ private val kTag = "ManagePointDialog" private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - private val context = builder.context private val listener = builder.listener class Builder { @@ -45,7 +49,42 @@ setCanceledOnTouchOutside(false) setCancelable(false) - binding.recyclerView.adapter = ManagePointAdapter(context, pointBeanDao.firstLinePoints, 8) + val points = pointBeanDao.firstLinePoints + val adapter = object : NormalRecyclerAdapter( + R.layout.item_inspection_point_rv_l, points + ) { + override fun convertView(viewHolder: ViewHolder, position: Int, item: PointBean) { + val currentThirdType = item.thirdType + viewHolder.setText(R.id.textView, "预置点位 $currentThirdType") + .setOnLongClickListener(R.id.textView) { + //长按删除巡航点 + val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) + if (itemsToDelete.isNotEmpty()) { + itemsToDelete.forEach { + pointBeanDao.deletePoint(it) + } + } + + val items = points.filter { item -> item.thirdType == currentThirdType } + if (items.isNotEmpty()) { + items.forEach { + points.remove(it) + } + + notifyDataSetChanged() + + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.DELETE_POINT_CODE + message.obj = currentThirdType + handler.sendMessage(message) + } + } + true + } + } + } + binding.recyclerView.adapter = adapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.LTGRAY)) binding.textView.isSelected = true diff --git a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt b/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt deleted file mode 100644 index 74eaf29..0000000 --- a/app/src/main/java/com/casic/br/operationsite/adapter/ManagePointAdapter.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.casic.br.operationsite.adapter - -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.casic.br.operationsite.R -import com.casic.br.operationsite.base.BaseApplication -import com.casic.br.operationsite.bean.PointBean -import com.casic.br.operationsite.service.CameraInspectionService -import com.casic.br.operationsite.utils.LocaleConstant -import com.pengxh.kt.lite.adapter.ViewHolder -import com.pengxh.kt.lite.extensions.convertColor - -class ManagePointAdapter( - private val context: Context, - private val points: MutableList, - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt index 9b92e5e..d23ca7a 100644 --- a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt +++ b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt @@ -4,10 +4,15 @@ import android.content.Context import android.graphics.Color import android.os.Bundle -import com.casic.br.operationsite.adapter.ManagePointAdapter +import com.casic.br.operationsite.R import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.DialogManagePointBinding import com.casic.br.operationsite.extensions.initDialogLayoutParams +import com.casic.br.operationsite.service.CameraInspectionService +import com.casic.br.operationsite.utils.LocaleConstant +import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter +import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.divider.RecyclerViewItemDivider import com.pengxh.kt.lite.extensions.binding @@ -15,7 +20,6 @@ private val kTag = "ManagePointDialog" private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - private val context = builder.context private val listener = builder.listener class Builder { @@ -45,7 +49,42 @@ setCanceledOnTouchOutside(false) setCancelable(false) - binding.recyclerView.adapter = ManagePointAdapter(context, pointBeanDao.firstLinePoints, 8) + val points = pointBeanDao.firstLinePoints + val adapter = object : NormalRecyclerAdapter( + R.layout.item_inspection_point_rv_l, points + ) { + override fun convertView(viewHolder: ViewHolder, position: Int, item: PointBean) { + val currentThirdType = item.thirdType + viewHolder.setText(R.id.textView, "预置点位 $currentThirdType") + .setOnLongClickListener(R.id.textView) { + //长按删除巡航点 + val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) + if (itemsToDelete.isNotEmpty()) { + itemsToDelete.forEach { + pointBeanDao.deletePoint(it) + } + } + + val items = points.filter { item -> item.thirdType == currentThirdType } + if (items.isNotEmpty()) { + items.forEach { + points.remove(it) + } + + notifyDataSetChanged() + + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.DELETE_POINT_CODE + message.obj = currentThirdType + handler.sendMessage(message) + } + } + true + } + } + } + binding.recyclerView.adapter = adapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.LTGRAY)) binding.textView.isSelected = true diff --git a/app/src/main/res/drawable/ic_minus.xml b/app/src/main/res/drawable/ic_minus.xml index 2942b80..f7703fd 100644 --- a/app/src/main/res/drawable/ic_minus.xml +++ b/app/src/main/res/drawable/ic_minus.xml @@ -1,6 +1,6 @@ , - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt index 9b92e5e..d23ca7a 100644 --- a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt +++ b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt @@ -4,10 +4,15 @@ import android.content.Context import android.graphics.Color import android.os.Bundle -import com.casic.br.operationsite.adapter.ManagePointAdapter +import com.casic.br.operationsite.R import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.DialogManagePointBinding import com.casic.br.operationsite.extensions.initDialogLayoutParams +import com.casic.br.operationsite.service.CameraInspectionService +import com.casic.br.operationsite.utils.LocaleConstant +import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter +import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.divider.RecyclerViewItemDivider import com.pengxh.kt.lite.extensions.binding @@ -15,7 +20,6 @@ private val kTag = "ManagePointDialog" private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - private val context = builder.context private val listener = builder.listener class Builder { @@ -45,7 +49,42 @@ setCanceledOnTouchOutside(false) setCancelable(false) - binding.recyclerView.adapter = ManagePointAdapter(context, pointBeanDao.firstLinePoints, 8) + val points = pointBeanDao.firstLinePoints + val adapter = object : NormalRecyclerAdapter( + R.layout.item_inspection_point_rv_l, points + ) { + override fun convertView(viewHolder: ViewHolder, position: Int, item: PointBean) { + val currentThirdType = item.thirdType + viewHolder.setText(R.id.textView, "预置点位 $currentThirdType") + .setOnLongClickListener(R.id.textView) { + //长按删除巡航点 + val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) + if (itemsToDelete.isNotEmpty()) { + itemsToDelete.forEach { + pointBeanDao.deletePoint(it) + } + } + + val items = points.filter { item -> item.thirdType == currentThirdType } + if (items.isNotEmpty()) { + items.forEach { + points.remove(it) + } + + notifyDataSetChanged() + + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.DELETE_POINT_CODE + message.obj = currentThirdType + handler.sendMessage(message) + } + } + true + } + } + } + binding.recyclerView.adapter = adapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.LTGRAY)) binding.textView.isSelected = true diff --git a/app/src/main/res/drawable/ic_minus.xml b/app/src/main/res/drawable/ic_minus.xml index 2942b80..f7703fd 100644 --- a/app/src/main/res/drawable/ic_minus.xml +++ b/app/src/main/res/drawable/ic_minus.xml @@ -1,6 +1,6 @@ , - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt index 9b92e5e..d23ca7a 100644 --- a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt +++ b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt @@ -4,10 +4,15 @@ import android.content.Context import android.graphics.Color import android.os.Bundle -import com.casic.br.operationsite.adapter.ManagePointAdapter +import com.casic.br.operationsite.R import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.DialogManagePointBinding import com.casic.br.operationsite.extensions.initDialogLayoutParams +import com.casic.br.operationsite.service.CameraInspectionService +import com.casic.br.operationsite.utils.LocaleConstant +import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter +import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.divider.RecyclerViewItemDivider import com.pengxh.kt.lite.extensions.binding @@ -15,7 +20,6 @@ private val kTag = "ManagePointDialog" private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - private val context = builder.context private val listener = builder.listener class Builder { @@ -45,7 +49,42 @@ setCanceledOnTouchOutside(false) setCancelable(false) - binding.recyclerView.adapter = ManagePointAdapter(context, pointBeanDao.firstLinePoints, 8) + val points = pointBeanDao.firstLinePoints + val adapter = object : NormalRecyclerAdapter( + R.layout.item_inspection_point_rv_l, points + ) { + override fun convertView(viewHolder: ViewHolder, position: Int, item: PointBean) { + val currentThirdType = item.thirdType + viewHolder.setText(R.id.textView, "预置点位 $currentThirdType") + .setOnLongClickListener(R.id.textView) { + //长按删除巡航点 + val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) + if (itemsToDelete.isNotEmpty()) { + itemsToDelete.forEach { + pointBeanDao.deletePoint(it) + } + } + + val items = points.filter { item -> item.thirdType == currentThirdType } + if (items.isNotEmpty()) { + items.forEach { + points.remove(it) + } + + notifyDataSetChanged() + + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.DELETE_POINT_CODE + message.obj = currentThirdType + handler.sendMessage(message) + } + } + true + } + } + } + binding.recyclerView.adapter = adapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.LTGRAY)) binding.textView.isSelected = true diff --git a/app/src/main/res/drawable/ic_minus.xml b/app/src/main/res/drawable/ic_minus.xml index 2942b80..f7703fd 100644 --- a/app/src/main/res/drawable/ic_minus.xml +++ b/app/src/main/res/drawable/ic_minus.xml @@ -1,6 +1,6 @@ , - private val countLimit: Int -) : RecyclerView.Adapter() { - - private val kTag = "ManagePointAdapter" - private val layoutInflater by lazy { LayoutInflater.from(context) } - private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder( - layoutInflater.inflate(R.layout.item_inspection_point_rv_l, parent, false) - ) - } - - override fun getItemCount(): Int { - return if (points.isEmpty()) { - 1 // 没有数据时只显示“添加” - } else if (points.size < countLimit) { - points.size + 1 // 显示数据 + “添加” - } else { - points.size // 达到上限,不显示“添加” - } - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val textView = holder.getView(R.id.textView) - if (position == itemCount - 1 && points.size < countLimit) { - textView.text = "添加" - textView.setTextColor(R.color.greenColor.convertColor(context)) - textView.setOnClickListener { - //添加巡航点 - val result = points.find { it.thirdType == 0 } - if (result == null) { - val pointBean = PointBean().apply { - firstType = 92 - secondType = 1 - thirdType = pointBeanDao.firstLinePoints.size + 1 - } - pointBeanDao.insert(pointBean) - points.add(pointBean) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = pointBean.thirdType - handler.sendMessage(message) - } - } else { - result.thirdType = 1 - pointBeanDao.updatePoint(result) - notifyDataSetChanged() - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.ADD_POINT_CODE - message.obj = 1 - handler.sendMessage(message) - } - } - } - } else { - if (points.isEmpty()) { - return - } - val currentThirdType = points[position].thirdType - textView.text = "预置点位 $currentThirdType" - textView.setTextColor(R.color.mainTextColor.convertColor(context)) - textView.setOnClickListener(null) - textView.setOnLongClickListener { v -> - //长按删除巡航点。删除所有线路中相同的点位 - val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) - if (itemsToDelete.isNotEmpty()) { - itemsToDelete.forEach { - pointBeanDao.deletePoint(it) - } - } - - val items = points.filter { item -> item.thirdType == currentThirdType } - if (items.isNotEmpty()) { - items.forEach { - points.remove(it) - } - - notifyDataSetChanged() - - CameraInspectionService.weakReferenceHandler?.let { handler -> - val message = handler.obtainMessage() - message.what = LocaleConstant.DELETE_POINT_CODE - message.obj = currentThirdType - handler.sendMessage(message) - } - } - true - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt index 862a00c..a0f9438 100644 --- a/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt +++ b/app/src/main/java/com/casic/br/operationsite/fragments/DeviceControllerFragment.kt @@ -4,10 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.MotionEvent +import android.view.View import android.view.ViewGroup +import android.widget.AdapterView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.FragmentDeviceControllerBinding import com.casic.br.operationsite.service.CameraInspectionService import com.casic.br.operationsite.utils.LocaleConstant @@ -28,6 +31,7 @@ private val deviceViewModel by lazy { ViewModelProvider(this)[DeviceViewModel::class.java] } private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } private var speed = 5 + private var selectedPoint = 1 override fun initOnCreate(savedInstanceState: Bundle?) { binding.currentSpeedView.text = "速度:${speed}" @@ -100,6 +104,37 @@ binding.currentSpeedView.text = "速度:${speed}" } + binding.pointSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected( + parent: AdapterView<*>?, view: View?, position: Int, id: Long + ) { + selectedPoint = position + 1 + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + binding.addPointButton.setOnClickListener { + var result = pointBeanDao.firstLinePoints.find { it.thirdType == selectedPoint } + if (result == null) { + result = PointBean().apply { + firstType = 92 + secondType = 1 + thirdType = selectedPoint + } + pointBeanDao.insert(result) + } + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.ADD_POINT_CODE + message.obj = result.thirdType + handler.sendMessage(message) + } + "添加成功".show(requireContext()) + } + binding.startInspectionButton.setOnClickListener { val beans = pointBeanDao.firstLinePoints //至少得2个点才能巡航 @@ -117,17 +152,17 @@ } binding.managePointButton.setOnClickListener { + val beans = pointBeanDao.firstLinePoints + if (beans.size < 2) { + "请至少添加两个点".show(requireContext()) + return@setOnClickListener + } + ManagePointDialog.Builder() .setContext(requireContext()) .setOnDialogButtonClickListener(object : ManagePointDialog.OnDialogButtonClickListener { override fun onConfirmClick() { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { - "请至少添加两个点".show(requireContext()) - return - } - lifecycleScope.launch(Dispatchers.IO) { CameraInspectionService.weakReferenceHandler?.let { it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) diff --git a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt index 9b92e5e..d23ca7a 100644 --- a/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt +++ b/app/src/main/java/com/casic/br/operationsite/widgets/ManagePointDialog.kt @@ -4,10 +4,15 @@ import android.content.Context import android.graphics.Color import android.os.Bundle -import com.casic.br.operationsite.adapter.ManagePointAdapter +import com.casic.br.operationsite.R import com.casic.br.operationsite.base.BaseApplication +import com.casic.br.operationsite.bean.PointBean import com.casic.br.operationsite.databinding.DialogManagePointBinding import com.casic.br.operationsite.extensions.initDialogLayoutParams +import com.casic.br.operationsite.service.CameraInspectionService +import com.casic.br.operationsite.utils.LocaleConstant +import com.pengxh.kt.lite.adapter.NormalRecyclerAdapter +import com.pengxh.kt.lite.adapter.ViewHolder import com.pengxh.kt.lite.divider.RecyclerViewItemDivider import com.pengxh.kt.lite.extensions.binding @@ -15,7 +20,6 @@ private val kTag = "ManagePointDialog" private val pointBeanDao by lazy { BaseApplication.get().dataBase.pointBeanDao() } - private val context = builder.context private val listener = builder.listener class Builder { @@ -45,7 +49,42 @@ setCanceledOnTouchOutside(false) setCancelable(false) - binding.recyclerView.adapter = ManagePointAdapter(context, pointBeanDao.firstLinePoints, 8) + val points = pointBeanDao.firstLinePoints + val adapter = object : NormalRecyclerAdapter( + R.layout.item_inspection_point_rv_l, points + ) { + override fun convertView(viewHolder: ViewHolder, position: Int, item: PointBean) { + val currentThirdType = item.thirdType + viewHolder.setText(R.id.textView, "预置点位 $currentThirdType") + .setOnLongClickListener(R.id.textView) { + //长按删除巡航点 + val itemsToDelete = pointBeanDao.queryPoint(currentThirdType) + if (itemsToDelete.isNotEmpty()) { + itemsToDelete.forEach { + pointBeanDao.deletePoint(it) + } + } + + val items = points.filter { item -> item.thirdType == currentThirdType } + if (items.isNotEmpty()) { + items.forEach { + points.remove(it) + } + + notifyDataSetChanged() + + CameraInspectionService.weakReferenceHandler?.let { handler -> + val message = handler.obtainMessage() + message.what = LocaleConstant.DELETE_POINT_CODE + message.obj = currentThirdType + handler.sendMessage(message) + } + } + true + } + } + } + binding.recyclerView.adapter = adapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.LTGRAY)) binding.textView.isSelected = true diff --git a/app/src/main/res/drawable/ic_minus.xml b/app/src/main/res/drawable/ic_minus.xml index 2942b80..f7703fd 100644 --- a/app/src/main/res/drawable/ic_minus.xml +++ b/app/src/main/res/drawable/ic_minus.xml @@ -1,6 +1,6 @@ - + android:orientation="horizontal"> - + - + - - + - + + - + - + - - + + + + + + + + + + + + + + + + android:orientation="horizontal">