@@ -19,18 +19,35 @@ class ConnectionAdapter(
1919
2020 fun bind (item : ConnectionInfo ) {
2121 binding.tvProtocol.text = item.protocol
22- binding.tvState.text = item.displayState
2322 binding.tvLocalAddr.text = item.localIp + " :" + item.localPort
2423 binding.tvRemoteAddr.text = item.remoteIp + " :" + item.remotePort
2524 binding.tvAppName.text = item.appName
2625
27- val stateColor = when (item.displayState) {
28- " ESTABLISHED" -> 0xFF4CAF50 .toInt()
29- " LISTEN" -> 0xFF2196F3 .toInt()
30- " CLOSE_WAIT" -> 0xFFFF9800 .toInt()
31- " TIME_WAIT" -> 0xFF9E9E9E .toInt()
32- else -> 0xFF757575 .toInt()
26+ val stateText: String
27+ val stateColor: Int
28+
29+ when {
30+ item.isRealIpExposed -> {
31+ stateText = " \u26a0 IP\u66b4\u9732 "
32+ stateColor = 0xFFF44336 .toInt() // 红色
33+ }
34+ item.isExposedListener -> {
35+ stateText = " \u26a0 \u7aef\u53e3\u66b4\u9732 "
36+ stateColor = 0xFFFF5722 .toInt() // 深橙色
37+ }
38+ else -> {
39+ stateText = item.displayState
40+ stateColor = when (item.displayState) {
41+ " ESTABLISHED" -> 0xFF4CAF50 .toInt()
42+ " LISTEN" -> 0xFF2196F3 .toInt()
43+ " CLOSE_WAIT" -> 0xFFFF9800 .toInt()
44+ " TIME_WAIT" -> 0xFF9E9E9E .toInt()
45+ else -> 0xFF757575 .toInt()
46+ }
47+ }
3348 }
49+
50+ binding.tvState.text = stateText
3451 binding.tvState.setTextColor(stateColor)
3552
3653 binding.root.setOnClickListener { onItemClick(item) }
@@ -55,10 +72,10 @@ class ConnectionAdapter(
5572 class DiffCallback : DiffUtil .ItemCallback <ConnectionInfo >() {
5673 override fun areItemsTheSame (old : ConnectionInfo , new : ConnectionInfo ): Boolean {
5774 return old.localIp == new.localIp &&
58- old.localPort == new.localPort &&
59- old.remoteIp == new.remoteIp &&
60- old.remotePort == new.remotePort &&
61- old.protocol == new.protocol
75+ old.localPort == new.localPort &&
76+ old.remoteIp == new.remoteIp &&
77+ old.remotePort == new.remotePort &&
78+ old.protocol == new.protocol
6279 }
6380
6481 override fun areContentsTheSame (old : ConnectionInfo , new : ConnectionInfo ): Boolean {
0 commit comments