From 25cbdb9a2c317b0a0fbde5e8d3680fbc4e6f759d Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 26 Nov 2024 23:00:07 +0300 Subject: [PATCH] ssh: smoother configuration (fixes #2047) (#2155) Co-authored-by: dogi --- .../treehouses/remote/bases/BaseSSHConfig.kt | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSHConfig.kt b/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSHConfig.kt index 8537f3fcf..67628ad93 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSHConfig.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/BaseSSHConfig.kt @@ -44,28 +44,36 @@ open class BaseSSHConfig: BaseFragment(), RVButtonClickListener, OnHostStatusCha } protected fun setUpAdapter() { - pastHosts = SaveUtils.getAllHosts(requireContext()).reversed() - if (!isVisible) return - if (pastHosts.isEmpty()) { - bind.noHosts.visibility = View.VISIBLE - bind.pastHosts.visibility = View.GONE - } - adapter = object : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderSSHRow { - val holderBinding = RowSshBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return ViewHolderSSHRow(holderBinding, this@BaseSSHConfig) + if (context != null) { + pastHosts = SaveUtils.getAllHosts(requireContext()).reversed() + if (!isVisible) return + if (pastHosts.isEmpty()) { + bind.noHosts.visibility = View.VISIBLE + bind.pastHosts.visibility = View.GONE } + adapter = object : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderSSHRow { + val holderBinding = RowSshBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return ViewHolderSSHRow(holderBinding, this@BaseSSHConfig) + } - override fun getItemCount(): Int { return pastHosts.size } + override fun getItemCount(): Int { + return pastHosts.size + } - override fun onBindViewHolder(holder: ViewHolderSSHRow, position: Int) { - val host = pastHosts[position] - holder.bind(host) - if (bound?.mHostBridgeMap?.get(host)?.get() != null) holder.setConnected(true) else holder.setConnected(false) + override fun onBindViewHolder(holder: ViewHolderSSHRow, position: Int) { + val host = pastHosts[position] + holder.bind(host) + if (bound?.mHostBridgeMap?.get(host)?.get() != null) { + holder.setConnected(true) + } else { + holder.setConnected(false) + } + } } + bind.pastHosts.adapter = adapter + addItemTouchListener() } - bind.pastHosts.adapter = adapter - addItemTouchListener() } private fun addItemTouchListener() {