[m1]
[温度调整]
This commit is contained in:
yangyakun
2023-02-06 15:08:33 +08:00
parent 8be7ac4f0e
commit 211c702fb0
4 changed files with 97 additions and 42 deletions

View File

@@ -0,0 +1,3 @@
package com.mogo.och.bus.passenger.bean
data class Temperature(val index:Int,val value:Int,val showTitle:String)

View File

@@ -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<String> {
val mutableListOf = mutableListOf<String>()
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<Temperature> {
val mutableListOf = mutableListOf<Temperature>()
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}

View File

@@ -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<TemperatureAdapter.TextVH> {
private Context context;
private List<String> dataList;
private List<Temperature> dataList;
private RecyclerView recyclerView;
public TemperatureAdapter(Context context, List<String> dataList, RecyclerView recyclerView) {
public TemperatureAdapter(Context context, List<Temperature> dataList, RecyclerView recyclerView) {
this.context = context;
this.dataList = dataList;
this.recyclerView = recyclerView;
@@ -37,15 +39,13 @@ public class TemperatureAdapter extends RecyclerView.Adapter<TemperatureAdapter.
}
@Override
public void onBindViewHolder(TextVH holder, final int position) {
TextVH textVH = holder;
textVH.pickerTxt.setText(dataList.get(position));
textVH.pickerTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (recyclerView != null) {
recyclerView.smoothScrollToPosition(position);
}
public void onBindViewHolder(TextVH holder, int position) {
Temperature temperature = dataList.get(holder.getBindingAdapterPosition());
holder.pickerTxt.setText(temperature.getShowTitle());
holder.pickerTxt.setTag(temperature);
holder.pickerTxt.setOnClickListener(v -> {
if (recyclerView != null) {
recyclerView.smoothScrollToPosition(position);
}
});
}
@@ -55,11 +55,15 @@ public class TemperatureAdapter extends RecyclerView.Adapter<TemperatureAdapter.
return dataList.size();
}
public void swapData(List<String> newData) {
public void swapData(List<Temperature> newData) {
dataList = newData;
notifyDataSetChanged();
}
public List<Temperature> getData(){
return dataList;
}
class TextVH extends RecyclerView.ViewHolder {
TextView pickerTxt;

View File

@@ -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;
}
}
}