New file |
| | |
| | | package com.hdl.hdlsdk.device; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.os.Bundle; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlsdk.R; |
| | | import com.hdl.hdlsdk.bean.FunctionBean; |
| | | import com.hdl.sdk.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.common.utils.gson.GsonConvert; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | | import com.hdl.sdk.connect.bean.response.BaseLocalResponse; |
| | | import com.hdl.sdk.connect.callback.HDLLinkCallBack; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class DevicesListActivity extends AppCompatActivity { |
| | | |
| | | private static final String TAG = "DevicesListActivity"; |
| | | private List<FunctionBean> devicesList = new ArrayList<>(); |
| | | private DevicesListAdapter mDevicesListAdapter; |
| | | private RecyclerView mRecyclerView; |
| | | private View view; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(R.layout.activity_devices_list); |
| | | |
| | | initView(); |
| | | initData(); |
| | | } |
| | | |
| | | @SuppressLint("WrongConstant") |
| | | private void initView() { |
| | | mRecyclerView = findViewById(R.id.device_list_rv); |
| | | mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); |
| | | mDevicesListAdapter = new DevicesListAdapter(this, devicesList); |
| | | mRecyclerView.setAdapter(mDevicesListAdapter); |
| | | |
| | | view = findViewById(R.id.rl_back); |
| | | view.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initData() { |
| | | getFunctionList(); |
| | | } |
| | | |
| | | /** |
| | | * 获取设备列表 |
| | | */ |
| | | void getFunctionList(){ |
| | | |
| | | HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() { |
| | | @Override |
| | | public void onError(HDLLinkException error) { |
| | | Log.e(TAG,error.getMsg()); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | Log.i(TAG, "获取设备列表成功"); |
| | | handelFunList(data); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | void handelFunList(String data){ |
| | | try { |
| | | final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() { |
| | | }.getType()); |
| | | |
| | | final BaseLocalResponse<List<FunctionBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<FunctionBean>>>() { |
| | | }.getType()); |
| | | devicesList.clear(); |
| | | devicesList.addAll(bean.getObjects()); |
| | | mDevicesListAdapter.notifyDataSetChanged(); |
| | | }catch (Exception e){ |
| | | Log.e(TAG, "handelFunList: " + e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | } |