坐标系统与当前项目关联;坐标系统与服务器端的上传、更新、下载

main
chenglifeng 2 months ago
parent 6d4f23517c
commit 2b9926767b
  1. 5
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/java/com/project/survey/constants/Constants.kt
  3. 24
      app/src/main/java/com/project/survey/logic/viewmodel/CoordinateSystemViewModel.kt
  4. 10
      app/src/main/java/com/project/survey/logic/viewmodel/ProjectViewModel.kt
  5. 9
      app/src/main/java/com/project/survey/model/CoordinateSystemData.kt
  6. 18
      app/src/main/java/com/project/survey/network/Api.kt
  7. 28
      app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CachedCurrentCoordinateSystem.java
  8. 40
      app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemAdapter.kt
  9. 74
      app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/CoordinateSystemListActivity.kt
  10. 41
      app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java
  11. 17
      app/src/main/java/com/project/survey/ui/project/ProjectListActivity.kt
  12. 15
      app/src/main/res/drawable/bg_rv_item_coordinate_system.xml
  13. 34
      app/src/main/res/layout/activity_coordinate_system_list.xml
  14. 35
      app/src/main/res/layout/rv_item_coordinate_system.xml

@ -449,6 +449,11 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/rtk_rover_setting"
android:windowSoftInputMode="adjustUnspecified|stateHidden" />
<activity
android:name=".ui.instrument.coordinatesystem.CoordinateSystemListActivity"
android:label="@string/coordinate_system"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
</application>
</manifest>

@ -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 {

@ -13,9 +13,10 @@ class CoordinateSystemViewModel : BaseViewModel() {
get() = _uploadCoordinateSystemResponse
private val _uploadCoordinateSystemResponse = MutableLiveData<String>()
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<CoordinateSystemData>
val downloadCoordinateSystemResponse: LiveData<List<CoordinateSystemData>>
get() = _downloadCoordinateSystemResponse
private val _downloadCoordinateSystemResponse = MutableLiveData<CoordinateSystemData>()
private val _downloadCoordinateSystemResponse = MutableLiveData<List<CoordinateSystemData>>()
fun downloadCoordinateSystem() {
launch {
@ -38,4 +39,19 @@ class CoordinateSystemViewModel : BaseViewModel() {
}
}
}
val updateCoordinateSystemResponse: LiveData<String>
get() = _updateCoordinateSystemResponse
private val _updateCoordinateSystemResponse = MutableLiveData<String>()
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)
}
}
}
}

@ -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)

@ -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?,
)

@ -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<String>
/**
@ -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<CoordinateSystemData>
): HttpResult<List<CoordinateSystemData>>
/**
* 修改坐标参数
*/
@FormUrlEncoded
@POST("je/measureWork/updateCoordinateParameter")
suspend fun updateCoordinateSystem(
@Field("id") id: String,
@Field("coordinateParameter") coordinateParameter: String,
@Field("name") name: String
): HttpResult<Any>
}

@ -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()));
});
}

@ -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<CoordinateSystem, QuickViewHolder>() {
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)
}
}

@ -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<CoordinateSystemListActivity> {}
}
}
}

@ -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<Message>() {
@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);
}

@ -102,12 +102,17 @@ class ProjectListActivity : BaseBindingActivity<ActivityProjectListBinding>(), 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)
})

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<solid android:color="#33396BD0" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</selector>

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="?colorPrimary"
android:minHeight="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/rv_item_coordinate_system" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnChoose"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/choose" />
</LinearLayout>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/sw_60dp"
android:layout_marginBottom="@dimen/sw_1dp"
android:background="@drawable/bg_rv_item_coordinate_system"
android:paddingHorizontal="@dimen/sw_10dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text_color_1"
android:textSize="@dimen/sw_14sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tvDescribe"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="000" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvDescribe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sw_5dp"
android:textColor="@color/text_color_404145"
android:textSize="@dimen/sw_12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName"
tools:text="000" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save