设备详情-区域选择-完成
parent
78c2d157bf
commit
b45f9b543a
@ -0,0 +1,216 @@
|
|||||||
|
package com.rehome.zhdcoa.ui.activity;
|
||||||
|
|
||||||
|
import static com.rehome.zhdcoa.utils.GsonUtils.GsonToBean;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
|
||||||
|
import androidx.activity.EdgeToEdge;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.graphics.Insets;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
import com.rehome.zhdcoa.Contans;
|
||||||
|
import com.rehome.zhdcoa.R;
|
||||||
|
import com.rehome.zhdcoa.base.BaseActivityOaToolbarViewBinding;
|
||||||
|
import com.rehome.zhdcoa.bean.DagerEnterDeparmentTreeBean;
|
||||||
|
import com.rehome.zhdcoa.bean.DeviceOnlineStatusAreaBean;
|
||||||
|
import com.rehome.zhdcoa.bean.DeviceOnlineStatusBean;
|
||||||
|
import com.rehome.zhdcoa.databinding.ActivityDeviceAreaTreeBinding;
|
||||||
|
import com.rehome.zhdcoa.tree.departmentTree.TreeAdapter;
|
||||||
|
import com.rehome.zhdcoa.tree.departmentTree.TreePoint;
|
||||||
|
import com.rehome.zhdcoa.tree.departmentTree.TreeUtils;
|
||||||
|
import com.rehome.zhdcoa.utils.AuthenticationLoginAIUtils;
|
||||||
|
import com.rehome.zhdcoa.utils.GsonUtils;
|
||||||
|
import com.rehome.zhdcoa.utils.HttpListener;
|
||||||
|
import com.rehome.zhdcoa.utils.NohttpUtils;
|
||||||
|
import com.rehome.zhdcoa.utils.OnAuthenticationLoginListener;
|
||||||
|
import com.rehome.zhdcoa.utils.RSAAndroid;
|
||||||
|
import com.rehome.zhdcoa.weiget.OAToolbar;
|
||||||
|
import com.yolanda.nohttp.NoHttp;
|
||||||
|
import com.yolanda.nohttp.RequestMethod;
|
||||||
|
import com.yolanda.nohttp.rest.Request;
|
||||||
|
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceAreaTreeActivity extends BaseActivityOaToolbarViewBinding<ActivityDeviceAreaTreeBinding> {
|
||||||
|
|
||||||
|
private List<DeviceOnlineStatusAreaBean.DeviceArea> areaList=new ArrayList<>();
|
||||||
|
private TreeAdapter adapter;
|
||||||
|
private List<TreePoint> pointList = new ArrayList<>();
|
||||||
|
private HashMap<String, TreePoint> pointMap = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected ActivityDeviceAreaTreeBinding getViewBinding() {
|
||||||
|
return ActivityDeviceAreaTreeBinding.inflate(LayoutInflater.from(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected OAToolbar getToolbar() {
|
||||||
|
return binding.toolbarView.toolbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initView() {
|
||||||
|
initToolbar("选择区域", "", new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
adapter = new TreeAdapter(this, pointList, pointMap);
|
||||||
|
binding.listView.setAdapter(adapter);
|
||||||
|
binding.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
adapter.onItemClick(position,new TreeAdapter.OnTreeNodeClickIsLeaf(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isLeaf(TreePoint treePoint) {
|
||||||
|
//处理回填
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra("nodeKey",treePoint.getID());
|
||||||
|
intent.putExtra("cname",treePoint.getNNAME());
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//TreePoint treePoint = pointList.get(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initData() {
|
||||||
|
authenticationLoginDeviceAlarmInfoRsa();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authenticationLoginDeviceAlarmInfoRsa() {
|
||||||
|
try {
|
||||||
|
//AI三维登录接口
|
||||||
|
String userName = Contans.SP.DeviceAlermInfoAccount;
|
||||||
|
String strPublicDecode = RSAAndroid.decryptByPublicKeyForSpiltStr(
|
||||||
|
Contans.SP.DeviceAlermInfoPwd,
|
||||||
|
RSAAndroid.publicRsaKeyLocal
|
||||||
|
);
|
||||||
|
AuthenticationLoginAIUtils.authenticationDeviceAlermInfoRsaShowProgress(this,userName,strPublicDecode,new OnAuthenticationLoginListener(){
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationSuccess(boolean result, String token) {
|
||||||
|
if(token!=null&&token.isEmpty()){
|
||||||
|
//登录失败
|
||||||
|
showToast("设备状态智能监测及分析平台登录失败");
|
||||||
|
}else{
|
||||||
|
//登录成功
|
||||||
|
getDeviceAreaList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDeviceAreaList() {
|
||||||
|
|
||||||
|
String url = Contans.IP + Contans.DeviceOnlineStatusAreaBeanUrl;
|
||||||
|
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.GET);
|
||||||
|
|
||||||
|
NohttpUtils.getInstance().add(this,0, request, new HttpListener<String>() {
|
||||||
|
|
||||||
|
@SuppressLint({"SetTextI18n", "DefaultLocale"})
|
||||||
|
@Override
|
||||||
|
public void onSucceed(int what, com.yolanda.nohttp.rest.Response<String> response) {
|
||||||
|
|
||||||
|
String result = response.get();
|
||||||
|
showLog(result);
|
||||||
|
|
||||||
|
DeviceOnlineStatusAreaBean bean = GsonUtils.GsonToBean(
|
||||||
|
result,
|
||||||
|
DeviceOnlineStatusAreaBean.class
|
||||||
|
);
|
||||||
|
if(bean!=null && bean.getCode()==20000 && bean.isSuccess() && bean.getData()!=null&& !bean.getData().isEmpty()){
|
||||||
|
areaList.clear();
|
||||||
|
areaList.addAll(bean.getData());
|
||||||
|
pointList.clear();
|
||||||
|
for (int i = 0; i < areaList.size(); i++) {
|
||||||
|
DeviceOnlineStatusAreaBean.DeviceArea itemParent = areaList.get(i);
|
||||||
|
pointList.add(new TreePoint(itemParent.getAreaKey(), itemParent.getCname(), "0", "0", i + 1));
|
||||||
|
if (itemParent.getNodeList() != null && !itemParent.getNodeList().isEmpty()) {
|
||||||
|
for (int j = 0; j < itemParent.getNodeList().size(); j++) {
|
||||||
|
DeviceOnlineStatusAreaBean.NodeList itemSecondNode = itemParent.getNodeList().get(j);
|
||||||
|
pointList.add(new TreePoint(itemSecondNode.getNodeKey(), itemSecondNode.getCname(), itemSecondNode.getAreaKey(), "1", j + 1));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
pointList.add(new TreePoint(itemParent.getAreaKey(), itemParent.getCname(), "0", "1", i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//打乱集合中的数据
|
||||||
|
Collections.shuffle(pointList);
|
||||||
|
//对集合中的数据重新排序
|
||||||
|
updateData();
|
||||||
|
}else{
|
||||||
|
showLog("数据加载失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailed(int what, com.yolanda.nohttp.rest.Response<String> response) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//对数据排序 深度优先
|
||||||
|
private void updateData() {
|
||||||
|
for (TreePoint treePoint : pointList) {
|
||||||
|
pointMap.put(treePoint.getID(), treePoint);
|
||||||
|
}
|
||||||
|
Collections.sort(pointList, new Comparator<TreePoint>() {
|
||||||
|
@Override
|
||||||
|
public int compare(TreePoint lhs, TreePoint rhs) {
|
||||||
|
int llevel = TreeUtils.getLevel(lhs, pointMap);
|
||||||
|
int rlevel = TreeUtils.getLevel(rhs, pointMap);
|
||||||
|
if (llevel == rlevel) {
|
||||||
|
if (lhs.getPARENTID().equals(rhs.getPARENTID())) { //左边小
|
||||||
|
return lhs.getDISPLAY_ORDER() > rhs.getDISPLAY_ORDER() ? 1 : -1;
|
||||||
|
} else { //如果父辈id不相等
|
||||||
|
//同一级别,不同父辈
|
||||||
|
TreePoint ltreePoint = TreeUtils.getTreePoint(lhs.getPARENTID(), pointMap);
|
||||||
|
TreePoint rtreePoint = TreeUtils.getTreePoint(rhs.getPARENTID(), pointMap);
|
||||||
|
return compare(ltreePoint, rtreePoint); //父辈
|
||||||
|
}
|
||||||
|
} else { //不同级别
|
||||||
|
if (llevel > rlevel) { //左边级别大 左边小
|
||||||
|
if (lhs.getPARENTID().equals(rhs.getID())) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
TreePoint lreasonTreePoint = TreeUtils.getTreePoint(lhs.getPARENTID(), pointMap);
|
||||||
|
return compare(lreasonTreePoint, rhs);
|
||||||
|
}
|
||||||
|
} else { //右边级别大 右边小
|
||||||
|
if (rhs.getPARENTID().equals(lhs.getID())) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
TreePoint rreasonTreePoint = TreeUtils.getTreePoint(rhs.getPARENTID(), pointMap);
|
||||||
|
return compare(lhs, rreasonTreePoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".ui.activity.DeviceAreaTreeActivity">
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/toolbarView"
|
||||||
|
layout="@layout/layout_base" />
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/listView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:cacheColorHint="@null"
|
||||||
|
android:divider="#dadada"
|
||||||
|
android:dividerHeight="1dp"
|
||||||
|
android:fadingEdge="none"
|
||||||
|
android:listSelector="@android:color/transparent"
|
||||||
|
android:scrollbarSize="2dp"/>
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue