wjc
2025-04-10 13420bde01402f662559045910bf0dece36a3926
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.hdl.photovoltaic.ui.me;
 
import androidx.recyclerview.widget.LinearLayoutManager;
 
import android.os.Bundle;
import android.view.View;
 
import com.google.gson.JsonObject;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.ActivityTemperatureUnitBinding;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.ui.adapter.LanguageAdapter;
import com.hdl.photovoltaic.uni.HDLUniMP;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 温度单位的界面
 */
public class TemperatureUnitActivity extends CustomBaseActivity {
 
    private ActivityTemperatureUnitBinding viewBinding;
    private LanguageAdapter languageAdapter;
 
    private List<LanguageAdapter.ItemData> mList;
 
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityTemperatureUnitBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setStatusBarTranslucent();
        getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
        readData();
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
 
 
    }
 
    private void readData() {
 
        mList = new ArrayList<>();
        LanguageAdapter.ItemData c = new LanguageAdapter.ItemData();
        c.setState(false);
        c.setTitle(getString(R.string.set_c));
        c.setUnit("℃");
        mList.add(c);
        LanguageAdapter.ItemData f = new LanguageAdapter.ItemData();
        f.setState(false);
        f.setTitle(getString(R.string.set_f));
        f.setUnit("℉");
        mList.add(f);
        for (int i = 0; i < mList.size(); i++) {
            LanguageAdapter.ItemData itemData = mList.get(i);
            if (itemData.getUnit().equals(UserConfigManage.getInstance().getTemperature_unit())) {
                //初始化之前状态
                itemData.setState(true);
            }
        }
 
 
    }
 
    private void initEvent() {
 
        viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                backPressedData();
                finish();
            }
        });
 
        languageAdapter.setNoOnclickListener(new LanguageAdapter.OnclickListener() {
            @Override
            public void onClick(int position, LanguageAdapter.ItemData itemData) {
                try {
                    if (position < 0 || position > mList.size()) {
                        return;
                    }
                    for (int i = 0; i < mList.size(); i++) {
                        LanguageAdapter.ItemData data = mList.get(i);
                        data.setState(false);
                    }
                    mList.get(position).setState(true);
                    languageAdapter.notifyDataSetChanged();
                    setResidenceTemperatureUnit(itemData.getUnit());
 
                } catch (Exception e) {
                    HdlLogLogic.print(e.getMessage(), false);
                }
            }
        });
 
    }
 
 
    private void initView() {
        viewBinding.toolbarTopRl.topTitleTv.setText(R.string.set_temperature_unit);
        viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE);
        LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity);
        languageAdapter = new LanguageAdapter(this.mList, _mActivity);
        viewBinding.languageRc.setLayoutManager(linearLayout);
        viewBinding.languageRc.setAdapter(languageAdapter);
    }
 
    /**
     * 配置住宅温度单位
     *
     * @param unit 单位
     */
    private void setResidenceTemperatureUnit(String unit) {
        if (UserConfigManage.getInstance().getTemperature_unit().equals(unit)) {
            return;
        }
        String tempType = "C";
        if (unit.contains("℃")) {
            tempType = "C";
        } else {
            tempType = "F";
        }
        HdlResidenceLogic.getInstance().setResidenceTemperatureUnit(tempType, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                UserConfigManage.getInstance().setTemperature_unit(unit);
                UserConfigManage.getInstance().Save();
            }
 
            @Override
            public void onFailure(HDLException e) {
                HdlThreadLogic.toast(_mActivity, e);
            }
        });
    }
 
    /**
     * 物理按键返回事件
     */
    @Override
    public void onBackPressed() {
        backPressedData();
        super.onBackPressed();
    }
 
    /**
     * 返回给上一级界面数据
     */
    private void backPressedData() {
        setResult(40);
        //通知给小程序更新温度单位
        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("temperature_unit", UserConfigManage.getInstance().getTemperature_unit());
        uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_TEMPERATURE);
        uniCallBackBaseBean.setData(jsonObject);
        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
    }
 
 
}