diff --git a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/bean/Temperature.kt b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/bean/Temperature.kt new file mode 100644 index 0000000000..84ea0e4ab8 --- /dev/null +++ b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/bean/Temperature.kt @@ -0,0 +1,3 @@ +package com.mogo.och.bus.passenger.bean + +data class Temperature(val index:Int,val value:Int,val showTitle:String) \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/BusPassengerFunctionSoftFragment.kt b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/BusPassengerFunctionSoftFragment.kt index 84f6d5b1f6..d910a1c474 100644 --- a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/BusPassengerFunctionSoftFragment.kt +++ b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/BusPassengerFunctionSoftFragment.kt @@ -12,12 +12,14 @@ import android.widget.SeekBar.OnSeekBarChangeListener import android.widget.TextView import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearSnapHelper +import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.SnapHelper import com.mogo.commons.mvp.MvpFragment import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant import com.mogo.eagle.core.utilcode.util.ToastUtils import com.mogo.och.bus.passenger.R +import com.mogo.och.bus.passenger.bean.Temperature import com.mogo.och.bus.passenger.presenter.BusPassengerFunctionSoftPresenter import com.mogo.och.bus.passenger.ui.adapter.TemperatureAdapter import com.mogo.och.bus.passenger.view.HorizontalDecoration @@ -39,6 +41,8 @@ class BusPassengerFunctionSoftFragment : override fun getTagName(): String = TAG + private var currentTemperature:Temperature?=null + override fun initViews() { rg_select_function.setOnCheckedChangeListener { group, checkedId -> when (checkedId) { @@ -105,6 +109,18 @@ class BusPassengerFunctionSoftFragment : } } } + val pickerLayoutManager = PickerLayoutManager(requireContext(), PickerLayoutManager.HORIZONTAL, false) + pickerLayoutManager.isChangeAlpha = true + pickerLayoutManager.scaleDownBy = 0.39f + pickerLayoutManager.scaleDownDistance = 0.8f + + val adapter = TemperatureAdapter(requireContext(), getData(), rv_aircondition_temperature) + val snapHelper: SnapHelper = LinearSnapHelper() + snapHelper.attachToRecyclerView(rv_aircondition_temperature) + rv_aircondition_temperature.layoutManager = pickerLayoutManager + rv_aircondition_temperature.adapter = adapter + rv_aircondition_temperature.addItemDecoration(HorizontalDecoration(20)) + // 风速调节 rg_setting_windspeed.setOnCheckedChangeListener { group, checkedId -> if (rg_setting_windspeed.tag == touchTag) { @@ -120,39 +136,37 @@ class BusPassengerFunctionSoftFragment : } } - val pickerLayoutManager = PickerLayoutManager(requireContext(), PickerLayoutManager.HORIZONTAL, false) - pickerLayoutManager.isChangeAlpha = true - pickerLayoutManager.scaleDownBy = 0.39f - pickerLayoutManager.scaleDownDistance = 0.8f - - val adapter = TemperatureAdapter(requireContext(), getData(), rv_aircondition_temperature) - val snapHelper: SnapHelper = LinearSnapHelper() - snapHelper.attachToRecyclerView(rv_aircondition_temperature) - rv_aircondition_temperature.layoutManager = pickerLayoutManager - rv_aircondition_temperature.adapter = adapter - rv_aircondition_temperature.addItemDecoration(HorizontalDecoration(20)) - - pickerLayoutManager.setOnScrollStopListener { view -> if (view is TextView) { - ToastUtils.showShort(view.text) + val tag = view.tag + if (tag is Temperature) { + currentTemperature = tag + ToastUtils.showShort(tag.value) + if(rv_aircondition_temperature.tag== touchTag){ + rv_aircondition_temperature.tag = null + }else { + SoundPoolHelper.getSoundPoolHelper() + .playSoundWithRedId(context, R.raw.bus_di) + } + openAircondition() + } } } } - private fun getData(): MutableList { - val mutableListOf = mutableListOf() - mutableListOf.add("16°") - mutableListOf.add("17°") - mutableListOf.add("18°") - mutableListOf.add("19°") - mutableListOf.add("20°") - mutableListOf.add("21°") - mutableListOf.add("22°") - mutableListOf.add("23°") - mutableListOf.add("24°") - mutableListOf.add("25°") - mutableListOf.add("26°") + private fun getData(): MutableList { + val mutableListOf = mutableListOf() + mutableListOf.add(Temperature(0,16,"16°")) + mutableListOf.add(Temperature(1,17,"17°")) + mutableListOf.add(Temperature(2,18,"18°")) + mutableListOf.add(Temperature(3,19,"19°")) + mutableListOf.add(Temperature(4,20,"20°")) + mutableListOf.add(Temperature(5,21,"21°")) + mutableListOf.add(Temperature(6,22,"22°")) + mutableListOf.add(Temperature(7,23,"23°")) + mutableListOf.add(Temperature(8,24,"24°")) + mutableListOf.add(Temperature(9,25,"25°")) + mutableListOf.add(Temperature(10,26,"26°")) return mutableListOf } @@ -171,7 +185,7 @@ class BusPassengerFunctionSoftFragment : CallerLogger.d(SceneConstant.M_BUS_P+ TAG,"打开空调") var modeCmd = 0 var windSpeedCmd = 0 - var temperatureCmd = 0 + val temperatureCmd = currentTemperature?.value?:26 closeHeater()//关闭暖风 when (rg_setting_pattern.checkedRadioButtonId) { R.id.rb_pattern_automatic -> modeCmd = 1 // 自动 @@ -185,7 +199,7 @@ class BusPassengerFunctionSoftFragment : R.id.rb_wind_speed_high -> windSpeedCmd = 3 // 3档 else -> {} } - mPresenter?.sendRoboBusJinlvM1AirConditionerCmd(1,modeCmd,windSpeedCmd,20) + mPresenter?.sendRoboBusJinlvM1AirConditionerCmd(1,modeCmd,windSpeedCmd,temperatureCmd) } /** @@ -200,7 +214,15 @@ class BusPassengerFunctionSoftFragment : tv_aircondition_switch.isChecked = true } if(airIsOpen){ - // TODO: 差一个温度 + val adapter = rv_aircondition_temperature.adapter + if (adapter is TemperatureAdapter) { + adapter.data.forEach { + if (it.value==temperatureCmd) { + rv_aircondition_temperature.tag = touchTag + rv_aircondition_temperature.smoothScrollToPosition(it.index) + } + } + } rg_setting_pattern.tag = touchTag when (pattern) {//1: 自动模式, 2: 制冷模式, 3: 通风模式(仅送风,无温度) 1 -> {rb_pattern_automatic.isChecked = true} diff --git a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/adapter/TemperatureAdapter.java b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/adapter/TemperatureAdapter.java index 55d13e1bc6..cf181e721a 100644 --- a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/adapter/TemperatureAdapter.java +++ b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/ui/adapter/TemperatureAdapter.java @@ -9,6 +9,8 @@ import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import com.mogo.och.bus.passenger.R; +import com.mogo.och.bus.passenger.bean.Temperature; +import com.mogo.och.bus.passenger.view.PickerLayoutManager; import java.util.List; @@ -19,10 +21,10 @@ import java.util.List; public class TemperatureAdapter extends RecyclerView.Adapter { private Context context; - private List dataList; + private List dataList; private RecyclerView recyclerView; - public TemperatureAdapter(Context context, List dataList, RecyclerView recyclerView) { + public TemperatureAdapter(Context context, List dataList, RecyclerView recyclerView) { this.context = context; this.dataList = dataList; this.recyclerView = recyclerView; @@ -37,15 +39,13 @@ public class TemperatureAdapter extends RecyclerView.Adapter { + if (recyclerView != null) { + recyclerView.smoothScrollToPosition(position); } }); } @@ -55,11 +55,15 @@ public class TemperatureAdapter extends RecyclerView.Adapter newData) { + public void swapData(List newData) { dataList = newData; notifyDataSetChanged(); } + public List getData(){ + return dataList; + } + class TextVH extends RecyclerView.ViewHolder { TextView pickerTxt; diff --git a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/view/PickerLayoutManager.java b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/view/PickerLayoutManager.java index 7a4608ef2d..1236314a66 100644 --- a/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/view/PickerLayoutManager.java +++ b/OCH/mogo-och-bus-passenger/src/m1/java/com/mogo/och/bus/passenger/view/PickerLayoutManager.java @@ -1,9 +1,11 @@ package com.mogo.och.bus.passenger.view; import android.content.Context; +import android.util.DisplayMetrics; import android.view.View; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; public class PickerLayoutManager extends LinearLayoutManager { @@ -52,6 +54,13 @@ public class PickerLayoutManager extends LinearLayoutManager { } } + @Override + public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { + RecyclerView.SmoothScroller smoothScroller = new CenterSmoothScroller(recyclerView.getContext()); + smoothScroller.setTargetPosition(position); + startSmoothScroll(smoothScroller); + } + @Override public void onScrollStateChanged(int state) { super.onScrollStateChanged(state); @@ -105,4 +114,21 @@ public class PickerLayoutManager extends LinearLayoutManager { public interface onScrollStopListener { void selectedView(View view); } + + private static class CenterSmoothScroller extends LinearSmoothScroller { + + CenterSmoothScroller(Context context) { + super(context); + } + + @Override + public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { + return (boxStart + (boxEnd - boxStart) / 2) - (viewStart + (viewEnd - viewStart) / 2); + } + + @Override + protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { + return 100f / displayMetrics.densityDpi; + } + } }