hxb
2022-11-23 d3c787f75211fda9ea84a4709d5ab9528a0a68a6
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
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();
    }
}