diff --git a/app/src/main/java/com/casic/br/extensions/ViewGroup.kt b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt new file mode 100644 index 0000000..1bb5d99 --- /dev/null +++ b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt @@ -0,0 +1,29 @@ +package com.casic.br.extensions + +import android.view.View +import android.view.ViewGroup +import com.casic.br.utils.LocaleConstant + +fun ViewGroup.disableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_DISABLE + this.isEnabled = false + view.forEach { + it.isEnabled = false + } +} + +fun ViewGroup.enableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_ENABLE + this.isEnabled = true + view.forEach { + it.isEnabled = true + } +} + +fun ViewGroup.disableView() { + this.isEnabled = false +} + +fun ViewGroup.enableView() { + this.isEnabled = true +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/extensions/ViewGroup.kt b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt new file mode 100644 index 0000000..1bb5d99 --- /dev/null +++ b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt @@ -0,0 +1,29 @@ +package com.casic.br.extensions + +import android.view.View +import android.view.ViewGroup +import com.casic.br.utils.LocaleConstant + +fun ViewGroup.disableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_DISABLE + this.isEnabled = false + view.forEach { + it.isEnabled = false + } +} + +fun ViewGroup.enableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_ENABLE + this.isEnabled = true + view.forEach { + it.isEnabled = true + } +} + +fun ViewGroup.disableView() { + this.isEnabled = false +} + +fun ViewGroup.enableView() { + this.isEnabled = true +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt index d140792..babe659 100644 --- a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt @@ -35,6 +35,14 @@ /** * ============================================================================================= + * Float + * ============================================================================================= + * */ + const val VIEW_ENABLE = 1.0f + const val VIEW_DISABLE = 0.3f + + /** + * ============================================================================================= * Int * ============================================================================================= * */ diff --git a/app/src/main/java/com/casic/br/extensions/ViewGroup.kt b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt new file mode 100644 index 0000000..1bb5d99 --- /dev/null +++ b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt @@ -0,0 +1,29 @@ +package com.casic.br.extensions + +import android.view.View +import android.view.ViewGroup +import com.casic.br.utils.LocaleConstant + +fun ViewGroup.disableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_DISABLE + this.isEnabled = false + view.forEach { + it.isEnabled = false + } +} + +fun ViewGroup.enableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_ENABLE + this.isEnabled = true + view.forEach { + it.isEnabled = true + } +} + +fun ViewGroup.disableView() { + this.isEnabled = false +} + +fun ViewGroup.enableView() { + this.isEnabled = true +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt index d140792..babe659 100644 --- a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt @@ -35,6 +35,14 @@ /** * ============================================================================================= + * Float + * ============================================================================================= + * */ + const val VIEW_ENABLE = 1.0f + const val VIEW_DISABLE = 0.3f + + /** + * ============================================================================================= * Int * ============================================================================================= * */ diff --git a/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt b/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt index 075a6de..4deb17a 100644 --- a/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt +++ b/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt @@ -6,6 +6,8 @@ import com.bumptech.glide.Glide import com.casic.br.R import com.casic.br.extensions.createCommand +import com.casic.br.extensions.disableLayout +import com.casic.br.extensions.enableLayout import com.casic.br.extensions.initLayoutImmersionBar import com.casic.br.utils.CommandManager import com.google.gson.Gson @@ -164,11 +166,37 @@ "1" -> {//开关机 isDeviceWorking = parseObject[it] as Boolean if (isDeviceWorking) { - //工作中 + /** + * 已开机 + * */ deviceStateButton.text = "关机" + + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) } else { - //未工作 + /** + * 已关机 + * */ deviceStateButton.text = "开机" + + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.disableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) } } "2" -> {//延时关机状态,{"105":90,"11":"delay","2":true}|{"11":"low","2":false} @@ -177,6 +205,11 @@ delayTimeView.text = "已取消" } delayTurnOffSwitch.isChecked = isDelay + if (isDeviceWorking) { + delayLayout.enableLayout(delayTurnOffSwitch) + } else { + delayLayout.disableLayout(delayTurnOffSwitch) + } } "4" -> {//照明 val isLighting = parseObject[it] as Boolean @@ -203,10 +236,40 @@ "101" -> {//清洁,{"10":"off","101":true,"11":"wash"}|{"101":false,"11":"off"} val isCleaning = parseObject[it] as Boolean cleanSwitch.isChecked = isCleaning + if (isCleaning) { + modeLayout.disableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.disableLayout(cruiseSwitch) + delayLayout.disableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } else { + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) + } } "102" -> {//假日通风 val isVentilating = parseObject[it] as Boolean ventilateSwitch.isChecked = isVentilating + if (isVentilating) { + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + } } "103" -> {//通风时长 ventilateTimeView.text = @@ -215,6 +278,41 @@ "104" -> {//巡航 val isCruising = parseObject[it] as Boolean cruiseSwitch.isChecked = isCruising + if (isCruising) { + if (isDeviceWorking) { + modeLayout.enableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } else { + modeLayout.enableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) + } + } else { + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } } "105" -> {//延时关机倒计时 delayTimeView.text = @@ -288,64 +386,6 @@ }) } - private fun configFunctionPanel( - isTurnOn: Boolean, - isSpeedEnable: Boolean, - isCleanEnable: Boolean, - isLightEnable: Boolean, - isCruiseEnable: Boolean, - isDelayEnable: Boolean, - isVentilateEnable: Boolean, - isVentilateTimeEnable: Boolean, - isAntiPourDownEnable: Boolean - ) { -// if (isTurnOn) { -// switchButtonLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// switchButtonLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isSpeedEnable) { -// speedLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// speedLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isCleanEnable) { -// cleanLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// cleanLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isLightEnable) { -// lightLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// lightLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isCruiseEnable) { -// cruiseLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//巡航 -// } else { -// cruiseLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//巡航 -// } -// if (isDelayEnable) { -// delayLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// delayLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isVentilateEnable) { -// ventilateLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//通风 -// } else { -// ventilateLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//通风 -// } -// if (isVentilateTimeEnable) { -// ventilateTimeLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// ventilateTimeLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isAntiPourDownEnable) { -// antiPourDownLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//防倒灌 -// } else { -// antiPourDownLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//防倒灌 -// } - } - override fun onDestroy() { super.onDestroy() deviceInstance.unRegisterDevListener() diff --git a/app/src/main/java/com/casic/br/extensions/ViewGroup.kt b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt new file mode 100644 index 0000000..1bb5d99 --- /dev/null +++ b/app/src/main/java/com/casic/br/extensions/ViewGroup.kt @@ -0,0 +1,29 @@ +package com.casic.br.extensions + +import android.view.View +import android.view.ViewGroup +import com.casic.br.utils.LocaleConstant + +fun ViewGroup.disableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_DISABLE + this.isEnabled = false + view.forEach { + it.isEnabled = false + } +} + +fun ViewGroup.enableLayout(vararg view: View) { + this.alpha = LocaleConstant.VIEW_ENABLE + this.isEnabled = true + view.forEach { + it.isEnabled = true + } +} + +fun ViewGroup.disableView() { + this.isEnabled = false +} + +fun ViewGroup.enableView() { + this.isEnabled = true +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt index d140792..babe659 100644 --- a/app/src/main/java/com/casic/br/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/utils/LocaleConstant.kt @@ -35,6 +35,14 @@ /** * ============================================================================================= + * Float + * ============================================================================================= + * */ + const val VIEW_ENABLE = 1.0f + const val VIEW_DISABLE = 0.3f + + /** + * ============================================================================================= * Int * ============================================================================================= * */ diff --git a/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt b/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt index 075a6de..4deb17a 100644 --- a/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt +++ b/app/src/main/java/com/casic/br/view/device/RangeHoodActivity.kt @@ -6,6 +6,8 @@ import com.bumptech.glide.Glide import com.casic.br.R import com.casic.br.extensions.createCommand +import com.casic.br.extensions.disableLayout +import com.casic.br.extensions.enableLayout import com.casic.br.extensions.initLayoutImmersionBar import com.casic.br.utils.CommandManager import com.google.gson.Gson @@ -164,11 +166,37 @@ "1" -> {//开关机 isDeviceWorking = parseObject[it] as Boolean if (isDeviceWorking) { - //工作中 + /** + * 已开机 + * */ deviceStateButton.text = "关机" + + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) } else { - //未工作 + /** + * 已关机 + * */ deviceStateButton.text = "开机" + + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.disableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) } } "2" -> {//延时关机状态,{"105":90,"11":"delay","2":true}|{"11":"low","2":false} @@ -177,6 +205,11 @@ delayTimeView.text = "已取消" } delayTurnOffSwitch.isChecked = isDelay + if (isDeviceWorking) { + delayLayout.enableLayout(delayTurnOffSwitch) + } else { + delayLayout.disableLayout(delayTurnOffSwitch) + } } "4" -> {//照明 val isLighting = parseObject[it] as Boolean @@ -203,10 +236,40 @@ "101" -> {//清洁,{"10":"off","101":true,"11":"wash"}|{"101":false,"11":"off"} val isCleaning = parseObject[it] as Boolean cleanSwitch.isChecked = isCleaning + if (isCleaning) { + modeLayout.disableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.disableLayout(cruiseSwitch) + delayLayout.disableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } else { + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + lightLayout.enableLayout(lightSwitch) + cruiseLayout.enableLayout(cruiseSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) + } } "102" -> {//假日通风 val isVentilating = parseObject[it] as Boolean ventilateSwitch.isChecked = isVentilating + if (isVentilating) { + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + } } "103" -> {//通风时长 ventilateTimeView.text = @@ -215,6 +278,41 @@ "104" -> {//巡航 val isCruising = parseObject[it] as Boolean cruiseSwitch.isChecked = isCruising + if (isCruising) { + if (isDeviceWorking) { + modeLayout.enableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } else { + modeLayout.enableLayout( + lowSpeedView, highSpeedView, maxSpeedView + ) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.enableLayout(ventilateSwitch) + if (ventilateSwitch.isChecked) { + ventilateTimeLayout.enableLayout(ventilateTimeView) + } else { + ventilateTimeLayout.disableLayout(ventilateTimeView) + } + antiPourDownLayout.enableLayout(antiPourDownSwitch) + } + } else { + modeLayout.enableLayout(lowSpeedView, highSpeedView, maxSpeedView) + cleanLayout.enableLayout(cleanSwitch) + lightLayout.enableLayout(lightSwitch) + delayLayout.enableLayout(delayTurnOffSwitch) + ventilateLayout.disableLayout(ventilateSwitch) + ventilateTimeLayout.disableLayout(ventilateTimeView) + antiPourDownLayout.disableLayout(antiPourDownSwitch) + } } "105" -> {//延时关机倒计时 delayTimeView.text = @@ -288,64 +386,6 @@ }) } - private fun configFunctionPanel( - isTurnOn: Boolean, - isSpeedEnable: Boolean, - isCleanEnable: Boolean, - isLightEnable: Boolean, - isCruiseEnable: Boolean, - isDelayEnable: Boolean, - isVentilateEnable: Boolean, - isVentilateTimeEnable: Boolean, - isAntiPourDownEnable: Boolean - ) { -// if (isTurnOn) { -// switchButtonLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// switchButtonLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isSpeedEnable) { -// speedLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// speedLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isCleanEnable) { -// cleanLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// cleanLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isLightEnable) { -// lightLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// lightLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isCruiseEnable) { -// cruiseLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//巡航 -// } else { -// cruiseLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//巡航 -// } -// if (isDelayEnable) { -// delayLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// delayLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isVentilateEnable) { -// ventilateLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//通风 -// } else { -// ventilateLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//通风 -// } -// if (isVentilateTimeEnable) { -// ventilateTimeLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10) -// } else { -// ventilateTimeLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10) -// } -// if (isAntiPourDownEnable) { -// antiPourDownLayout.setBackgroundResource(R.drawable.bg_solid_layout_white_radius_10)//防倒灌 -// } else { -// antiPourDownLayout.setBackgroundResource(R.drawable.bg_solid_layout_hint_radius_10)//防倒灌 -// } - } - override fun onDestroy() { super.onDestroy() deviceInstance.unRegisterDevListener() diff --git a/app/src/main/res/layout/activity_range_hood.xml b/app/src/main/res/layout/activity_range_hood.xml index 6d6eec2..2a1419e 100644 --- a/app/src/main/res/layout/activity_range_hood.xml +++ b/app/src/main/res/layout/activity_range_hood.xml @@ -146,7 +146,7 @@