| | |
| | | import android.content.pm.PackageManager; |
| | | import android.hardware.camera2.CameraManager; |
| | | import android.os.Bundle; |
| | | import android.os.SystemClock; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.NonNull; |
| | |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.FragmentHouseListBinding; |
| | | import com.hdl.photovoltaic.base.CustomBaseFragment; |
| | | import com.hdl.photovoltaic.databinding.LoadingConfirmInputBinding; |
| | | import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | | 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.HouseInfoAdapter; |
| | | import com.hdl.photovoltaic.ui.bean.HouseListBean; |
| | | import com.hdl.photovoltaic.ui.device.FastScanActivity; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.photovoltaic.widget.ConfirmationInputDialog; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import io.dcloud.feature.unimp.DCUniMPJSCallback; |
| | | |
| | | /** |
| | | * (住宅)电站列表-界面 |
| | | */ |
| | | public class HouseListFragment extends CustomBaseFragment { |
| | | |
| | | public static final String SORT_TYPE_1 = "powerSort";//发电功率排序 |
| | | public static final String SORT_TYPE_2 = "todayElectricitySort";//今日发电量排序 |
| | | public static final String SORT_TYPE_3 = "createTimeSort";//创建时间排序 |
| | | public static final String DESCENDING = "descending";//降序 |
| | | public static final String ASCENDING = "ascending";//升序 |
| | | public static final String SELECTED_SORT_TYPE = SORT_TYPE_1; |
| | | public static final String SELECTED_SORT = DESCENDING; |
| | | |
| | | private FragmentHouseListBinding viewBinding; |
| | | private HouseInfoAdapter houseInfoAdapter; |
| | | private CameraManager manager; |
| | | |
| | | private List<HouseListBean> houseListBeanList = null; |
| | | private List<HouseIdBean> houseListBeanIDList = null; |
| | | |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | manager = (CameraManager) _mActivity.getSystemService(Context.CAMERA_SERVICE); |
| | | |
| | | initData(); |
| | | //初始化 |
| | | initView(); |
| | |
| | | |
| | | private void initEvent() { |
| | | |
| | | |
| | | //添加电站 |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | // 打开小程序页面 |
| | | HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_HOME_CREATION, null); |
| | | requestPermissions(new PermissionsResultCallback() { |
| | | @Override |
| | | public void succeed() { |
| | | |
| | | // Intent intent = new Intent(); |
| | | // intent.setClass(_mActivity, FastScanActivity.class); |
| | | // startActivity(intent); |
| | | // // 打开小程序页面 |
| | | HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null); |
| | | } |
| | | |
| | | @Override |
| | | public void failing() { |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | //设置下拉箭头颜色 |
| | |
| | | viewBinding.fragmentHouseSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | Log.d("HouseListFragment", "下拉刷新"); |
| | | updateUIData(true); |
| | | HdlLogLogic.print("HouseListFragment下拉刷新", false); |
| | | } |
| | | }); |
| | | houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() { |
| | | @Override |
| | | public void onClick(int position) { |
| | | public void onClick(int position, HouseIdBean houseIdBean) { |
| | | //点击住宅详情 |
| | | HdlLogLogic.print("====点击住宅详情" + position); |
| | | if (houseListBeanList == null || houseListBeanList.size() <= 0) { |
| | | return; |
| | | } |
| | | HouseListBean houseListBean = houseListBeanList.get(position); |
| | | String path = HDLUniMP.UNI_EVENT_HOME_CREATION + "?homeId=" + houseListBean.getHomeId(); |
| | | HdlLogLogic.print("点击住宅详情--->" + new Gson().toJson(houseIdBean), false); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS |
| | | + "?homeId=" + houseIdBean.getHomeId() |
| | | + "&homeName=" + houseIdBean.getHomeName() |
| | | + "&powerStationStatus=" + houseIdBean.getPowerStationStatus(); |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station_我的电站); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topTitleTv.setText(R.string.my_power_station); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setImageResource(R.drawable.add); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(_mActivity); |
| | | houseInfoAdapter = new HouseInfoAdapter(this.houseListBeanList); |
| | | houseInfoAdapter = new HouseInfoAdapter(this.houseListBeanIDList, _mActivity); |
| | | viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout); |
| | | viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter); |
| | | |
| | | |
| | | this.nullDataUpdateUi(houseListBeanIDList); |
| | | |
| | | |
| | | } |
| | | |
| | | private void initData() { |
| | | this.houseListBeanList = new ArrayList<>(); |
| | | for (int i = 0; i < 11; i++) { |
| | | HouseListBean houseListBean = new HouseListBean(); |
| | | houseListBean.setHomeName("电站" + i); |
| | | this.houseListBeanList.add(houseListBean); |
| | | this.houseListBeanIDList = new ArrayList<>(); |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | } |
| | | |
| | | /** |
| | | * 收到EventBUs通知 |
| | | * |
| | | * @param eventBus 数据 |
| | | */ |
| | | @Override |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | super.onEventMessage(eventBus); |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(eventBus.getTopic())) { |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) { |
| | | //uin创建电站成功后通知 |
| | | updateUIData(false); |
| | | if (eventBus.getData() != null) { |
| | | Gson gson = new Gson(); |
| | | String json = eventBus.getData().toString(); |
| | | HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT.equals(eventBus.getType())) { |
| | | //todo 现在默认刷新全部 |
| | | //uin编辑住宅通知 |
| | | // String homeId = HdlUniLogic.getInstance().getKeyValue("homeId", eventBus.getData()); |
| | | // String home_name = HdlUniLogic.getInstance().getKeyValue("powerStationName", eventBus.getData()); |
| | | // if (TextUtils.isEmpty(homeId) || TextUtils.isEmpty(home_name)) { |
| | | // return; |
| | | // } |
| | | // int index = -1; |
| | | // for (int i = 0; i < houseListBeanIDList.size(); i++) { |
| | | // HouseIdBean houseIdBean = houseListBeanIDList.get(i); |
| | | // if (houseIdBean.getHomeId().equals(homeId)) { |
| | | // index = i; |
| | | // houseIdBean.setHomeName(home_name); |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (index > -1) { |
| | | // if (houseInfoAdapter != null) { |
| | | // //更新单个数据 |
| | | // houseInfoAdapter.notifyItemChanged(index); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) { |
| | | //uin关闭住宅详情界面通知 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().removeAllTopic(); |
| | | } |
| | | updateUIData(false); |
| | | |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) { |
| | | //进去住宅详情uni读取逆变器列表成功后通知 |
| | | // for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().size(); i++) { |
| | | //String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().get(i).getGatewayId(); |
| | | //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值; |
| | | //String topic = "/user/" + gatewayId+"/1"; |
| | | //进去住宅详情开始订阅主题 |
| | | MqttRecvClient.getInstance().checkAndsubscribeAllTopics(""); |
| | | // } |
| | | } else if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) { |
| | | //接收外部点击事件 |
| | | if (eventBus.getType().equals(HomepageTitleTabSwitch.powerstation.toString())) { |
| | | HdlLogLogic.print("正在点击【电站】"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 刷新UI |
| | | * |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | */ |
| | | private void updateUIData(boolean isRefreshing) { |
| | | //获取住宅(电站)ID列表 |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | @Override |
| | | public void onSuccess(List<HouseIdBean> list) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | } |
| | | if (list != null && list.size() > 0) { |
| | | //更新缓存 |
| | | HdlResidenceLogic.getInstance().setHouseIdList(list); |
| | | if (houseInfoAdapter != null) { |
| | | //更新UI |
| | | houseInfoAdapter.setList(list); |
| | | houseInfoAdapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | } |
| | | nullDataUpdateUi(list); |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | } |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 申请权限 |
| | | */ |
| | | private void requestPermissions() { |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.CAMERA}); |
| | | private void requestPermissions(PermissionsResultCallback permissionsResultCallback) { |
| | | |
| | | |
| | | mPermissionsResultCallback = permissionsResultCallback; |
| | | |
| | | String[] s = new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA,}; |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, s); |
| | | if (ary.length > 0) { |
| | | requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); |
| | | } else { |
| | | startActivity(FastScanActivity.class); |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (requestCode == PermissionUtils.STATUS_SUCCESS) { |
| | | for (int i = 0; i < permissions.length; i++) { |
| | | if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
| | | startActivity(FastScanActivity.class); |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | private PermissionsResultCallback mPermissionsResultCallback; |
| | | |
| | | public interface PermissionsResultCallback { |
| | | |
| | | void succeed(); |
| | | |
| | | void failing(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |
| | | private void nullDataUpdateUi(List<HouseIdBean> list) { |
| | | if (list != null && list.size() > 0) { |
| | | viewBinding.nullListTv.setVisibility(View.GONE); |
| | | } else { |
| | | viewBinding.nullListTv.setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |