From b3a6aebe50fa8ccae54522bb384841085ac78ed6 Mon Sep 17 00:00:00 2001 From: wlh <646507849@qq.com> Date: Wed, 10 Jan 2024 17:42:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E5=BB=BA365-=E4=BA=8C=E6=9C=9F?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zj365/dc/activity/MainActivity.kt | 44 +++- .../zj365/dc/activity/RecognizeResultAct.kt | 3 +- .../dc/fragment/DynamicManagementFrag.kt | 6 +- .../com/zj365/dc/fragment/HealthHomeFrag.kt | 17 +- .../java/com/zj365/dc/fragment/MineFrag.kt | 8 +- app/src/main/java/com/zj365/dc/vm/MainVm.kt | 14 ++ .../layout/frag_dynamic_management_header.xml | 1 + app/src/main/res/layout/frag_mine.xml | 5 +- common/src/main/java/com/xty/common/Const.kt | 2 + .../java/com/xty/common/arouter/ARouterUrl.kt | 6 + .../com/xty/common/weight/HealthBodyView.kt | 1 + health/src/main/AndroidManifest.xml | 7 + .../act/healthrecord/HealthRecordMainAct.kt | 206 ++++++++++++++++++ .../psychological/PsychologicalTestMainAct.kt | 30 ++- .../PsychologicalTestMainAdapter.kt | 10 +- .../zj365/health/vm/PsychologicalResultVm.kt | 20 ++ .../health/vm/PsychologicalTestMainVm.kt | 24 ++ .../zj365/health/weight/HealthSurveyView.kt | 198 +++++++++++++++++ .../res/layout/act_health_record_main.xml | 20 +- .../layout/act_psychological_test_main.xml | 21 +- .../res/layout/item_psychokogical_test.xml | 2 + .../res/layout/layout_health_record_test.xml | 7 + .../res/layout/layout_health_survey_child.xml | 15 ++ .../main/java/com/xty/network/ApiInterface.kt | 11 + .../xty/network/model/FoodRecoginzeInfo.kt | 1 + .../network/model/PsychologicalListBean.kt | 14 ++ .../network/model/PsychologicalResultBean.kt | 10 + 27 files changed, 678 insertions(+), 25 deletions(-) create mode 100644 health/src/main/java/com/zj365/health/vm/PsychologicalResultVm.kt create mode 100644 health/src/main/java/com/zj365/health/vm/PsychologicalTestMainVm.kt create mode 100644 health/src/main/java/com/zj365/health/weight/HealthSurveyView.kt create mode 100644 health/src/main/res/layout/layout_health_survey_child.xml create mode 100644 network/src/main/java/com/xty/network/model/PsychologicalListBean.kt create mode 100644 network/src/main/java/com/xty/network/model/PsychologicalResultBean.kt diff --git a/app/src/main/java/com/zj365/dc/activity/MainActivity.kt b/app/src/main/java/com/zj365/dc/activity/MainActivity.kt index 8680cb7..1341a93 100644 --- a/app/src/main/java/com/zj365/dc/activity/MainActivity.kt +++ b/app/src/main/java/com/zj365/dc/activity/MainActivity.kt @@ -40,9 +40,12 @@ import com.xty.common.aMapUtils.AmapInit import com.xty.common.arouter.ARouterUrl import com.xty.common.arouter.RouteManager import com.xty.common.bracelet.checkBlueConnectPermission +import com.xty.common.event.AddSuccessEvent +import com.xty.common.event.BindDevEvent import com.xty.common.event.LoginOrRegisterEvent import com.xty.common.event.MeasureWeightEvent import com.xty.common.event.MqttReceive +import com.xty.common.event.MyInfoEvent import com.xty.common.util.CommonToastUtils import com.xty.common.util.CommonUtils import com.xty.common.util.ViewScreenshotUtils @@ -158,6 +161,8 @@ class MainActivity : BaseVmAct(), Consumer { } if(!TextUtils.isEmpty(userId)){ + mViewModel.getIsDemonstate() + mViewModel.getMySetting() // if (BuildConfig.isRelease) {//设置极光推送别名 JPushInterface.setAlias( this, @@ -169,7 +174,8 @@ class MainActivity : BaseVmAct(), Consumer { mViewModel.getUserEquipmentInformationizationRequest(userId) mViewModel.getBanners(userId,3) - mViewModel.getIsDemonstate() + + /* if(EasyPermissions.hasPermissions(this, Manifest.permission.ACCESS_COARSE_LOCATION, @@ -290,6 +296,24 @@ class MainActivity : BaseVmAct(), Consumer { override fun liveObserver() { mViewModel.saveSuccess.observe(this) { } + + //个人设置信息获取 + mViewModel.settingLive.observe(this) { + if (null == it.data) return@observe + it.data.let { settingBean -> + + if (BuildConfig.isRelease) {//设置极光推送别名 + JPushInterface.setAlias( + this, + settingBean.user.id.toInt(), + "user_release_${settingBean.user.id}" + ) + } + Const.mainLiveData.value = settingBean +// binding.mNoNetwork.root.visibility = View.GONE + } + } + /* mViewModel.boundDevices.observe(this) { if (it.code != 0) return@observe val data = it.data @@ -462,4 +486,22 @@ class MainActivity : BaseVmAct(), Consumer { // BlueUtil.getBlueManage().releaseResource() } + @Subscribe(threadMode = ThreadMode.MAIN) + fun bindDevSuccess(event: BindDevEvent){ + mViewModel.getMySetting() + mViewModel.getIsDemonstate() + + } + @Subscribe(threadMode = ThreadMode.MAIN) + fun refreshUI(event: MyInfoEvent){ + mViewModel.getMySetting() + + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onLoginOrRegisterSuccess(event: LoginOrRegisterEvent){ + mViewModel.getMySetting() + mViewModel.getIsDemonstate() + } + } \ No newline at end of file diff --git a/app/src/main/java/com/zj365/dc/activity/RecognizeResultAct.kt b/app/src/main/java/com/zj365/dc/activity/RecognizeResultAct.kt index b8491f9..2e4e875 100644 --- a/app/src/main/java/com/zj365/dc/activity/RecognizeResultAct.kt +++ b/app/src/main/java/com/zj365/dc/activity/RecognizeResultAct.kt @@ -51,6 +51,7 @@ class RecognizeResultAct : BaseVmAct() { it.data[0].isCheck = true adapter.setNewInstance(it.data) refreshCalorieUI(it.data[0]) + foodRecoginzeInfo = it.data[0] } } @@ -78,7 +79,7 @@ class RecognizeResultAct : BaseVmAct() { binding.tvDetail.setOnClickListener { foodRecoginzeInfo?.let { bundle.clear() - bundle.putString("web_site_url","${BuildConfig.h5url}pages/index/index?pageId=mealsDetail&id=${it.id}") + bundle.putString("web_site_url","${BuildConfig.h5url}pages/index/index?pageId=mealsDetail&id=${it.recipe_id}") RouteManager.goAct(ARouterUrl.H5_ACT,bundle) } diff --git a/app/src/main/java/com/zj365/dc/fragment/DynamicManagementFrag.kt b/app/src/main/java/com/zj365/dc/fragment/DynamicManagementFrag.kt index c438a89..4d00c7d 100644 --- a/app/src/main/java/com/zj365/dc/fragment/DynamicManagementFrag.kt +++ b/app/src/main/java/com/zj365/dc/fragment/DynamicManagementFrag.kt @@ -271,9 +271,10 @@ class DynamicManagementFrag : BaseVmFrag(){ R.id.mMsg, R.id.mMsgLayout -> { RouteManager.goAct(ARouterUrl.WARNING_MSG) } - //设备连接 + //健康档案 R.id.mHealthRecords -> { + // RouteManager.goAct(ARouterUrl.FAMILY_RECORD_ACT) CommonToastUtils.showToast("敬请期待") return@OnClickListener @@ -738,6 +739,8 @@ class DynamicManagementFrag : BaseVmFrag(){ dialogInfoUn.show() } isDemonstrate = bean.demonstrate == 1 //1 演示模式,0 普通模式 + + Const.isDemonstrate = bean.demonstrate == 1 // (requireActivity() as MainActivity).isDemonstrate = isDemonstrate if (isDemonstrate) { binding.mHeader.mWearInfo.visibility = View.INVISIBLE @@ -748,6 +751,7 @@ class DynamicManagementFrag : BaseVmFrag(){ if (showIdInfo ==MMkvHelper.getLong(Const.USER_ID).toString()) { //自己 Const.otherLiveData.value = bean + binding.mHeader.mHealthRecords.visibility = View.VISIBLE } Const.battery = bean.power Const.watchType = bean.watchType diff --git a/app/src/main/java/com/zj365/dc/fragment/HealthHomeFrag.kt b/app/src/main/java/com/zj365/dc/fragment/HealthHomeFrag.kt index 82c4b25..b898bd3 100644 --- a/app/src/main/java/com/zj365/dc/fragment/HealthHomeFrag.kt +++ b/app/src/main/java/com/zj365/dc/fragment/HealthHomeFrag.kt @@ -6,6 +6,7 @@ import android.view.View import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.alibaba.android.arouter.facade.annotation.Route import com.lifesense.android.ble.core.application.ApplicationContext import com.shuyu.gsyvideoplayer.listener.VideoAllCallBack import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram @@ -248,7 +249,20 @@ HealthHomeFrag : BaseVmFrag() { when(contentData.jumpType){ 1 ->{ - CommonToastUtils.showToast("敬请期待") + when(contentData.jumpUrl){ + "health_data" ->{ + // RouteManager.goAct(ARouterUrl.FAMILY_RECORD_ACT) + CommonToastUtils.showToast("敬请期待") + } + "health_dic" ->{ + CommonToastUtils.showToast("敬请期待") + + } + else ->{ + CommonToastUtils.showToast("敬请期待") + + } + } } @@ -344,6 +358,7 @@ HealthHomeFrag : BaseVmFrag() { } "PSYCHOLOGY" ->{ + // RouteManager.goAct(ARouterUrl.PSYCHOLOGICAL_TEST_LIST_ACT) CommonToastUtils.showToast("敬请期待") } diff --git a/app/src/main/java/com/zj365/dc/fragment/MineFrag.kt b/app/src/main/java/com/zj365/dc/fragment/MineFrag.kt index 3f322ec..4c25135 100644 --- a/app/src/main/java/com/zj365/dc/fragment/MineFrag.kt +++ b/app/src/main/java/com/zj365/dc/fragment/MineFrag.kt @@ -494,7 +494,7 @@ class MineFrag : BaseVmFrag() { } else { MMkvHelper.getLong(Const.USER_ID).toString() } - mViewModel.getMySetting() + // mViewModel.getMySetting() // mViewModel.getScore(1) mViewModel.searchInviteInfo() } @@ -506,7 +506,7 @@ class MineFrag : BaseVmFrag() { @Subscribe(threadMode = ThreadMode.MAIN) fun addSuccess(event: AddSuccessEvent){ - mViewModel.getMySetting() + // mViewModel.getMySetting() mViewModel.getAllInfo(showIdInfo,false) // mViewModel.getScore(1) @@ -514,13 +514,13 @@ class MineFrag : BaseVmFrag() { @Subscribe(threadMode = ThreadMode.MAIN) fun bindDevSuccess(event:BindDevEvent){ - mViewModel.getMySetting() + // mViewModel.getMySetting() mViewModel.getAllInfo(showIdInfo,false) // mViewModel.getScore(1) } @Subscribe(threadMode = ThreadMode.MAIN) fun refreshUI(event: MyInfoEvent){ - mViewModel.getMySetting() + // mViewModel.getMySetting() mViewModel.getAllInfo(showIdInfo,false) // mViewModel.getScore(1) mViewModel.searchInviteInfo() diff --git a/app/src/main/java/com/zj365/dc/vm/MainVm.kt b/app/src/main/java/com/zj365/dc/vm/MainVm.kt index 92ce411..fccd296 100644 --- a/app/src/main/java/com/zj365/dc/vm/MainVm.kt +++ b/app/src/main/java/com/zj365/dc/vm/MainVm.kt @@ -12,6 +12,7 @@ import com.xty.network.model.BannerBean import com.xty.network.model.BindDeviceListBean import com.xty.network.model.InviteCustodyBean import com.xty.network.model.RespBody +import com.xty.network.model.SettingBean import com.xty.network.model.UnReadMessageBean import com.xty.network.model.Update import com.xty.network.model.UserEquipmentInformationizationBean @@ -41,6 +42,9 @@ class MainVm : BaseVm() { val confirmInviteLiveData by lazy { MutableLiveData>() } + val settingLive by lazy { MutableLiveData>() } + + /** * 设备类型1,血压计,2,血糖仪.3体脂秤 */ @@ -183,4 +187,14 @@ class MainVm : BaseVm() { } } } + + /** + * 个人设置接口 + */ + fun getMySetting() { + startHttp { + val body = apiInterface().getMySetting() + body.getCodeStatus(settingLive, nowData) + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/frag_dynamic_management_header.xml b/app/src/main/res/layout/frag_dynamic_management_header.xml index 5c878a1..d48a0aa 100644 --- a/app/src/main/res/layout/frag_dynamic_management_header.xml +++ b/app/src/main/res/layout/frag_dynamic_management_header.xml @@ -97,6 +97,7 @@ android:textColor="@color/white" android:textSize="@dimen/dp_10" android:textStyle="bold" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="@+id/mHeaderImage" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="@+id/mHeaderImage" /> diff --git a/app/src/main/res/layout/frag_mine.xml b/app/src/main/res/layout/frag_mine.xml index 5628452..c292303 100644 --- a/app/src/main/res/layout/frag_mine.xml +++ b/app/src/main/res/layout/frag_mine.xml @@ -131,12 +131,14 @@ + + + \ No newline at end of file diff --git a/health/src/main/java/com/zj365/health/act/healthrecord/HealthRecordMainAct.kt b/health/src/main/java/com/zj365/health/act/healthrecord/HealthRecordMainAct.kt index 13b92df..da119ae 100644 --- a/health/src/main/java/com/zj365/health/act/healthrecord/HealthRecordMainAct.kt +++ b/health/src/main/java/com/zj365/health/act/healthrecord/HealthRecordMainAct.kt @@ -1,18 +1,49 @@ package com.zj365.health.act.healthrecord +import android.util.Log import android.view.View +import androidx.core.view.get +import androidx.core.view.size +import androidx.core.widget.NestedScrollView import androidx.recyclerview.widget.LinearLayoutManager +import com.alibaba.android.arouter.facade.annotation.Route +import com.androidkun.xtablayout.XTabLayout import com.xty.base.act.BaseVmAct import com.xty.base.vm.BaseVm +import com.xty.common.Const +import com.xty.common.MMkvHelper +import com.xty.common.R +import com.xty.common.UmengEventId +import com.xty.common.arouter.ARouterUrl +import com.xty.common.arouter.RouteManager +import com.xty.common.onEventObject +import com.xty.common.setImageUser +import com.xty.common.weight.HealthBodyView import com.zj365.health.adapter.familyhealth.HealthFamilyTargetAdapter import com.zj365.health.databinding.ActHealthRecordMainBinding +import com.zj365.health.model.MyReportBean +import com.zj365.health.vm.ReportVm +import com.zj365.health.weight.HealthSurveyView +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +@Route(path = ARouterUrl.FAMILY_RECORD_ACT) class HealthRecordMainAct : BaseVmAct() { val binding by lazy { ActHealthRecordMainBinding.inflate(layoutInflater) } val mAdapter by lazy { HealthFamilyTargetAdapter() } + + private val mTitles = mutableListOf() + + private var isSelectTable = false + private var isScrollTable = false + private var launch: Job? = null + + override fun liveObserver() { } @@ -25,7 +56,182 @@ class HealthRecordMainAct : BaseVmAct() { finish() } + initTab() + initSurvey() initAdapter() + initClickListener() + + Const.mainLiveData.value?.let { + binding.tvName.text = it.user.name + if (it.user.avatarUrl.isNullOrEmpty()) { + binding.imgAvatar.setImageResource(R.mipmap.icon_default_avator) + } else { + binding.imgAvatar.setImageUser( + this, + it.user.avatarUrl, + it.user.sex.toString() + ) + } + + } + } + + fun initClickListener(){ + binding.llInquiryRecord.setOnClickListener { + + } + + binding.llHealthWeekRecord.setOnClickListener { + bundle.clear() + var showIdInfo =if (MMkvHelper.getLong(Const.USER_ID).toString() == "0") { + "" + } else { + MMkvHelper.getLong(Const.USER_ID).toString() + } + bundle.putString("id", showIdInfo) + bundle.putSerializable("index", ReportVm.ReportInfoType.Week) + bundle.putBoolean("isDemonstrate", Const.isDemonstrate) + bundle.putString("titleName", "周报") + Const.functionListDate.value?.let { + if(it.size > 0){ + bundle.putParcelableArrayList("functionList",it) + } + } + RouteManager.goAct(ARouterUrl.HEALTH_WEEK_MONTH_HOUR_REPORT, bundle) + } + + binding.llReportRecord.setOnClickListener { + + } + + binding.tvCompleteInfo.setOnClickListener { + RouteManager.goAct(ARouterUrl.BASE_INFO_CHANGE) + } + } + + fun initSurvey(){ + var surveyList = ArrayList() + + surveyList.add("免疫系统") + surveyList.add("神经系统") + surveyList.add("内分泌系统") + surveyList.add("泌尿系统") + surveyList.add("生殖系统") + surveyList.add("运动系统") + surveyList.add("心脑血管") + surveyList.add("消化系统") + surveyList.add("呼吸系统") + + binding.clBody.surveyView.setMenuItemTexts(surveyList) + + binding.clBody.surveyView.setOnClicklisteners(object : HealthSurveyView.onItemClicked{ + override fun onPositionClicked(postion: Int) { + + } + }) + } + + fun initTab(){ + mTitles.add("自检自测") + mTitles.add("饮食日记") + mTitles.add("健康监测") + mTitles.add("健康记录") + + //设置tab + mTitles.forEach { tabData -> + val tab = binding.xTablayout.newTab() + tab.text = tabData + binding.xTablayout.addTab(tab) + } + + binding.xTablayout.setOnTabSelectedListener(object : XTabLayout.OnTabSelectedListener{ + override fun onTabSelected(tab: XTabLayout.Tab?) { + + if (!isScrollTable) { + Log.e("HealthRecordMainAct", "选择的${tab?.position!!}") + isSelectTable = true + if (launch != null) { + launch?.cancel() + } + when (mTitles[tab.position]) { + "自检自测" -> { + binding.scrollView.smoothScrollTo( + 0, + binding.clSelfTest.top + ) + } + + "饮食日记" -> { + binding.scrollView.smoothScrollTo( + 0, + binding.clFoodDiary.top + ) + } + + "健康监测" -> { + binding.scrollView.smoothScrollTo( + 0, + binding.clHealthMonitoring.top + ) + } + + + "健康记录" -> { + binding.scrollView.smoothScrollTo( + 0, + binding.clHealthRecording.top + ) + } + } + + launch = GlobalScope.launch { + delay(1000) // 延迟一秒 + // 在这里执行你的操作 + isSelectTable = false + } + } + } + + override fun onTabUnselected(tab: XTabLayout.Tab?) { + } + + override fun onTabReselected(tab: XTabLayout.Tab?) { + } + + }) + + binding.scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, _ -> + if (mTitles.size > 0) { + if (!isSelectTable) { + Log.e("HealthRecordMainAct", "移动的${scrollY}") + isScrollTable = true + val selectedTabPosition = binding.xTablayout.selectedTabPosition + if (scrollY >= binding.clHealthRecording.top) { + if (selectedTabPosition != mTitles.size - 1) { + binding.xTablayout.getTabAt(mTitles.size - 1)?.select() + } + } else if (scrollY >= binding.clHealthMonitoring.top) { + if (selectedTabPosition != mTitles.size - 2) { + binding.xTablayout.getTabAt(mTitles.size - 2)?.select() + } + } else if (scrollY >= binding.clFoodDiary.top) { + if (selectedTabPosition != mTitles.size - 3) { + binding.xTablayout.getTabAt(mTitles.size - 3)?.select() + } + } else if (scrollY >= binding.clSelfTest.top) { + if (selectedTabPosition != 0) { + binding.xTablayout.getTabAt(0)?.select() + } + } else { + if (selectedTabPosition != 0) { + binding.xTablayout.getTabAt(0)?.select() + binding.xTablayout.setScrollPosition(0, 0F, true) + } + } + isScrollTable = false + } + } + }) } fun initAdapter (){ diff --git a/health/src/main/java/com/zj365/health/act/psychological/PsychologicalTestMainAct.kt b/health/src/main/java/com/zj365/health/act/psychological/PsychologicalTestMainAct.kt index f50b38f..6e4c790 100644 --- a/health/src/main/java/com/zj365/health/act/psychological/PsychologicalTestMainAct.kt +++ b/health/src/main/java/com/zj365/health/act/psychological/PsychologicalTestMainAct.kt @@ -1,12 +1,17 @@ package com.zj365.health.act.psychological import androidx.recyclerview.widget.LinearLayoutManager +import com.alibaba.android.arouter.facade.annotation.Route +import com.xty.base.act.BaseListAct import com.xty.base.act.BaseVmAct import com.xty.base.vm.BaseVm +import com.xty.common.arouter.ARouterUrl import com.zj365.health.adapter.psychological.PsychologicalTestMainAdapter import com.zj365.health.databinding.ActPsychologicalTestMainBinding +import com.zj365.health.vm.PsychologicalTestMainVm -class PsychologicalTestMainAct : BaseVmAct() { +@Route(path = ARouterUrl.PSYCHOLOGICAL_TEST_LIST_ACT) +class PsychologicalTestMainAct : BaseListAct() { val binding by lazy { ActPsychologicalTestMainBinding.inflate(layoutInflater) } val mAdapter by lazy { PsychologicalTestMainAdapter() } @@ -19,15 +24,34 @@ class PsychologicalTestMainAct : BaseVmAct() { finish() } - binding.recycler.layoutManager = LinearLayoutManager(this) - binding.recycler.adapter = mAdapter + + setRecycleRefresh(binding.mRecycle,binding.mRefresh,true) + } + + override fun initAdapter() { + + binding.mRecycle.layoutManager = LinearLayoutManager(this) + binding.mRecycle.adapter = mAdapter mAdapter.setOnItemChildClickListener { adapter, view, position -> } } + override fun loadData() { + mViewModel.getPsychologicalList(page) + } + override fun liveObserver() { + mViewModel.psychologicalListData.observe(this){ + if (page > 1){ + mAdapter.setList(it.data.records) + + }else{ + mAdapter.setNewInstance(it.data.records) + + } + } } override fun setLayout() = binding.root diff --git a/health/src/main/java/com/zj365/health/adapter/psychological/PsychologicalTestMainAdapter.kt b/health/src/main/java/com/zj365/health/adapter/psychological/PsychologicalTestMainAdapter.kt index 6ce5667..ba9c02d 100644 --- a/health/src/main/java/com/zj365/health/adapter/psychological/PsychologicalTestMainAdapter.kt +++ b/health/src/main/java/com/zj365/health/adapter/psychological/PsychologicalTestMainAdapter.kt @@ -1,11 +1,15 @@ package com.zj365.health.adapter.psychological import com.chad.library.adapter.base.viewholder.BaseViewHolder +import com.ruffian.library.widget.RImageView import com.xty.base.adapter.BaseAdapter +import com.xty.common.setImage +import com.xty.network.model.PsychologicalListBean import com.zj365.health.R -class PsychologicalTestMainAdapter : BaseAdapter(R.layout.item_psychokogical_test) { - override fun convert(holder: BaseViewHolder, item: Any) { - +class PsychologicalTestMainAdapter : BaseAdapter(R.layout.item_psychokogical_test) { + override fun convert(holder: BaseViewHolder, item: PsychologicalListBean.PsychologicalBean) { + holder.setText(R.id.tv_psy,item.surveyName) + holder.getView(R.id.img_psy).setImage(context,item.imageUrl) } } \ No newline at end of file diff --git a/health/src/main/java/com/zj365/health/vm/PsychologicalResultVm.kt b/health/src/main/java/com/zj365/health/vm/PsychologicalResultVm.kt new file mode 100644 index 0000000..b77c84e --- /dev/null +++ b/health/src/main/java/com/zj365/health/vm/PsychologicalResultVm.kt @@ -0,0 +1,20 @@ +package com.zj365.health.vm + +import androidx.lifecycle.MutableLiveData +import com.alibaba.fastjson.JSONObject +import com.xty.base.vm.BaseVm +import com.xty.network.model.PsychologicalResultBean +import com.xty.network.model.RespBody + +class PsychologicalResultVm : BaseVm() { + + val psychologicalResultData by lazy { MutableLiveData>() } + + fun getPsychologicalResult(answerId:Long){ + startHttp { + var request=apiInterface().getPsychologicalResult(answerId.toString()) + request.getCodeStatus(psychologicalResultData,nowData) + + } + } +} \ No newline at end of file diff --git a/health/src/main/java/com/zj365/health/vm/PsychologicalTestMainVm.kt b/health/src/main/java/com/zj365/health/vm/PsychologicalTestMainVm.kt new file mode 100644 index 0000000..3f7dfab --- /dev/null +++ b/health/src/main/java/com/zj365/health/vm/PsychologicalTestMainVm.kt @@ -0,0 +1,24 @@ +package com.zj365.health.vm + +import androidx.lifecycle.MutableLiveData +import com.alibaba.fastjson.JSONObject +import com.xty.base.vm.BaseVm +import com.xty.network.model.PsychologicalListBean +import com.xty.network.model.RespBody + +class PsychologicalTestMainVm: BaseVm() { + + val psychologicalListData by lazy { MutableLiveData>() } + + fun getPsychologicalList(pageNum:Int){ + startHttp { + var json = JSONObject() + json.put("pageNum",pageNum) + json.put("pageSize",10) + + var request=apiInterface().getPsychologicalList(retrofits.getRequestBody(json.toString())) + request.getCodeStatus(psychologicalListData,nowData) + + } + } +} \ No newline at end of file diff --git a/health/src/main/java/com/zj365/health/weight/HealthSurveyView.kt b/health/src/main/java/com/zj365/health/weight/HealthSurveyView.kt new file mode 100644 index 0000000..76d0156 --- /dev/null +++ b/health/src/main/java/com/zj365/health/weight/HealthSurveyView.kt @@ -0,0 +1,198 @@ +package com.zj365.health.weight + +import android.content.Context +import android.graphics.Color +import android.provider.CalendarContract.Colors +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import com.google.android.exoplayer2.util.ColorParser +import com.xty.common.LogUtils +import com.zj365.health.R +import kotlin.math.cos +import kotlin.math.roundToInt +import kotlin.math.sin + +class HealthSurveyView(context: Context, attrs: AttributeSet?) : ViewGroup(context, attrs) { + + + //圆形直径 + var mRadius = 0 + + //该容器内child item 的默认尺寸 + val RADIO_DEFAULT_CHILD_DIMESION = 1 /4f + + // 该容器的内边距,无视padding属性 , 如需边距请用该变量 + val RADIO_PADDING_LAYOUT = 1 / 12f + var mPadding = 0f + + // 布局时的开始角度 + var mStartAngle = 270.0 + + //文本 + var mSurveyText = ArrayList() + + var colors = arrayOf("#20C387","#FD830B","#1ECAFC") + + + //数 + var mCount = 12 + + var mItemLayoutId: Int = R.layout.layout_health_survey_child + + var mOnClicklistener: onItemClicked? = null + fun setMenuItemTexts( texts: ArrayList) { + require(!( texts == null)) { "菜单文本和图标至少设置其一" } + mSurveyText = texts + //初始化mMenucount + mCount = texts.size + //构建菜单项 + buildMenuItems() + } + + + private fun buildMenuItems() { + //根据用户设置的参数,初始化menu item + for (i in 0 until mCount) { + val itemView = inflateMenuView(i) + initMenuItem(itemView, i) + addView(itemView) + } + } + + private fun inflateMenuView(index: Int): View { + val mInflater = LayoutInflater.from(context) + val itemView: View = mInflater.inflate(mItemLayoutId, this, false) + itemView.setOnClickListener(object : OnClickListener { + override fun onClick(p0: View?) { + mOnClicklistener?.onPositionClicked(index) + } + + }) + return itemView + } + + private fun initMenuItem(itemView: View, index: Int) { + val tv = itemView.findViewById(R.id.tv_survey) + tv.text = mSurveyText[index] + when(index){ + 0,2,4,6 ->{ + tv.setTextColor(Color.parseColor(colors[0])) + } + 1,5,7->{ + tv.setTextColor(Color.parseColor(colors[1])) + } + else ->{ + tv.setTextColor(Color.parseColor(colors[2])) + + } + } + } + + fun setMenuItemLayoutId(mItemLayoutId: Int) { + this.mItemLayoutId = mItemLayoutId + } + + fun setOnClicklisteners(mOnClicklistener: onItemClicked) { + this. mOnClicklistener = mOnClicklistener + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + // 测量自己 + measureSelf(widthMeasureSpec, heightMeasureSpec) + // 测量菜单 + measureChildViews() + } + + private fun measureSelf(widthMeasureSpec: Int, heightMeasureSpec: Int) { + var resWidth = 0 + var resHeight = 0 + val width = MeasureSpec.getSize(widthMeasureSpec) + val widthMode = MeasureSpec.getMode(widthMeasureSpec) + val heigh = MeasureSpec.getSize(heightMeasureSpec) + val heightMode = MeasureSpec.getMode(heightMeasureSpec) + + //如果宽或者高的测量模式非精确值 + /* if (widthMode != MeasureSpec.EXACTLY || + heightMode != MeasureSpec.EXACTLY + ) { + //设置为背景图的宽高 + resWidth = suggestedMinimumWidth + //如果未设置背景图,则设置为屏幕宽高的默认值 + resWidth = if (resWidth == 0) getDefaultWidth() else resWidth + resHeight = if (resHeight == 0) getDefaultWidth() else resHeight + } else {*/ + resHeight = Math.min(width, heigh) + resWidth = resHeight +// } + setMeasuredDimension(resWidth, resHeight) + } + + private fun getDefaultWidth(): Int { + return (mRadius * RADIO_DEFAULT_CHILD_DIMESION).toInt() + } + + private fun measureChildViews() { + //获得半径 + mRadius = Math.max(measuredWidth, measuredWidth) + //menu item 数量 + val count = childCount + //menu 尺寸 + val childSize = (mRadius * RADIO_DEFAULT_CHILD_DIMESION).toInt() + // menu item 测量模式 + val childMode = MeasureSpec.EXACTLY + //迭代测量 + for (i in 0 until count) { + val child = getChildAt(i) + if (child.visibility == GONE) { + continue + } + // 计算menu item 的尺寸 , 以及设置好的模式,去对item进行测量 + var makeMeasureSpec = -1 + makeMeasureSpec = MeasureSpec.makeMeasureSpec(childSize, childMode) + child.measure(makeMeasureSpec, makeMeasureSpec) + } +// mPadding = RADIO_PADDING_LAYOUT * mRadius + } + + override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { + val childCount = childCount + var left: Int + var top: Int + // menu item 的尺寸 + val itemWidth = (mRadius * RADIO_DEFAULT_CHILD_DIMESION).toInt() + // 根据menuitem 的个数 计算item的布局占用的角度 + if(childCount > 0){ + val angleDelay = (360 / childCount).toFloat() + // 遍历所有菜单 设置它们的位置 + for (i in 0 until childCount) { + val child = getChildAt(i) + if (child.visibility == GONE) { + continue + } + //菜单的起始角度 + mStartAngle %= 360.0 + //计算 中心点到menuitem 中心的距离 + val distanceFromCenter = mRadius / 2f - itemWidth / 2 + left = + mRadius / 2 + (distanceFromCenter * cos(Math.toRadians(mStartAngle)) - 1 / 2f * itemWidth).roundToInt() + + top = + mRadius / 2 + (distanceFromCenter * sin(Math.toRadians(mStartAngle)) - 1 / 2f * itemWidth).roundToInt() + + LogUtils.e("HealthSurveyView","left:${left},top:${top},itemWidth${itemWidth},mRadius:${mRadius},distanceFromCenter:${distanceFromCenter}") + + child.layout(left, top, left + itemWidth, top + itemWidth) + mStartAngle += angleDelay.toDouble() + } + } + + } + + interface onItemClicked{ + fun onPositionClicked(postion:Int) + } +} \ No newline at end of file diff --git a/health/src/main/res/layout/act_health_record_main.xml b/health/src/main/res/layout/act_health_record_main.xml index 4b616da..0edf067 100644 --- a/health/src/main/res/layout/act_health_record_main.xml +++ b/health/src/main/res/layout/act_health_record_main.xml @@ -54,7 +54,7 @@ android:id="@+id/mProgress" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="@dimen/dp_9" android:layout_marginLeft="@dimen/dp_10" android:layout_marginTop="@dimen/dp_14" android:layout_below="@+id/tv_name" @@ -269,6 +269,7 @@ android:drawableRight="@mipmap/icon_arrow_right" android:drawablePadding="@dimen/dp_5" app:layout_constraintEnd_toEndOf="parent" + android:textSize="@dimen/sp_13" app:layout_constraintTop_toBottomOf="@+id/mTvFoodDiary" android:layout_marginTop="@dimen/dp_22"/> @@ -337,7 +338,7 @@ - + android:layout_height="match_parent"> + + + + + + + \ No newline at end of file diff --git a/health/src/main/res/layout/item_psychokogical_test.xml b/health/src/main/res/layout/item_psychokogical_test.xml index 5d8d242..59a33ac 100644 --- a/health/src/main/res/layout/item_psychokogical_test.xml +++ b/health/src/main/res/layout/item_psychokogical_test.xml @@ -14,6 +14,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:is_circle="false" + android:scaleType="fitXY" + android:adjustViewBounds="true" app:corner_radius="@dimen/dp_8"/> @@ -29,6 +30,12 @@ android:layout_marginTop="@dimen/dp_9"/> + + diff --git a/health/src/main/res/layout/layout_health_survey_child.xml b/health/src/main/res/layout/layout_health_survey_child.xml new file mode 100644 index 0000000..5932227 --- /dev/null +++ b/health/src/main/res/layout/layout_health_survey_child.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/network/src/main/java/com/xty/network/ApiInterface.kt b/network/src/main/java/com/xty/network/ApiInterface.kt index c0db521..5a056cf 100644 --- a/network/src/main/java/com/xty/network/ApiInterface.kt +++ b/network/src/main/java/com/xty/network/ApiInterface.kt @@ -794,6 +794,17 @@ interface ApiInterface { @POST("customer/question/reportList") suspend fun getAnswerList(@Body rb: RequestBody): RespBody> + /** + * 心理测试问卷列表 + */ + @POST("customer/surveys/list") + suspend fun getPsychologicalList(@Body rb: RequestBody):RespBody + + /** + * 答题详情 + */ + @GET("customer/surveys/answerDetail") + suspend fun getPsychologicalResult(@Query("answerId") answerId:String):RespBody /** * 设备解绑 */ diff --git a/network/src/main/java/com/xty/network/model/FoodRecoginzeInfo.kt b/network/src/main/java/com/xty/network/model/FoodRecoginzeInfo.kt index 46b85f9..f1007ec 100644 --- a/network/src/main/java/com/xty/network/model/FoodRecoginzeInfo.kt +++ b/network/src/main/java/com/xty/network/model/FoodRecoginzeInfo.kt @@ -37,6 +37,7 @@ data class FoodRecoginzeInfo( val as_name:String,//别名 val fe:Float,//铁(mg/100g) + val recipe_id:Long, var isCheck:Boolean = false ) { } \ No newline at end of file diff --git a/network/src/main/java/com/xty/network/model/PsychologicalListBean.kt b/network/src/main/java/com/xty/network/model/PsychologicalListBean.kt new file mode 100644 index 0000000..527f094 --- /dev/null +++ b/network/src/main/java/com/xty/network/model/PsychologicalListBean.kt @@ -0,0 +1,14 @@ +package com.xty.network.model + +data class PsychologicalListBean( + var records:ArrayList +){ + data class PsychologicalBean( + var id:Long, + var surveyName:String, + var surveyDesc:String, + var totalNum:Int, + var imageUrl:String, + var createTime:String + ) +} diff --git a/network/src/main/java/com/xty/network/model/PsychologicalResultBean.kt b/network/src/main/java/com/xty/network/model/PsychologicalResultBean.kt new file mode 100644 index 0000000..440ad1b --- /dev/null +++ b/network/src/main/java/com/xty/network/model/PsychologicalResultBean.kt @@ -0,0 +1,10 @@ +package com.xty.network.model + +data class PsychologicalResultBean( + var surveyName:String, + var surveyDesc:String, + var conclusionText:String, + var answerId:Long, + var score:String +) { +} \ No newline at end of file