| | |
| | | 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; |
| | |
| | | |
| | | private List<LanguageAdapter.ItemData> mList; |
| | | |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | | viewBinding = ActivityTemperatureUnitBinding.inflate(getLayoutInflater()); |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); |
| | | readData(); |
| | | //初始化 |
| | | initView(); |
| | |
| | | } |
| | | |
| | | private void readData() { |
| | | |
| | | mList = new ArrayList<>(); |
| | | LanguageAdapter.ItemData c = new LanguageAdapter.ItemData(); |
| | | c.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())) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | private void initEvent() { |
| | | |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | setResult(40); |
| | | backPressedData(); |
| | | finish(); |
| | | } |
| | | }); |
| | |
| | | } |
| | | mList.get(position).setState(true); |
| | | languageAdapter.notifyDataSetChanged(); |
| | | UserConfigManage.getInstance().setTemperature_unit(itemData.getUnit()); |
| | | UserConfigManage.getInstance().Save(); |
| | | setResidenceTemperatureUnit(itemData.getUnit()); |
| | | |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print(e.getMessage(), false); |
| | | } |
| | |
| | | |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.set_temperature_unit); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null)); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null)); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |