Advertisement
Guest User

Untitled

a guest
May 14th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. val adapter = object : CustomAdapter<HostItem, ItemHostBinding>(navigator as NetworkDiagnosticsActivity, R.layout.item_host) {
  2. override fun bindView(position: Int, item: HostItem, binding: ItemHostBinding, parent: ViewGroup) {
  3. val ssb = SpannableStringBuilder()
  4. ssb.appendln(item.hostName)
  5. ssb.appendln(applyStyles(item.hostAddressIpv4,
  6. ForegroundColorSpan(getColorRes(R.color.textColorAccent))))
  7. ssb.append(applyStyles(item.hostAddressIpv6,
  8. ForegroundColorSpan(getColorRes(R.color.textColorAccent))))
  9. binding.tvHostName.text = ssb
  10. val onClick = View.OnClickListener {
  11. when (it.id) {
  12. R.id.btnPing -> showResultDialog(Ping(), position)
  13. R.id.btnTraceRoute -> showResultDialog(Traceroute(), position)
  14. }
  15. }
  16. binding.btnPing.setOnClickListener(onClick)
  17. binding.btnTraceRoute.setOnClickListener(onClick)
  18. val successColor = getColorRes(R.color.holoGreenLight)
  19. val whiteColor = getColorRes(R.color.mainTextColorDark)
  20. val blackColor = getColorRes(R.color.mainBgrDark)
  21. val errorColor = getColorRes(R.color.tansRed)
  22. val transparentColor = getColorRes(android.R.color.transparent)
  23. if (item.isSuccessPing != null) {
  24. binding.btnPing.setBackgroundColor(if (item.isSuccessPing == true) successColor else errorColor)
  25. binding.btnPing.setTextColor(if (item.isSuccessPing == true) blackColor else whiteColor)
  26. } else {
  27. binding.btnPing.setBackgroundColor(transparentColor)
  28. binding.btnPing.setTextColor(whiteColor)
  29. }
  30. if (item.isSuccessTraceRoute != null) {
  31. binding.btnTraceRoute.setBackgroundColor(if (item.isSuccessTraceRoute == true && !item.isBlackListed) successColor else errorColor)
  32. binding.btnTraceRoute.setTextColor(if (item.isSuccessTraceRoute == true && !item.isBlackListed) blackColor else whiteColor)
  33. } else {
  34. binding.btnTraceRoute.setBackgroundColor(transparentColor)
  35. binding.btnTraceRoute.setTextColor(whiteColor)
  36. }
  37. binding.progressPing.visibility = if (item.isSuccessPing != null) View.GONE else View.VISIBLE
  38. binding.btnPing.isEnabled = item.isSuccessPing != null
  39. binding.progressTraceRoute.visibility = if (item.isSuccessTraceRoute != null) View.GONE else View.VISIBLE
  40. binding.btnTraceRoute.isEnabled = item.isSuccessTraceRoute != null
  41. }
  42. }
  43.  
  44. binding.lv.adapter = adapter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement