wxr
2022-11-24 7c3d23232c5c0328131d2b560e6224dd0d566f01
AndroidOpenDemo/app/src/main/java/com/utils/DeviceUtils.java
New file
@@ -0,0 +1,94 @@
package com.utils;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.common.openapi.ClassInstanceManager;
import com.common.openapi.DeviceSubAccountListService;
import com.common.openapi.IGetDeviceInfoCallBack;
import com.common.openapi.MethodConst;
import com.common.openapi.entity.DeviceDetailListData;
import com.lechange.demo.ui.DeviceDetailActivity;
import com.lechange.demo.ui.DeviceListActivity;
import com.lechange.demo.ui.DeviceOnlineMediaPlayActivity;
import com.mm.android.deviceaddmodule.openapi.HDLMD5Utils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
 * Created by hxb on 2022/11/22.
 */
public class DeviceUtils implements IGetDeviceInfoCallBack.ISubAccountDevice< DeviceDetailListData.Response>  {
    private String deviceId;
    public DeviceUtils(String deviceId){
        this.deviceId=deviceId;
    }
    private static List<DeviceDetailListData.ResponseData.DeviceListBean> datas = new ArrayList<>();
    private void getDeviceList() {
        DeviceSubAccountListService deviceSubAccountListService = ClassInstanceManager.newInstance().getDeviceSubAccountListService();
        deviceSubAccountListService.getSubAccountDeviceList(1,this);
    }
    public void play() {
        for (DeviceDetailListData.ResponseData.DeviceListBean deviceListBean : datas) {
            if (deviceListBean.deviceId.equals(deviceId)) {
                if (!deviceListBean.status.equals("online")) {
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putSerializable(MethodConst.ParamConst.deviceDetail, deviceListBean);
                Intent intent = new Intent(HdlToLcUtils.getInstance().getActivity(), DeviceOnlineMediaPlayActivity.class);
                intent.putExtras(bundle);
                HdlToLcUtils.getInstance().getActivity().startActivity(intent);
                return;
            }
        }
        getDeviceList();
    }
    @Override
    public void DeviceList(DeviceDetailListData.Response responseData) {
        if (responseData.data != null && responseData.data.deviceList != null && responseData.data.deviceList.size() != 0) {
            Iterator<DeviceDetailListData.ResponseData.DeviceListBean> iterator = responseData.data.deviceList.iterator();
            while (iterator.hasNext()) {
                DeviceDetailListData.ResponseData.DeviceListBean next = iterator.next();
                if (next.channels != null && next.channels.size() == 0 && !next.catalog.contains("NVR")) {
                    // 使用迭代器中的remove()方法,可以删除元素.
                    iterator.remove();
                }
            }
        }
        if ((responseData.data == null || responseData.data.deviceList == null || responseData.data.deviceList.size() == 0)) {
            return;
        }
        datas.addAll(responseData.data.deviceList);
        for (DeviceDetailListData.ResponseData.DeviceListBean deviceListBean : datas) {
            if (deviceListBean.deviceId.equals(deviceId)) {
                if (!deviceListBean.status.equals("online")) {
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putSerializable(MethodConst.ParamConst.deviceDetail, deviceListBean);
                Intent intent = new Intent(HdlToLcUtils.getInstance().getActivity(), DeviceOnlineMediaPlayActivity.class);
                intent.putExtras(bundle);
                HdlToLcUtils.getInstance().getActivity().startActivity(intent);
                return;
            }
        }
    }
    @Override
    public void onError(Throwable throwable) {
        Toast.makeText(HdlToLcUtils.getInstance().getActivity(), throwable.getMessage(), Toast.LENGTH_SHORT).show();
    }
}