Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val adapter = object : CustomAdapter<HostItem, ItemHostBinding>(navigator as NetworkDiagnosticsActivity, R.layout.item_host) {
- override fun bindView(position: Int, item: HostItem, binding: ItemHostBinding, parent: ViewGroup) {
- val ssb = SpannableStringBuilder()
- ssb.appendln(item.hostName)
- ssb.appendln(applyStyles(item.hostAddressIpv4,
- ForegroundColorSpan(getColorRes(R.color.textColorAccent))))
- ssb.append(applyStyles(item.hostAddressIpv6,
- ForegroundColorSpan(getColorRes(R.color.textColorAccent))))
- binding.tvHostName.text = ssb
- val onClick = View.OnClickListener {
- when (it.id) {
- R.id.btnPing -> showResultDialog(Ping(), position)
- R.id.btnTraceRoute -> showResultDialog(Traceroute(), position)
- }
- }
- binding.btnPing.setOnClickListener(onClick)
- binding.btnTraceRoute.setOnClickListener(onClick)
- val successColor = getColorRes(R.color.holoGreenLight)
- val whiteColor = getColorRes(R.color.mainTextColorDark)
- val blackColor = getColorRes(R.color.mainBgrDark)
- val errorColor = getColorRes(R.color.tansRed)
- val transparentColor = getColorRes(android.R.color.transparent)
- if (item.isSuccessPing != null) {
- binding.btnPing.setBackgroundColor(if (item.isSuccessPing == true) successColor else errorColor)
- binding.btnPing.setTextColor(if (item.isSuccessPing == true) blackColor else whiteColor)
- } else {
- binding.btnPing.setBackgroundColor(transparentColor)
- binding.btnPing.setTextColor(whiteColor)
- }
- if (item.isSuccessTraceRoute != null) {
- binding.btnTraceRoute.setBackgroundColor(if (item.isSuccessTraceRoute == true && !item.isBlackListed) successColor else errorColor)
- binding.btnTraceRoute.setTextColor(if (item.isSuccessTraceRoute == true && !item.isBlackListed) blackColor else whiteColor)
- } else {
- binding.btnTraceRoute.setBackgroundColor(transparentColor)
- binding.btnTraceRoute.setTextColor(whiteColor)
- }
- binding.progressPing.visibility = if (item.isSuccessPing != null) View.GONE else View.VISIBLE
- binding.btnPing.isEnabled = item.isSuccessPing != null
- binding.progressTraceRoute.visibility = if (item.isSuccessTraceRoute != null) View.GONE else View.VISIBLE
- binding.btnTraceRoute.isEnabled = item.isSuccessTraceRoute != null
- }
- }
- binding.lv.adapter = adapter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement