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 1a9c186..f9e632f 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 @@ -20,12 +20,21 @@ import com.casic.br.operationsite.widgets.ManagePointDialog import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadingDialog import com.pengxh.kt.lite.widget.SteeringWheelView import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.asFlow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flatMapConcat +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.onCompletion +import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.launch +@FlowPreview class DeviceControllerFragment : KotlinBaseFragment() { private val kTag = "DeviceFragment" @@ -164,8 +173,7 @@ } binding.managePointButton.setOnClickListener { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { + if (pointBeanDao.firstLinePoints.size < 2) { "请至少添加两个点".show(requireContext()) return@setOnClickListener } @@ -187,25 +195,41 @@ if (pointBeanDao.firstLinePoints.isEmpty()) { binding.pointSpinner.setSelection(0) } else { - binding.pointSpinner.setSelection(pointBeanDao.firstLinePoints.size - 1) - lifecycleScope.launch(Dispatchers.IO) { - CameraInspectionService.weakReferenceHandler?.let { - it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) + val beans = pointBeanDao.firstLinePoints + binding.pointSpinner.setSelection(beans.size - 1) + LoadingDialog.show(requireActivity(), "预置点绑定中,请稍后...") + lifecycleScope.launch(Dispatchers.Main) { + (1..beans.size).asFlow().onStart { + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.START_ADD_POINT_CONFIG_CODE + ) delay(1000) - it.sendEmptyMessage(LocaleConstant.SELECT_LINE_CODE) + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.SELECT_LINE_CODE + ) delay(1000) - //循环设置巡航点 - for (i in 1..beans.size) { - val message = it.obtainMessage() - message.what = LocaleConstant.SETUP_POINT_CODE - message.obj = i - it.sendMessage(message) + }.flatMapConcat { i -> + flow { + CameraInspectionService.weakReferenceHandler?.let { + val message = it.obtainMessage() + message.what = LocaleConstant.SETUP_POINT_CODE + message.obj = i + it.sendMessage(message) + } delay(1000) + emit(i) } - it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) + }.onCompletion { + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.START_ADD_POINT_CONFIG_CODE + ) delay(1000) - it.sendEmptyMessage(LocaleConstant.END_ADD_POINT_CONFIG_CODE) - } + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.END_ADD_POINT_CONFIG_CODE + ) + LoadingDialog.dismiss() + "绑定成功,可以开始巡航了!".show(requireContext()) + }.collect() } } } 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 1a9c186..f9e632f 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 @@ -20,12 +20,21 @@ import com.casic.br.operationsite.widgets.ManagePointDialog import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.LoadingDialog import com.pengxh.kt.lite.widget.SteeringWheelView import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.asFlow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flatMapConcat +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.onCompletion +import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.launch +@FlowPreview class DeviceControllerFragment : KotlinBaseFragment() { private val kTag = "DeviceFragment" @@ -164,8 +173,7 @@ } binding.managePointButton.setOnClickListener { - val beans = pointBeanDao.firstLinePoints - if (beans.size < 2) { + if (pointBeanDao.firstLinePoints.size < 2) { "请至少添加两个点".show(requireContext()) return@setOnClickListener } @@ -187,25 +195,41 @@ if (pointBeanDao.firstLinePoints.isEmpty()) { binding.pointSpinner.setSelection(0) } else { - binding.pointSpinner.setSelection(pointBeanDao.firstLinePoints.size - 1) - lifecycleScope.launch(Dispatchers.IO) { - CameraInspectionService.weakReferenceHandler?.let { - it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) + val beans = pointBeanDao.firstLinePoints + binding.pointSpinner.setSelection(beans.size - 1) + LoadingDialog.show(requireActivity(), "预置点绑定中,请稍后...") + lifecycleScope.launch(Dispatchers.Main) { + (1..beans.size).asFlow().onStart { + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.START_ADD_POINT_CONFIG_CODE + ) delay(1000) - it.sendEmptyMessage(LocaleConstant.SELECT_LINE_CODE) + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.SELECT_LINE_CODE + ) delay(1000) - //循环设置巡航点 - for (i in 1..beans.size) { - val message = it.obtainMessage() - message.what = LocaleConstant.SETUP_POINT_CODE - message.obj = i - it.sendMessage(message) + }.flatMapConcat { i -> + flow { + CameraInspectionService.weakReferenceHandler?.let { + val message = it.obtainMessage() + message.what = LocaleConstant.SETUP_POINT_CODE + message.obj = i + it.sendMessage(message) + } delay(1000) + emit(i) } - it.sendEmptyMessage(LocaleConstant.START_ADD_POINT_CONFIG_CODE) + }.onCompletion { + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.START_ADD_POINT_CONFIG_CODE + ) delay(1000) - it.sendEmptyMessage(LocaleConstant.END_ADD_POINT_CONFIG_CODE) - } + CameraInspectionService.weakReferenceHandler?.sendEmptyMessage( + LocaleConstant.END_ADD_POINT_CONFIG_CODE + ) + LoadingDialog.dismiss() + "绑定成功,可以开始巡航了!".show(requireContext()) + }.collect() } } } 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 bf020f4..0a4d923 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 @@ -45,7 +45,7 @@ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - initDialogLayoutParams(0.75f, 0.55f) + initDialogLayoutParams(0.8f, 0.4f) setCanceledOnTouchOutside(false) setCancelable(false)