| | |
| | | package com.hdl.photovoltaic.ui.powerstation; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.hardware.camera2.CameraManager; |
| | | import android.os.Bundle; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.bean.BaseEventBus; |
| | | 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.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.utils.PermissionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | 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 |
| | | public Object getContentView() { |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | private void initEvent() { |
| | | |
| | | viewBinding.toolbarTopFragmentHouseListRl.topMoreIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(_mActivity, FastScanActivity.class); |
| | | startActivity(intent); |
| | | |
| | | // 打开小程序页面 |
| | | // HdlUniLogic.getInstance().openUniMP(HDLUniMP.UNI_EVENT_OPEN_HOME_CREATION, null); |
| | | requestPermissions(new PermissionsResultCallback() { |
| | | @Override |
| | | public void succeed() { |
| | | // 打开小程序页面 |
| | | 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); |
| | | updateUIData(true); |
| | | Log.d("HouseListFragment", "下拉刷新"); |
| | | } |
| | | }); |
| | | houseInfoAdapter.setNoOnclickListener(new HouseInfoAdapter.OnclickListener() { |
| | | @Override |
| | | public void onClick(int position, HouseIdBean houseIdBean) { |
| | | //点击住宅详情 |
| | | HdlLogLogic.print("====点击住宅详情" + position); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean.getHomeId()); |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId(); |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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); |
| | | viewBinding.fragmentHouseSrlListRc.setLayoutManager(linearLayout); |
| | | viewBinding.fragmentHouseSrlListRc.setAdapter(houseInfoAdapter); |
| | | |
| | |
| | | } |
| | | |
| | | 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<>(); |
| | | // for (int i = 0; i < 11; i++) { |
| | | // HouseListBean houseListBean = new HouseListBean(); |
| | | // houseListBean.setHomeName("电站" + i); |
| | | // this.houseListBeanList.add(houseListBean); |
| | | // } |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | } |
| | | |
| | | @Override |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | super.onEventMessage(eventBus); |
| | | //收到EventBUs通知 |
| | | if (ConstantManage.EVENTBUS_POST_HOME_CREATED.equals(eventBus.getType())) { |
| | | updateUIData(false); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 刷新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(); |
| | | } |
| | | } |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (isRefreshing) { |
| | | //关闭下拉刷新的圈圈 |
| | | viewBinding.fragmentHouseSrl.setRefreshing(false); |
| | | } |
| | | |
| | | } |
| | | }, _mActivity, ShowErrorMode.YES); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 申请权限 |
| | | */ |
| | | private void requestPermissions(PermissionsResultCallback permissionsResultCallback) { |
| | | |
| | | |
| | | mPermissionsResultCallback = permissionsResultCallback; |
| | | //Manifest.permission.CAMERA, |
| | | String[] s = new String[]{ |
| | | Manifest.permission.ACCESS_FINE_LOCATION, |
| | | }; |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, s); |
| | | if (ary.length > 0) { |
| | | requestPermissions(ary, PermissionUtils.STATUS_SUCCESS); |
| | | } else { |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | if (requestCode == PermissionUtils.STATUS_SUCCESS) { |
| | | for (int i = 0; i < permissions.length; i++) { |
| | | if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
| | | if (mPermissionsResultCallback != null) { |
| | | mPermissionsResultCallback.succeed(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private PermissionsResultCallback mPermissionsResultCallback; |
| | | |
| | | public interface PermissionsResultCallback { |
| | | |
| | | void succeed(); |
| | | |
| | | void failing(); |
| | | |
| | | } |
| | | |
| | | } |