From 2b9926767b52b3a85dd8e1607af0658c91db0087 Mon Sep 17 00:00:00 2001 From: chenglifeng Date: Tue, 4 Mar 2025 11:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=90=E6=A0=87=E7=B3=BB=E7=BB=9F=E4=B8=8E?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E9=A1=B9=E7=9B=AE=E5=85=B3=E8=81=94=EF=BC=9B?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E7=B3=BB=E7=BB=9F=E4=B8=8E=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E7=AB=AF=E7=9A=84=E4=B8=8A=E4=BC=A0=E3=80=81=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=80=81=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 5 ++ .../com/project/survey/constants/Constants.kt | 2 + .../viewmodel/CoordinateSystemViewModel.kt | 24 +++++- .../logic/viewmodel/ProjectViewModel.kt | 10 ++- .../survey/model/CoordinateSystemData.kt | 9 ++- .../java/com/project/survey/network/Api.kt | 18 ++++- .../CachedCurrentCoordinateSystem.java | 28 +++---- .../CoordinateSystemAdapter.kt | 40 ++++++++++ .../CoordinateSystemListActivity.kt | 74 +++++++++++++++++++ .../CoordinateSystemContainerFragment.java | 41 +++++++--- .../survey/ui/project/ProjectListActivity.kt | 17 +++-- .../drawable/bg_rv_item_coordinate_system.xml | 15 ++++ .../activity_coordinate_system_list.xml | 34 +++++++++ .../res/layout/rv_item_coordinate_system.xml | 35 +++++++++ 14 files changed, 310 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemAdapter.kt create mode 100644 app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemListActivity.kt create mode 100644 app/src/main/res/drawable/bg_rv_item_coordinate_system.xml create mode 100644 app/src/main/res/layout/activity_coordinate_system_list.xml create mode 100644 app/src/main/res/layout/rv_item_coordinate_system.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 272421a..ad45347 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -449,6 +449,11 @@ android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/rtk_rover_setting" android:windowSoftInputMode="adjustUnspecified|stateHidden" /> + \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/constants/Constants.kt b/app/src/main/java/com/project/survey/constants/Constants.kt index b57e2ce..5f59dcc 100644 --- a/app/src/main/java/com/project/survey/constants/Constants.kt +++ b/app/src/main/java/com/project/survey/constants/Constants.kt @@ -19,11 +19,13 @@ object SPConstants { const val PROJECT_ID = "projectId" const val PROJECT_NAME = "projectName" const val CURRENT_PROJECT = "currentProject" + const val CURRENT_COORDINATE_SYSTEM_ID = "currentCoordinateSystemId" } object EventConstants { const val LOGIN_STATUS = "loginStatus" const val UPDATE_PROJECT = "updateProject" + const val CHOOSE_COORDINATE_SYSTEM = "chooseCoordinateSystem" } object AdapterConstants { diff --git a/app/src/main/java/com/project/survey/logic/viewmodel/CoordinateSystemViewModel.kt b/app/src/main/java/com/project/survey/logic/viewmodel/CoordinateSystemViewModel.kt index 0454886..8e1c47e 100644 --- a/app/src/main/java/com/project/survey/logic/viewmodel/CoordinateSystemViewModel.kt +++ b/app/src/main/java/com/project/survey/logic/viewmodel/CoordinateSystemViewModel.kt @@ -13,9 +13,10 @@ class CoordinateSystemViewModel : BaseViewModel() { get() = _uploadCoordinateSystemResponse private val _uploadCoordinateSystemResponse = MutableLiveData() - fun uploadCoordinateSystem(coordinateParameter: String) { + fun uploadCoordinateSystem(coordinateParameter: String, name: String) { launch { - val res = api.uploadCoordinateSystem(coordinateParameter = coordinateParameter) + val res = + api.uploadCoordinateSystem(coordinateParameter = coordinateParameter, name = name) if (res.success) { _uploadCoordinateSystemResponse.postValue(res.message) } else { @@ -24,9 +25,9 @@ class CoordinateSystemViewModel : BaseViewModel() { } } - val downloadCoordinateSystemResponse: LiveData + val downloadCoordinateSystemResponse: LiveData> get() = _downloadCoordinateSystemResponse - private val _downloadCoordinateSystemResponse = MutableLiveData() + private val _downloadCoordinateSystemResponse = MutableLiveData>() fun downloadCoordinateSystem() { launch { @@ -38,4 +39,19 @@ class CoordinateSystemViewModel : BaseViewModel() { } } } + + val updateCoordinateSystemResponse: LiveData + get() = _updateCoordinateSystemResponse + private val _updateCoordinateSystemResponse = MutableLiveData() + + fun updateCoordinateSystem(id: String, coordinateParameter: String, name: String) { + launch { + val res = api.updateCoordinateSystem(id, coordinateParameter, name) + if (res.success) { + _updateCoordinateSystemResponse.postValue(res.message) + } else { + errorResponse.postValue(res.message) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt b/app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt index 68a3d27..3356455 100644 --- a/app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt +++ b/app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt @@ -13,6 +13,7 @@ import com.project.survey.constants.SPConstants import com.project.survey.logic.bean.ListResult import com.project.survey.model.ApprovalBean import com.project.survey.model.ApprovalResponse +import com.project.survey.model.CoordinateSystemValue import com.project.survey.model.InspectionReportBean import com.project.survey.model.LoftingBean import com.project.survey.model.LoftingPointBean @@ -307,13 +308,14 @@ class ProjectViewModel : BaseViewModel() { /** * 拉取坐标 */ - fun fetchCoordinateSystem(onSuccess: (String) -> Unit, onFailure: (String) -> Unit) { + fun fetchCoordinateSystem(onSuccess: (CoordinateSystemValue) -> Unit, onFailure: (String) -> Unit) { launch { val res = api.downloadCoordinateSystem() if (res.success) { - withContext(Dispatchers.Main) { - onSuccess(res.data.ZBZHCS_ZHCS) - } + if (res.data.isNotEmpty()) + withContext(Dispatchers.Main) { + onSuccess(res.data[0].values) + } } else { withContext(Dispatchers.Main) { onFailure(res.message) diff --git a/app/src/main/java/com/project/survey/model/CoordinateSystemData.kt b/app/src/main/java/com/project/survey/model/CoordinateSystemData.kt index 0ae2b06..d99099b 100644 --- a/app/src/main/java/com/project/survey/model/CoordinateSystemData.kt +++ b/app/src/main/java/com/project/survey/model/CoordinateSystemData.kt @@ -4,5 +4,12 @@ import androidx.annotation.Keep @Keep data class CoordinateSystemData( - val ZBZHCS_ZHCS: String + val values: CoordinateSystemValue +) + +@Keep +data class CoordinateSystemValue( + val ZBZHCS_ZHCS: String, + val BD_ZBZHCS_ID: String, + val ZBZHCS_NAME: String?, ) diff --git a/app/src/main/java/com/project/survey/network/Api.kt b/app/src/main/java/com/project/survey/network/Api.kt index d6255f4..d8b533d 100644 --- a/app/src/main/java/com/project/survey/network/Api.kt +++ b/app/src/main/java/com/project/survey/network/Api.kt @@ -268,9 +268,9 @@ interface Api { @FormUrlEncoded @POST("je/measureWork/insertCoordinateParameter") suspend fun uploadCoordinateSystem( -// @Header("projectId") projectId: String = SPUtils.getString(SPConstants.PROJECT_ID), @Field("projectId") projectId: String = SPUtils.getString(SPConstants.PROJECT_ID), - @Field("coordinateParameter") coordinateParameter: String + @Field("coordinateParameter") coordinateParameter: String, + @Field("name") name: String ): HttpResult /** @@ -279,7 +279,17 @@ interface Api { @FormUrlEncoded @POST("je/measureWork/findCoordinateParameter") suspend fun downloadCoordinateSystem( -// @Header("projectId") projectId: String = SPUtils.getString(SPConstants.PROJECT_ID) @Field("projectId") projectId: String = SPUtils.getString(SPConstants.PROJECT_ID) - ): HttpResult + ): HttpResult> + + /** + * 修改坐标参数 + */ + @FormUrlEncoded + @POST("je/measureWork/updateCoordinateParameter") + suspend fun updateCoordinateSystem( + @Field("id") id: String, + @Field("coordinateParameter") coordinateParameter: String, + @Field("name") name: String + ): HttpResult } \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CachedCurrentCoordinateSystem.java b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CachedCurrentCoordinateSystem.java index 9b4bb70..9a4ec1d 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CachedCurrentCoordinateSystem.java +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CachedCurrentCoordinateSystem.java @@ -47,20 +47,20 @@ public class CachedCurrentCoordinateSystem extends CacheHelper { //1.监听当前坐标系id currentProjectKV .observe(this, configRecord -> { -// if (configRecord == null) { -// return; -// } -// if (projectRecordLiveData != null) { -// projectRecordLiveData.removeObservers(this); -// } -// projectRecordLiveData = ProjectDb.getInstance() -// .rawQueryLiveData(DBQueryConstant.findById(ProjectConstants.DB_NAME, configRecord.value)); -// -// projectRecordLiveData.observe(this, projectRecord -> { -// CoordinateSystem coordinateSystem = projectRecord == null ? null : projectRecord.coordinateSystem; -// currentCoordinateSystemMutableLiveData.setValue(coordinateSystem == null ? CoordinateSystem.newCoordinateSystem(context.value()) : coordinateSystem); -// }); - currentCoordinateSystemMutableLiveData.setValue(CoordinateSystem.newCoordinateSystem(context.value())); + if (configRecord == null) { + return; + } + if (projectRecordLiveData != null) { + projectRecordLiveData.removeObservers(this); + } + projectRecordLiveData = ProjectDb.getInstance() + .rawQueryLiveData(DBQueryConstant.findById(ProjectConstants.DB_NAME, configRecord.value)); + + projectRecordLiveData.observe(this, projectRecord -> { + CoordinateSystem coordinateSystem = projectRecord == null ? null : projectRecord.coordinateSystem; + currentCoordinateSystemMutableLiveData.setValue(coordinateSystem == null ? CoordinateSystem.newCoordinateSystem(context.value()) : coordinateSystem); + }); +// currentCoordinateSystemMutableLiveData.setValue(CoordinateSystem.newCoordinateSystem(context.value())); }); } diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemAdapter.kt b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemAdapter.kt new file mode 100644 index 0000000..18fa113 --- /dev/null +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemAdapter.kt @@ -0,0 +1,40 @@ +package com.project.survey.ui.instrument.coordinatesystem + +import android.content.Context +import android.view.ViewGroup +import com.bingce.coordlib.model.CoordinateSystem +import com.chad.library.adapter4.BaseQuickAdapter +import com.chad.library.adapter4.viewholder.QuickViewHolder +import com.project.survey.R +import com.project.survey.extend.setOnClickNoRepeatListener + +class CoordinateSystemAdapter : BaseQuickAdapter() { + + private var selectedPosition = -1 + private var lastPosition = -1 + + override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: CoordinateSystem?) { + if (item == null) return + + holder.setText(R.id.tvName, item.name) + .setText(R.id.tvDescribe, item.country + " " + item.projection.name) + holder.itemView.isSelected = position == selectedPosition + + holder.itemView.setOnClickNoRepeatListener { + holder.itemView.isSelected = true + lastPosition = selectedPosition + selectedPosition = position + notifyItemChanged(lastPosition) + } + } + + fun getSelectedPosition(): Int = selectedPosition + + override fun onCreateViewHolder( + context: Context, + parent: ViewGroup, + viewType: Int + ): QuickViewHolder { + return QuickViewHolder(R.layout.rv_item_coordinate_system, parent) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemListActivity.kt b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemListActivity.kt new file mode 100644 index 0000000..9da1f3a --- /dev/null +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemListActivity.kt @@ -0,0 +1,74 @@ +package com.project.survey.ui.instrument.coordinatesystem + +import android.R +import android.os.Bundle +import android.view.MenuItem +import androidx.activity.viewModels +import com.bingce.coordlib.util.CoordinateSystemUtil +import com.project.survey.constants.EventConstants +import com.project.survey.databinding.ActivityCoordinateSystemListBinding +import com.project.survey.extend.setOnClickNoRepeatListener +import com.project.survey.extend.toast +import com.project.survey.logic.event.Message +import com.project.survey.logic.viewmodel.CoordinateSystemViewModel +import com.project.survey.util.ActivityNavUtil +import org.polaric.colorful.ColorfulActivity + +/** + * 坐标系统列表 + */ +class CoordinateSystemListActivity : ColorfulActivity() { + + private lateinit var binding: ActivityCoordinateSystemListBinding + private val adapter by lazy { CoordinateSystemAdapter() } + private val viewModel: CoordinateSystemViewModel by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityCoordinateSystemListBinding.inflate(layoutInflater, null, false) + setContentView(binding.root) + setSupportActionBar(binding.toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + + binding.recyclerView.itemAnimator = null + binding.recyclerView.adapter = adapter + + viewModel.downloadCoordinateSystemResponse.observe(this) { + adapter.submitList(it.map { data -> + CoordinateSystemUtil.importCoordSysString(data.values.ZBZHCS_ZHCS) + }) + } + viewModel.downloadCoordinateSystem() + + // 选择 + binding.btnChoose.setOnClickNoRepeatListener { + if (adapter.getSelectedPosition() == -1) { + toast("请选择坐标系统") + return@setOnClickNoRepeatListener + } + if (adapter.getSelectedPosition() < adapter.itemCount) { + adapter.getItem(adapter.getSelectedPosition())?.let { item -> + viewModel.msgEvent.postValue( + Message(EventConstants.CHOOSE_COORDINATE_SYSTEM, obj = item) + ) + finish() + } + } + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (R.id.home == item.itemId) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } + + companion object { + @JvmStatic + fun start() { + ActivityNavUtil.startActivity {} + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java index 4f4719c..d6f8387 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java @@ -50,9 +50,12 @@ import com.bingce.utils.SoftKeyUtils; import com.bingce.utils.ThreadPoolUtil; import com.bingce.utils.ValidateUtil; import com.flyco.tablayout.SlidingTabLayout; +import com.project.survey.constants.EventConstants; import com.project.survey.constants.SPConstants; +import com.project.survey.logic.event.Message; import com.project.survey.logic.viewmodel.CoordinateSystemViewModel; import com.project.survey.ui.instrument.coordinatesystem.CachedCurrentCoordinateSystem; +import com.project.survey.ui.instrument.coordinatesystem.CoordinateSystemListActivity; import com.project.survey.ui.instrument.mobilestationmode.base.RtkPointCorrectActivity; import com.project.survey.util.SPUtils; import com.rengwuxian.materialedittext.MaterialEditText; @@ -153,16 +156,29 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC } viewModel = new ViewModelProvider(this).get(CoordinateSystemViewModel.class); + viewModel.getMsgEvent().observe(this, new Observer() { + @Override + public void onChanged(Message message) { + if (message.getMsg().equals(EventConstants.CHOOSE_COORDINATE_SYSTEM)) { + CoordinateSystem system = (CoordinateSystem) message.getObj(); + onCoordinateSystemChanged(system); + } + } + }); // 分享坐标系统(上传到服务器) viewModel.getUploadCoordinateSystemResponse().observe(this, s -> { ToastUtils.showShort(s); }); - // 导入坐标系统 - viewModel.getDownloadCoordinateSystemResponse().observe(this, data -> { - CoordinateSystem system = CoordinateSystemUtil.importCoordSysString(data.getZBZHCS_ZHCS()); - onCoordinateSystemChanged(system); - ToastUtils.showShort("导入成功"); + // 更新坐标系统 + viewModel.getUpdateCoordinateSystemResponse().observe(this, s ->{ + ToastUtils.showShort(s); }); + // 导入坐标系统 +// viewModel.getDownloadCoordinateSystemResponse().observe(this, data -> { +// CoordinateSystem system = CoordinateSystemUtil.importCoordSysString(data.getZBZHCS_ZHCS()); +// onCoordinateSystemChanged(system); +// ToastUtils.showShort("导入成功"); +// }); } @Override @@ -178,7 +194,7 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC SoftKeyUtils.hideSoftKey(); save(() -> { ToastUtils.showShort(R.string.save_success); - getActivity().finish(); +// getActivity().finish(); }); } @@ -325,7 +341,8 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC mSlidingTabLayout.setCurrentTab(index, true); } }); - } else*/ if (itemId == R.id.menu_fragment_coordinate_system_share) { //上传 + } else*/ + if (itemId == R.id.menu_fragment_coordinate_system_share) { //上传 // showShareParametersDialog(); new MaterialDialog.Builder(requireContext()) .title("提示") @@ -334,12 +351,18 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC .negativeText(R.string.cancel) .onPositive((materialDialog, dialogAction) -> { String coordinateSystemString = CoordinateSystemUtil.exportCoordSysString(currentCoordinateSystem()); - viewModel.uploadCoordinateSystem(coordinateSystemString); + String name = currentCoordinateSystem().getName(); + String coordinateSystemId = SPUtils.INSTANCE.getString(SPConstants.CURRENT_COORDINATE_SYSTEM_ID, ""); + if (coordinateSystemId.isEmpty()) { //上传新的 + viewModel.uploadCoordinateSystem(coordinateSystemString, name); + } else { //修改 + viewModel.updateCoordinateSystem(coordinateSystemId, coordinateSystemString, name); + } }) .show(); } else if (itemId == R.id.menu_fragment_coordinate_system_import) { //下载 // showImportParametersDialog(); - viewModel.downloadCoordinateSystem(); + CoordinateSystemListActivity.start(); } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt b/app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt index c6bacc2..b49aa79 100644 --- a/app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt +++ b/app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt @@ -102,12 +102,17 @@ class ProjectListActivity : BaseBindingActivity(), O SPUtils.put(SPConstants.CURRENT_PROJECT, bean) SPUtils.put(SPConstants.PROJECT_ID, bean.XMXX_ID) // 查询当前项目坐标系统 - viewModel.fetchCoordinateSystem({ coordinateSystemString -> - val coordinateSystem = - CoordinateSystemUtil.importCoordSysString(coordinateSystemString) - nav2Main(bean, coordinateSystem) - }, { message -> - toastLong(message + "使用默认坐标系统") + viewModel.fetchCoordinateSystem({ coordinateSystemValue -> + SPUtils.put( + SPConstants.CURRENT_COORDINATE_SYSTEM_ID, + coordinateSystemValue.BD_ZBZHCS_ID + ) + nav2Main( + bean, + CoordinateSystemUtil.importCoordSysString(coordinateSystemValue.ZBZHCS_ZHCS) + ) + }, { + SPUtils.put(SPConstants.CURRENT_COORDINATE_SYSTEM_ID, "") nav2Main(bean) }) diff --git a/app/src/main/res/drawable/bg_rv_item_coordinate_system.xml b/app/src/main/res/drawable/bg_rv_item_coordinate_system.xml new file mode 100644 index 0000000..3fe6eae --- /dev/null +++ b/app/src/main/res/drawable/bg_rv_item_coordinate_system.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_coordinate_system_list.xml b/app/src/main/res/layout/activity_coordinate_system_list.xml new file mode 100644 index 0000000..a729926 --- /dev/null +++ b/app/src/main/res/layout/activity_coordinate_system_list.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/rv_item_coordinate_system.xml b/app/src/main/res/layout/rv_item_coordinate_system.xml new file mode 100644 index 0000000..e74477e --- /dev/null +++ b/app/src/main/res/layout/rv_item_coordinate_system.xml @@ -0,0 +1,35 @@ + + + + + + + \ No newline at end of file