From ef78de301c033f62a7a0730736494c9b8d386c98 Mon Sep 17 00:00:00 2001 From: huangwei <983142558@qq.com> Date: Tue, 13 Aug 2024 17:22:47 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=86=9B=E6=B5=8B]=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 4 + .../MeasureHeightTraverseFragment.kt | 5 +- .../IStationSettingOperate.kt | 5 + ...ettingEnvironmentHeightTraverseFragment.kt | 213 ++++++++++++ ...tionSettingHeightHeightTraverseFragment.kt | 151 +++++++++ .../StationSettingHeightTraverseVm.kt | 21 ++ .../StationSettingsHeightTraverseActivity.kt | 317 ++++++++++++++++++ .../model/StationSettingEnvironmentData.kt | 38 +++ .../model/StationSettingHeightData.kt | 58 ++++ ...on_setting_environment_height_traverse.xml | 88 +++++ ...station_setting_height_height_traverse.xml | 91 +++++ 11 files changed, 989 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/IStationSettingOperate.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingEnvironmentHeightTraverseFragment.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightHeightTraverseFragment.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightTraverseVm.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingsHeightTraverseActivity.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingEnvironmentData.kt create mode 100644 app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingHeightData.kt create mode 100644 app/src/main/res/layout/new_fragment_station_setting_environment_height_traverse.xml create mode 100644 app/src/main/res/layout/new_fragment_station_setting_height_height_traverse.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b141559..b334bc8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -187,6 +187,10 @@ android:name=".newui.stationsetting.StationSettingsActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="true" /> + (), + IStationSettingOperate { + + private val viewModel by activityViewModels() + + override fun getViewBinding( + inflater: LayoutInflater, + container: ViewGroup? + ): NewFragmentStationSettingEnvironmentHeightTraverseBinding { + return NewFragmentStationSettingEnvironmentHeightTraverseBinding.inflate( + inflater, + container, + false + ) + } + + override fun initView() { + mBinding.ilDryTemperature.tvName.text = getString(R.string.dry_temperature) + mBinding.ilDryTemperature.etValue.hint = getString(R.string.dry_temperature) + mBinding.ilDryTemperature.tvUnit.text = "℃" + + mBinding.ilHumidityTemperature.tvName.text = getString(R.string.humidity_temperature) + mBinding.ilHumidityTemperature.etValue.hint = getString(R.string.humidity_temperature) + mBinding.ilHumidityTemperature.tvUnit.text = "℃" + + mBinding.ilAirPressure.tvName.text = getString(R.string.hint_air_pressure) + mBinding.ilAirPressure.etValue.hint = getString(R.string.hint_air_pressure) + mBinding.ilAirPressure.tvUnit.text = "hPa" + + mBinding.ilAdditionConstant.tvName.text = getString(R.string.addition_constant) + mBinding.ilAdditionConstant.etValue.hint = getString(R.string.addition_constant) + mBinding.ilAdditionConstant.tvUnit.text = "mm" + + mBinding.ilmultiplicationConstant.tvName.text = getString(R.string.multiplication_constant) + mBinding.ilmultiplicationConstant.etValue.hint = getString(R.string.multiplication_constant) + mBinding.ilmultiplicationConstant.tvUnit.text = "ppm" + + initListener() + } + + private fun initListener() { + mBinding.tvLastData.setOnClickListener { + useLastData() + } + mBinding.tvStandardData.setOnClickListener { + setDataFromRecord(null) + } + } + + private fun useLastData() { + lifecycleScope.launch { + val record = withContext(Dispatchers.IO) { + val dryTemperature = getValueFromLastKey(ConfigConstants.KEY_LAST_DRY_TEMPERATURE) + val humidityTemperature = + getValueFromLastKey(ConfigConstants.KEY_LAST_HUMIDITY_TEMPERATURE) + val airPressure = getValueFromLastKey(ConfigConstants.KEY_LAST_AIR_PRESSURE) + val additionConstant = + getValueFromLastKey(ConfigConstants.KEY_LAST_ADDITION_CONSTANT) + val multiplicationConstant = + getValueFromLastKey(ConfigConstants.KEY_LAST_MULTIPLICATION_CONSTANT) + val instrumentHeightBefore = + getValueFromLastKey(ConfigConstants.KEY_LAST_INSTRUMENT_HEIGHT_BEFORE) + val instrumentHeightAfter = + getValueFromLastKey(ConfigConstants.KEY_LAST_INSTRUMENT_HEIGHT_AFTER) + val backPrismHeightBefore = + getValueFromLastKey(ConfigConstants.KEY_LAST_BACK_PRISM_HEIGHT_BEFORE) + val backPrismHeightAfter = + getValueFromLastKey(ConfigConstants.KEY_LAST_BACK_PRISM_HEIGHT_AFTER) + val frontPrismHeightBefore = + getValueFromLastKey(ConfigConstants.KEY_LAST_FRONT_PRISM_HEIGHT_BEFORE) + val frontPrismHeightAfter = + getValueFromLastKey(ConfigConstants.KEY_LAST_FRONT_PRISM_HEIGHT_AFTER) + + if (dryTemperature == null + || humidityTemperature == null + || airPressure == null + || additionConstant == null + || multiplicationConstant == null + || instrumentHeightBefore == null + || instrumentHeightAfter == null + || backPrismHeightBefore == null + || backPrismHeightAfter == null + || frontPrismHeightBefore == null + || frontPrismHeightAfter == null + ) { + return@withContext null + } + + StationSettingHeightTraverseRecord.newInstance( + viewModel.stationId, + dryTemperature, + humidityTemperature, + airPressure, + additionConstant, + multiplicationConstant, + instrumentHeightBefore, + instrumentHeightAfter, + backPrismHeightBefore, + backPrismHeightAfter, + frontPrismHeightBefore, + frontPrismHeightAfter + ) + } + + setDataFromRecord(record) + } + } + + private fun getValueFromLastKey(key: String): String? { + val record = + SurveyorDatabaseFactory.instance.configDataSource.getByKeySync(key) + return record?.configValue + } + + override fun initData() { + lifecycleScope.launch { + val record = withContext(Dispatchers.IO) { + SurveyorDatabaseFactory.instance.getStationSettingHeightTraverseDataSource() + .getRecordByStationId(viewModel.stationId) + } + setDataFromRecord(record) + } + } + + private fun setDataFromRecord(record: StationSettingHeightTraverseRecord?) { + mBinding.ilDryTemperature.etValue.setText( + record?.dryTemperature ?: DEFAULT_TEMPERATURE + ) + mBinding.ilHumidityTemperature.etValue.setText( + record?.humidityTemperature ?: DEFAULT_TEMPERATURE + ) + mBinding.ilAirPressure.etValue.setText(record?.airPressure ?: DEFAULT_AIR_PRESSURE) + mBinding.ilAdditionConstant.etValue.setText( + record?.additionConstant ?: DEFAULT_CONSTANT + ) + mBinding.ilmultiplicationConstant.etValue.setText( + record?.multiplicationConstant ?: DEFAULT_CONSTANT + ) + } + + override fun checkSaveNot(): Boolean { + if (editTextEmpty(mBinding.ilDryTemperature.etValue)) { + ToastUtils.showShort(R.string.please_enter_dry_temperature) + return true + } + if (editTextEmpty(mBinding.ilHumidityTemperature.etValue)) { + ToastUtils.showShort(R.string.please_enter_humidity_temperature) + return true + } + if (editTextEmpty(mBinding.ilAirPressure.etValue)) { + ToastUtils.showShort(Tools.getString(R.string.please_enter_air_pressure)) + return true + } + if (editTextEmpty(mBinding.ilAdditionConstant.etValue)) { + ToastUtils.showShort(R.string.please_enter_addition_constant) + return true + } + if (editTextEmpty(mBinding.ilmultiplicationConstant.etValue)) { + ToastUtils.showShort(R.string.please_enter_multiplication_constant) + return true + } + setDataToViewModel() + return false + } + + private fun setDataToViewModel() { + val dryTemperature = getEtText(mBinding.ilDryTemperature.etValue) + val humidityTemperature = getEtText(mBinding.ilHumidityTemperature.etValue) + val airPressure = getEtText(mBinding.ilAirPressure.etValue) + val additionConstant = getEtText(mBinding.ilAdditionConstant.etValue) + val multiplicationConstant = getEtText(mBinding.ilmultiplicationConstant.etValue) + + viewModel.dryTemperature = dryTemperature + viewModel.humidityTemperature = humidityTemperature + viewModel.airPressure = airPressure + viewModel.additionConstant = additionConstant + viewModel.multiplicationConstant = multiplicationConstant + } + + private fun editTextEmpty(et: EditText): Boolean { + return TextUtils.isEmpty(getEtText(et)) + } + + private fun getEtText(et: EditText) = et.text.toString().trim() + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightHeightTraverseFragment.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightHeightTraverseFragment.kt new file mode 100644 index 0000000..d16e812 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightHeightTraverseFragment.kt @@ -0,0 +1,151 @@ +package com.bingce.controlnetwork.newui.stationsettingheighttraverse + +import android.text.TextUtils +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.EditText +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.lifecycleScope +import blankj.utilcode.util.ToastUtils +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory +import com.bingce.controlapphelper.datasource.database.heighttraverse.stationsetting.model.StationSettingHeightTraverseRecord +import com.bingce.controlnetwork.R +import com.bingce.controlnetwork.databinding.NewFragmentStationSettingHeightHeightTraverseBinding +import com.bingce.controlnetwork.fragment.stationsetting.BaseStationSettingFragment.Companion.DEFAULT_INSTRUMEN_HEIGHT +import com.bingce.controlnetwork.newui.base.BaseFragmentBinding +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +/** + * 高程导线-仪高镜高 + */ +class StationSettingHeightHeightTraverseFragment : + BaseFragmentBinding(), + IStationSettingOperate { + + private val viewModel by activityViewModels() + + + override fun getViewBinding( + inflater: LayoutInflater, + container: ViewGroup? + ): NewFragmentStationSettingHeightHeightTraverseBinding { + return NewFragmentStationSettingHeightHeightTraverseBinding.inflate( + inflater, + container, + false + ) + } + + override fun initView() { + mBinding.ilInstrumentHeight.tvName.text = getString(R.string.instrument_height) + mBinding.ilBackPrismHeight.tvName.text = getString(R.string.back_prism_height) + mBinding.ilFrontPrismHeight.tvName.text = getString(R.string.front_prism_height) + + //仪器高,棱镜高 + mBinding.ilInstrumentHeight.button1.setOnClickListener { + mBinding.ilInstrumentHeight.etValueAfter.setText( + getEtText(mBinding.ilInstrumentHeight.etValueBefore) + ) + } + mBinding.ilBackPrismHeight.button1.setOnClickListener { + mBinding.ilBackPrismHeight.etValueAfter.setText( + getEtText(mBinding.ilBackPrismHeight.etValueBefore) + ) + } + mBinding.ilFrontPrismHeight.button1.setOnClickListener { + mBinding.ilFrontPrismHeight.etValueAfter.setText( + getEtText(mBinding.ilFrontPrismHeight.etValueBefore) + ) + } + + } + + private fun getEtText(et: EditText) = et.text.toString().trim() + + + override fun initData() { + lifecycleScope.launch { + val record = withContext(Dispatchers.IO) { + SurveyorDatabaseFactory.instance.getStationSettingHeightTraverseDataSource() + .getRecordByStationId(viewModel.stationId) + } + setDataFromRecord(record) + } + } + + private fun setDataFromRecord(record: StationSettingHeightTraverseRecord?) { + mBinding.ilInstrumentHeight.etValueBefore.setText( + record?.instrumentHeightBefore ?: DEFAULT_INSTRUMEN_HEIGHT + ) + mBinding.ilInstrumentHeight.etValueAfter.setText( + record?.instrumentHeightAfter ?: DEFAULT_INSTRUMEN_HEIGHT + ) + mBinding.ilBackPrismHeight.etValueBefore.setText( + record?.backPrismHeightBefore ?: DEFAULT_INSTRUMEN_HEIGHT + ) + mBinding.ilBackPrismHeight.etValueAfter.setText( + record?.backPrismHeightAfter ?: DEFAULT_INSTRUMEN_HEIGHT + ) + mBinding.ilFrontPrismHeight.etValueBefore.setText( + record?.frontPrismHeightBefore ?: DEFAULT_INSTRUMEN_HEIGHT + ) + mBinding.ilFrontPrismHeight.etValueAfter.setText( + record?.frontPrismHeightAfter ?: DEFAULT_INSTRUMEN_HEIGHT + ) + } + + override fun checkSaveNot(): Boolean { + if (editTextEmpty(mBinding.ilInstrumentHeight.etValueBefore)) { + ToastUtils.showShort(R.string.please_enter_instrument_height_before) + return true + } + if (editTextEmpty(mBinding.ilInstrumentHeight.etValueAfter)) { + ToastUtils.showShort(R.string.please_enter_instrument_height_after) + return true + } + if (editTextEmpty(mBinding.ilBackPrismHeight.etValueBefore)) { + ToastUtils.showShort(R.string.please_enter_back_prism_height_before) + return true + } + if (editTextEmpty(mBinding.ilBackPrismHeight.etValueAfter)) { + ToastUtils.showShort(R.string.please_enter_back_prism_height_after) + return true + } + if (editTextEmpty(mBinding.ilFrontPrismHeight.etValueBefore)) { + ToastUtils.showShort(R.string.please_enter_front_prism_height_before) + return true + } + if (editTextEmpty(mBinding.ilFrontPrismHeight.etValueAfter)) { + ToastUtils.showShort(R.string.please_enter_front_prism_height_after) + return true + } + + setDataToViewModel() + + return false + } + + private fun setDataToViewModel() { + val instrumentHeightBefore = getEtText(mBinding.ilInstrumentHeight.etValueBefore) + val instrumentHeightAfter = getEtText(mBinding.ilInstrumentHeight.etValueAfter) + val backPrismHeightBefore = getEtText(mBinding.ilBackPrismHeight.etValueBefore) + val backPrismHeightAfter = getEtText(mBinding.ilBackPrismHeight.etValueAfter) + val frontPrismHeightBefore = getEtText(mBinding.ilFrontPrismHeight.etValueBefore) + val frontPrismHeightAfter = getEtText(mBinding.ilFrontPrismHeight.etValueAfter) + + viewModel.instrumentHeightBefore = instrumentHeightBefore + viewModel.instrumentHeightAfter = instrumentHeightAfter + viewModel.backPrismHeightBefore = backPrismHeightBefore + viewModel.backPrismHeightAfter = backPrismHeightAfter + viewModel.frontPrismHeightBefore = frontPrismHeightBefore + viewModel.frontPrismHeightAfter = frontPrismHeightAfter + } + + private fun editTextEmpty(et: EditText): Boolean { + return TextUtils.isEmpty(getEtText(et)) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightTraverseVm.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightTraverseVm.kt new file mode 100644 index 0000000..860d09e --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingHeightTraverseVm.kt @@ -0,0 +1,21 @@ +package com.bingce.controlnetwork.newui.stationsettingheighttraverse + +import androidx.lifecycle.ViewModel + +class StationSettingHeightTraverseVm : ViewModel() { + lateinit var stationId: String + + var instrumentHeightBefore: String? = null + var instrumentHeightAfter: String? = null + var backPrismHeightBefore: String? = null + var backPrismHeightAfter: String? = null + var frontPrismHeightBefore: String? = null + var frontPrismHeightAfter: String? = null + + var dryTemperature: String? = null + var humidityTemperature: String? = null + var airPressure: String? = null + var additionConstant: String? = null + var multiplicationConstant: String? = null + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingsHeightTraverseActivity.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingsHeightTraverseActivity.kt new file mode 100644 index 0000000..79b29cb --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/StationSettingsHeightTraverseActivity.kt @@ -0,0 +1,317 @@ +package com.bingce.controlnetwork.newui.stationsettingheighttraverse + +import android.content.Context +import android.content.Intent +import android.view.Menu +import android.view.MenuItem +import androidx.activity.viewModels +import androidx.annotation.WorkerThread +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.FragmentStatePagerAdapter +import androidx.lifecycle.lifecycleScope +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import blankj.utilcode.util.ToastUtils +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory +import com.bingce.controlapphelper.datasource.database.config.ConfigConstants +import com.bingce.controlapphelper.datasource.database.config.ConfigRecord +import com.bingce.controlapphelper.datasource.database.heighttraverse.stationsetting.model.StationSettingHeightTraverseRecord +import com.bingce.controlapphelper.model.BundleConstants +import com.bingce.controlapphelper.util.FastClickUtil +import com.bingce.controlnetwork.R +import com.bingce.controlnetwork.databinding.NewActivityStationSettingBinding +import com.bingce.controlnetwork.newui.base.BaseBindingActivity +import com.bingce.controlnetwork.util.KeyboardUtil +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +class StationSettingsHeightTraverseActivity : + BaseBindingActivity() { + + private val viewModel by viewModels() + + private val fragments = mutableListOf() + private val fragmentTitleList = listOf("仪高镜高", "环境信息") + + companion object { + @JvmStatic + fun start(context: Context, stationId: String?) { + if (stationId == null) { + return + } + context.startActivity( + Intent( + context, + StationSettingsHeightTraverseActivity::class.java + ).apply { + putExtra(BundleConstants.KEY_SURVEYOR_STATION_ID, stationId) + }) + } + } + + override fun getBinding(): NewActivityStationSettingBinding { + return NewActivityStationSettingBinding.inflate(layoutInflater) + } + + override fun initView() { + viewModel.stationId = getStationId() + initViewPager() + } + + override fun initData() { + + } + + private fun initViewPager() { + fragments.add(StationSettingHeightHeightTraverseFragment()) + fragments.add(StationSettingEnvironmentHeightTraverseFragment()) + + mBinding.vp.offscreenPageLimit = 3 + mBinding.vp.adapter = MyPagerAdapter(supportFragmentManager) + mBinding.tabLayout.setViewPager(mBinding.vp) + mBinding.vp.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + + } + + override fun onPageScrollStateChanged(state: Int) { + + } + }) + +// //设置当前tab为仪高镜高 +// mBinding.vp.currentItem = 1 + } + + + private inner class MyPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { + override fun getCount(): Int { + return fragments.size + } + + override fun getPageTitle(position: Int): CharSequence { + return fragmentTitleList[position] + } + + override fun getItem(position: Int): Fragment { + return fragments[position] + } + + override fun getItemPosition(`object`: Any): Int { + return POSITION_NONE + } + } + + private fun getStationId(): String { + return intent.getStringExtra(BundleConstants.KEY_SURVEYOR_STATION_ID)!! + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_save, menu) + return super.onCreateOptionsMenu(menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.menuSave) { + FastClickUtil.click { + KeyboardUtil.hideSoftInput() + startSave() + } + } + return super.onOptionsItemSelected(item) + } + + private fun startSave() { + //检查未完成的选项 + for (fragment in fragments) { + val operate = fragment as IStationSettingOperate + if (operate.checkSaveNot()) { + val fragmentNotFinishPos = fragments.indexOf(fragment) + if (mBinding.vp.currentItem != fragmentNotFinishPos) { + mBinding.tabLayout.currentTab = fragmentNotFinishPos + } + return + } + } + //保存到数据库 + saveData() + } + + private fun saveData() { + lifecycleScope.launch(Dispatchers.IO) { + val stationId = getStationId() + + val stationSettingHeightTraverseRecord = + SurveyorDatabaseFactory.instance.getStationSettingHeightTraverseDataSource() + .getRecordByStationId(stationId) + + if (stationSettingHeightTraverseRecord == null) { + val stationSettingHeightTraverseRecordNew = + StationSettingHeightTraverseRecord.newInstance( + stationId, + viewModel.dryTemperature!!, + viewModel.humidityTemperature!!, + viewModel.airPressure!!, + viewModel.additionConstant!!, + viewModel.multiplicationConstant!!, + viewModel.instrumentHeightBefore!!, + viewModel.instrumentHeightAfter!!, + viewModel.backPrismHeightBefore!!, + viewModel.backPrismHeightAfter!!, + viewModel.frontPrismHeightBefore!!, + viewModel.frontPrismHeightAfter!! + ) + SurveyorDatabaseFactory.instance.getStationSettingHeightTraverseDataSource() + .saveRecord(stationSettingHeightTraverseRecordNew) + } else { + stationSettingHeightTraverseRecord.dryTemperature = viewModel.dryTemperature!! + stationSettingHeightTraverseRecord.humidityTemperature = + viewModel.humidityTemperature!! + stationSettingHeightTraverseRecord.airPressure = viewModel.airPressure!! + stationSettingHeightTraverseRecord.additionConstant = viewModel.additionConstant!! + stationSettingHeightTraverseRecord.multiplicationConstant = + viewModel.multiplicationConstant!! + stationSettingHeightTraverseRecord.instrumentHeightBefore = + viewModel.instrumentHeightBefore!! + stationSettingHeightTraverseRecord.instrumentHeightAfter = + viewModel.instrumentHeightAfter!! + stationSettingHeightTraverseRecord.backPrismHeightBefore = + viewModel.backPrismHeightBefore!! + stationSettingHeightTraverseRecord.backPrismHeightAfter = + viewModel.backPrismHeightAfter!! + stationSettingHeightTraverseRecord.frontPrismHeightBefore = + viewModel.frontPrismHeightBefore!! + stationSettingHeightTraverseRecord.frontPrismHeightAfter = + viewModel.frontPrismHeightAfter!! + SurveyorDatabaseFactory.instance.getStationSettingHeightTraverseDataSource() + .updateRecord(stationSettingHeightTraverseRecord) + } + + val stationRecord = + SurveyorDatabaseFactory.instance.surveyorStation.getRecordSync(stationId) + if (stationRecord != null) { + stationRecord.instrumentHeight = viewModel.instrumentHeightBefore + if (!stationRecord.items.isNullOrEmpty()) { + stationRecord.items.last().prismHeight = viewModel.frontPrismHeightBefore + if (stationRecord.items.size > 2) { + stationRecord.items[1].prismHeight = viewModel.backPrismHeightBefore + } + } + } + SurveyorDatabaseFactory.instance.surveyorStation.update(stationRecord) + + saveLastData( + viewModel.dryTemperature!!, + viewModel.humidityTemperature!!, + viewModel.airPressure!!, + viewModel.additionConstant!!, + viewModel.multiplicationConstant!!, + viewModel.instrumentHeightBefore!!, + viewModel.instrumentHeightAfter!!, + viewModel.backPrismHeightBefore!!, + viewModel.backPrismHeightAfter!!, + viewModel.frontPrismHeightBefore!!, + viewModel.frontPrismHeightAfter!! + ) + + ToastUtils.showShort(R.string.save_success) + + } + } + + @WorkerThread + private fun saveLastData( + dryTemperature: String, + humidityTemperature: String, + airPressure: String, + additionConstant: String, + multiplicationConstant: String, + instrumentHeightBefore: String, + instrumentHeightAfter: String, + backPrismHeightBefore: String, + backPrismHeightAfter: String, + frontPrismHeightBefore: String, + frontPrismHeightAfter: String + ) { + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_DRY_TEMPERATURE, + dryTemperature + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_HUMIDITY_TEMPERATURE, + humidityTemperature + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_AIR_PRESSURE, + airPressure + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_ADDITION_CONSTANT, + additionConstant + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_MULTIPLICATION_CONSTANT, + multiplicationConstant + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_INSTRUMENT_HEIGHT_BEFORE, + instrumentHeightBefore + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_INSTRUMENT_HEIGHT_AFTER, + instrumentHeightAfter + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_BACK_PRISM_HEIGHT_BEFORE, + backPrismHeightBefore + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_BACK_PRISM_HEIGHT_AFTER, + backPrismHeightAfter + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_FRONT_PRISM_HEIGHT_BEFORE, + frontPrismHeightBefore + ) + ) + SurveyorDatabaseFactory.instance.configDataSource.recordSync( + ConfigRecord( + ConfigConstants.KEY_LAST_FRONT_PRISM_HEIGHT_AFTER, + frontPrismHeightAfter + ) + ) + } + + override fun onBackPressed() { + if (isFinishAtOnce()) { + super.onBackPressed() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingEnvironmentData.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingEnvironmentData.kt new file mode 100644 index 0000000..c63f2ef --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingEnvironmentData.kt @@ -0,0 +1,38 @@ +package com.bingce.controlnetwork.newui.stationsettingheighttraverse.model + +import androidx.annotation.WorkerThread +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory +import com.bingce.controlapphelper.datasource.database.config.ConfigConstants +import com.bingce.controlapphelper.surveyor.method.model.MeasureConstant + +class StationSettingEnvironmentData { + var temperature: String? = null + var humidity: String? = null + var airPress: String? = null + + + /** + * 获取上次数据 + */ + @WorkerThread + fun getLastData() { + val configDataSource = SurveyorDatabaseFactory.instance.getConfigDataSource() + val temperature = configDataSource.getByKeySync(ConfigConstants.KEY_LAST_TEMPERATURE) + val humidity = configDataSource.getByKeySync(ConfigConstants.KEY_LAST_HUMIDITY) + val airPress = configDataSource.getByKeySync(ConfigConstants.KEY_LAST_AIR_PRESSURE) + + this.temperature = temperature?.configValue + this.humidity = humidity?.configValue + this.airPress = airPress?.configValue + } + + /** + * 获取标准气象数据 + */ + fun getStandardData() { + this.temperature = MeasureConstant.DEFAULT_TEMPERATURE + this.humidity = MeasureConstant.DEFAULT_HUMIDITY + this.airPress = MeasureConstant.DEFAULT_AIR_PRESSURE + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingHeightData.kt b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingHeightData.kt new file mode 100644 index 0000000..6bb05e8 --- /dev/null +++ b/app/src/main/java/com/bingce/controlnetwork/newui/stationsettingheighttraverse/model/StationSettingHeightData.kt @@ -0,0 +1,58 @@ +package com.bingce.controlnetwork.newui.stationsettingheighttraverse.model + +import androidx.annotation.WorkerThread +import com.bingce.controlapphelper.datasource.database.SurveyorDatabaseFactory +import com.bingce.controlapphelper.datasource.database.surveyorstation.SurveyorStationRecord +import com.bingce.controlapphelper.datasource.database.surveyorstation.model.SurveyorPoint + + +/** + * 高度tab相关数据 + */ +class StationSettingHeightData { + + private var instrumentHeight: String? = null + val pointList = mutableListOf() + + private val pointNameMap = hashMapOf() + private val pointHeightMap = hashMapOf() + + @WorkerThread + fun initData(stationRecord: SurveyorStationRecord?) { + if (stationRecord?.items == null) return + instrumentHeight = stationRecord.instrumentHeight + + for (point in stationRecord.items) { + if (point.type == SurveyorPoint.TYPE_STATION || point.isWellSteel) { + //忽略站点和钢丝点 + continue + } + pointList.add(point) + val pointRecord = + SurveyorDatabaseFactory.instance.getPointDataSource().findByIdSync(point.originalPointId) + pointNameMap[point.originalPointId] = pointRecord.name + pointHeightMap[point.originalPointId] = point.prismHeight + } + } + + fun getPointName(pointId: String) = pointNameMap[pointId] + fun getPointHeight(pointId: String): String { + return pointHeightMap[pointId] ?: "0" + } + + fun getInstrumentHeight(): String { + return instrumentHeight ?: "0" + } + + /** + * 保存时 + */ + fun updatePointData(pointIndex: Int, pointHeight: String) { + val surveyorPoint = pointList[pointIndex] + //点高 + surveyorPoint.prismHeight = pointHeight + } + +} + + diff --git a/app/src/main/res/layout/new_fragment_station_setting_environment_height_traverse.xml b/app/src/main/res/layout/new_fragment_station_setting_environment_height_traverse.xml new file mode 100644 index 0000000..21cfbb0 --- /dev/null +++ b/app/src/main/res/layout/new_fragment_station_setting_environment_height_traverse.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/new_fragment_station_setting_height_height_traverse.xml b/app/src/main/res/layout/new_fragment_station_setting_height_height_traverse.xml new file mode 100644 index 0000000..34241bd --- /dev/null +++ b/app/src/main/res/layout/new_fragment_station_setting_height_height_traverse.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + +