|
|
@ -1,11 +1,13 @@
|
|
|
|
package com.zj365.health.fragment
|
|
|
|
package com.zj365.health.fragment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.content.res.ColorStateList
|
|
|
|
import android.content.res.ColorStateList
|
|
|
|
import android.graphics.Color
|
|
|
|
import android.graphics.Color
|
|
|
|
import android.graphics.Typeface
|
|
|
|
import android.graphics.Typeface
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Build
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.text.TextUtils
|
|
|
|
import android.text.TextUtils
|
|
|
|
|
|
|
|
import android.util.SparseArray
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import android.widget.TextView
|
|
|
|
import android.widget.TextView
|
|
|
@ -24,6 +26,9 @@ import com.xty.common.*
|
|
|
|
import com.xty.common.arouter.ARouterUrl
|
|
|
|
import com.xty.common.arouter.ARouterUrl
|
|
|
|
import com.xty.common.arouter.RouteManager
|
|
|
|
import com.xty.common.arouter.RouteManager
|
|
|
|
import com.xty.common.audioUtils.RecordAudio
|
|
|
|
import com.xty.common.audioUtils.RecordAudio
|
|
|
|
|
|
|
|
import com.xty.common.weight.tablayout.TabEntity
|
|
|
|
|
|
|
|
import com.xty.common.weight.tablayout.listener.CustomTabEntity
|
|
|
|
|
|
|
|
import com.xty.common.weight.tablayout.listener.OnTabSelectListener
|
|
|
|
import com.zj365.health.R
|
|
|
|
import com.zj365.health.R
|
|
|
|
import com.zj365.health.act.HealthMainAct
|
|
|
|
import com.zj365.health.act.HealthMainAct
|
|
|
|
import com.zj365.health.databinding.FragSleepNewBinding
|
|
|
|
import com.zj365.health.databinding.FragSleepNewBinding
|
|
|
@ -51,17 +56,17 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
|
|
|
|
|
|
|
|
private val musicInfoBinding by lazy { SleepMusicInfoBinding.bind(binding.root)}
|
|
|
|
private val musicInfoBinding by lazy { SleepMusicInfoBinding.bind(binding.root)}
|
|
|
|
val timeDaySelect by lazy{TimeSelect(requireContext()){
|
|
|
|
val timeDaySelect by lazy{TimeSelect(requireContext()){
|
|
|
|
var time=binding.mTime.text.toString()
|
|
|
|
var time=binding.tvShowDate.text.toString()
|
|
|
|
getData(time)
|
|
|
|
getData(time)
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
val timeMonthSelect by lazy{TimeSelect(requireContext()){
|
|
|
|
val timeMonthSelect by lazy{TimeSelect(requireContext()){
|
|
|
|
var time=binding.mTime.text.toString()
|
|
|
|
var time=binding.tvShowDate.text.toString()
|
|
|
|
getData(time)
|
|
|
|
getData(time)
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
val timeYearSelect by lazy{TimeSelect(requireContext()){
|
|
|
|
val timeYearSelect by lazy{TimeSelect(requireContext()){
|
|
|
|
var time=binding.mTime.text.toString()
|
|
|
|
var time=binding.tvShowDate.text.toString()
|
|
|
|
getData(time)
|
|
|
|
getData(time)
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|
|
|
@ -101,8 +106,86 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
private val activeSize = 15F
|
|
|
|
private val activeSize = 15F
|
|
|
|
private val normalSize = 15F
|
|
|
|
private val normalSize = 15F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val mTabEntities: ArrayList<CustomTabEntity> = ArrayList()
|
|
|
|
|
|
|
|
private val mTitles = arrayOf(
|
|
|
|
|
|
|
|
"日", "周", "月", "年"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun initTab() {
|
|
|
|
|
|
|
|
mTabEntities.clear()
|
|
|
|
|
|
|
|
listFrag.clear()
|
|
|
|
|
|
|
|
if (id.isNullOrEmpty()) {
|
|
|
|
|
|
|
|
listFrag.add(SleepStaticDayFrag())
|
|
|
|
|
|
|
|
listFrag.add(SleepStatisticWeekFrag())
|
|
|
|
|
|
|
|
listFrag.add(SleepStatisticMonthFrag())
|
|
|
|
|
|
|
|
listFrag.add(SleepStatisticYearFrag())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
listFrag.add(setArgumentFrag(SleepStaticDayFrag(), id))
|
|
|
|
|
|
|
|
listFrag.add(setArgumentFrag(SleepStatisticWeekFrag(), id))
|
|
|
|
|
|
|
|
listFrag.add(setArgumentFrag(SleepStatisticMonthFrag(), id))
|
|
|
|
|
|
|
|
listFrag.add(setArgumentFrag(SleepStatisticYearFrag(), id))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.mVp2.adapter = MyAdapter(this,listFrag,requireActivity(),childFragmentManager)
|
|
|
|
|
|
|
|
binding.mVp2.isUserInputEnabled =false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTitles.forEach {
|
|
|
|
|
|
|
|
mTabEntities.add(
|
|
|
|
|
|
|
|
TabEntity(
|
|
|
|
|
|
|
|
it, android.R.drawable.ic_delete, android.R.drawable.ic_delete
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.commonTabLayout.setTabData(mTabEntities)
|
|
|
|
|
|
|
|
binding.commonTabLayout.setOnTabSelectListener(object : OnTabSelectListener {
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
|
|
|
|
override fun onTabSelect(position: Int) {
|
|
|
|
|
|
|
|
binding.commonTabLayout.currentTab = position
|
|
|
|
|
|
|
|
binding.mVp2.setCurrentItem(position, false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showSelectTime()
|
|
|
|
|
|
|
|
//这个view是的fragment。
|
|
|
|
|
|
|
|
if (initFrag){
|
|
|
|
|
|
|
|
initFrag = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val view = listFrag[position].view
|
|
|
|
|
|
|
|
view?.let {
|
|
|
|
|
|
|
|
updatePagerHeightForChild(view)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when (position) {
|
|
|
|
|
|
|
|
0 -> {
|
|
|
|
|
|
|
|
// binding.tvShowDate.text = dayDate
|
|
|
|
|
|
|
|
showSelectTime()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 -> {
|
|
|
|
|
|
|
|
// binding.tvShowDate.text = weekDate
|
|
|
|
|
|
|
|
showSelectTime()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 -> {
|
|
|
|
|
|
|
|
// binding.tvShowDate.text = mouthDate
|
|
|
|
|
|
|
|
showSelectTime()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 -> {
|
|
|
|
|
|
|
|
// binding.tvShowDate.text = yearDate
|
|
|
|
|
|
|
|
showSelectTime()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onTabReselect(position: Int) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*binding.mVp2.post {
|
|
|
|
|
|
|
|
binding.commonTabLayout.
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private fun initTabVp2() {
|
|
|
|
private fun initTabVp2() {
|
|
|
|
var mediator = TabLayoutMediator(
|
|
|
|
var mediator = TabLayoutMediator(
|
|
|
|
binding.tabLayout, binding.mVp2
|
|
|
|
binding.tabLayout, binding.mVp2
|
|
|
@ -119,7 +202,7 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
tabView.setText(tabs[position])
|
|
|
|
tabView.setText(tabs[position])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tabView.setTextSize(normalSize)
|
|
|
|
// tabView.setTextSize(normalSize)
|
|
|
|
tabView.setTextColor(colorStateList)
|
|
|
|
tabView.setTextColor(colorStateList)
|
|
|
|
tab.setCustomView(tabView)
|
|
|
|
tab.setCustomView(tabView)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -146,10 +229,10 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
val tab: TabLayout.Tab = binding.tabLayout.getTabAt(i)!!
|
|
|
|
val tab: TabLayout.Tab = binding.tabLayout.getTabAt(i)!!
|
|
|
|
val tabView = tab.customView as TextView?
|
|
|
|
val tabView = tab.customView as TextView?
|
|
|
|
if (tab.position == position) {
|
|
|
|
if (tab.position == position) {
|
|
|
|
tabView!!.textSize = activeSize.toFloat()
|
|
|
|
//tabView!!.textSize = activeSize.toFloat()
|
|
|
|
tabView!!.setTypeface(Typeface.DEFAULT_BOLD)
|
|
|
|
tabView!!.setTypeface(Typeface.DEFAULT_BOLD)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
tabView!!.textSize = normalSize
|
|
|
|
// tabView!!.textSize = normalSize
|
|
|
|
tabView!!.setTypeface(Typeface.DEFAULT)
|
|
|
|
tabView!!.setTypeface(Typeface.DEFAULT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -200,7 +283,8 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
super.initView()
|
|
|
|
super.initView()
|
|
|
|
isDemonstrate = (requireActivity() as HealthMainAct).isDemonstrate
|
|
|
|
isDemonstrate = (requireActivity() as HealthMainAct).isDemonstrate
|
|
|
|
// mViewModel.getSetting(Const.SLEEP_SETTING)
|
|
|
|
// mViewModel.getSetting(Const.SLEEP_SETTING)
|
|
|
|
initTabVp2()
|
|
|
|
// initTabVp2()
|
|
|
|
|
|
|
|
initTab()
|
|
|
|
initTimeSelect()
|
|
|
|
initTimeSelect()
|
|
|
|
val assets = context?.assets?.open("forest.mp3")
|
|
|
|
val assets = context?.assets?.open("forest.mp3")
|
|
|
|
//保存到手机的路劲
|
|
|
|
//保存到手机的路劲
|
|
|
@ -283,7 +367,7 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
showSelectTime()
|
|
|
|
showSelectTime()
|
|
|
|
binding.mTime.setOnClickListener {
|
|
|
|
binding.tvShowDate.setOnClickListener {
|
|
|
|
val currentFragment = getCurrentFragment()
|
|
|
|
val currentFragment = getCurrentFragment()
|
|
|
|
if (currentFragment is SleepStaticDayFrag){
|
|
|
|
if (currentFragment is SleepStaticDayFrag){
|
|
|
|
timeDaySelect.selectTime(it,"yyyy-MM-dd")
|
|
|
|
timeDaySelect.selectTime(it,"yyyy-MM-dd")
|
|
|
@ -296,6 +380,19 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* binding.ivPosition.setOnClickListener {
|
|
|
|
|
|
|
|
val currentFragment = getCurrentFragment()
|
|
|
|
|
|
|
|
if (currentFragment is SleepStaticDayFrag){
|
|
|
|
|
|
|
|
timeDaySelect.selectTime(it,"yyyy-MM-dd")
|
|
|
|
|
|
|
|
} else if (currentFragment is SleepStatisticWeekFrag) {
|
|
|
|
|
|
|
|
bottomSheetDialog?.show()
|
|
|
|
|
|
|
|
} else if (currentFragment is SleepStatisticMonthFrag) {
|
|
|
|
|
|
|
|
timeMonthSelect.selectTimeWithYearMonth(it,"yyyy-MM")
|
|
|
|
|
|
|
|
} else if (currentFragment is SleepStatisticYearFrag) {
|
|
|
|
|
|
|
|
timeYearSelect.selectTimeWithYear(it,"yyyy")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
initBottomDialog()
|
|
|
|
initBottomDialog()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -328,7 +425,9 @@ class SleepFrag : BaseVmFrag<SleepVm>() {
|
|
|
|
timeYearSelect.selectTime
|
|
|
|
timeYearSelect.selectTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.mTime.text = showTime
|
|
|
|
// binding.mTime.text = showTime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.tvShowDate.text = showTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
override fun onDestroy() {
|
|
|
|