From 925f933e081d79737bf52c6ba536d5a9d443ef6a Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 4 Jun 2024 22:54:58 +0300 Subject: [PATCH] all: smoother adapters (fixes #2012) (#2015) Co-authored-by: dogi --- .../treehouses/remote/BaseInitialActivity.kt | 4 +-- .../remote/adapter/CommandListAdapter.kt | 20 ++++++------- .../treehouses/remote/adapter/HelpAdapter.kt | 1 - .../remote/adapter/ProfilesListAdapter.kt | 17 +++++------ .../remote/adapter/RPIListAdapter.kt | 7 ----- .../remote/adapter/ServicesListAdapter.kt | 6 ++-- .../remote/adapter/SystemListAdapter.kt | 30 +++++++------------ .../remote/adapter/TerminalPagerAdapter.kt | 10 ++----- .../remote/adapter/TunnelPortAdapter.kt | 3 -- .../remote/adapter/ViewHolderBlocker.kt | 16 ++++------ .../remote/adapter/ViewHolderCamera.kt | 18 +++++------ .../remote/adapter/ViewHolderSSH2FA.kt | 18 +++++------ .../remote/adapter/ViewHolderSSHAllKeyRow.kt | 7 +---- .../remote/adapter/ViewHolderSSHKey.kt | 8 ++--- .../adapter/ViewHolderShutdownReboot.kt | 17 ++++------- .../remote/adapter/ViewHolderTether.kt | 18 ++++++----- .../remote/adapter/ViewHolderVnc.kt | 11 +++---- .../remote/callback/HomeInteractListener.kt | 2 +- app/src/main/res/layout/configure_camera.xml | 2 +- app/src/main/res/layout/configure_ssh2fa.xml | 2 +- app/src/main/res/layout/open_vnc.xml | 2 +- 21 files changed, 85 insertions(+), 134 deletions(-) diff --git a/app/src/main/kotlin/io/treehouses/remote/BaseInitialActivity.kt b/app/src/main/kotlin/io/treehouses/remote/BaseInitialActivity.kt index e18fa741b..7909c5512 100644 --- a/app/src/main/kotlin/io/treehouses/remote/BaseInitialActivity.kt +++ b/app/src/main/kotlin/io/treehouses/remote/BaseInitialActivity.kt @@ -53,7 +53,7 @@ open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigatio */ - override fun sendMessage(s: String) { + override fun sendMessage(s: String?) { // Check that we're actually connected before trying anything if (mChatService.state != Constants.STATE_CONNECTED) { Toast.makeText(this@BaseInitialActivity, R.string.not_connected, Toast.LENGTH_SHORT).show() @@ -61,7 +61,7 @@ open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigatio } // Check that there's actually something to send - if (s.isNotEmpty()) { + if (s?.isNotEmpty() == true) { // Get the message bytes and tell the BluetoothChatService to write val send = s.toByteArray() mChatService.write(send) diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/CommandListAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/CommandListAdapter.kt index 3872860cf..20d29dc97 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/CommandListAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/CommandListAdapter.kt @@ -10,12 +10,13 @@ import io.treehouses.remote.R import io.treehouses.remote.pojo.CommandListItem import java.util.* -class CommandListAdapter(private val context: Context, private val expandableListTitle: List, - private val expandableListDetail: HashMap>) : BaseExpandableListAdapter() { +class CommandListAdapter(private val context: Context, private val expandableListTitle: List, private val expandableListDetail: HashMap>) : BaseExpandableListAdapter() { override fun getChild(listPosition: Int, expandedListPosition: Int): Any { return if (expandedListPosition < expandableListDetail[expandableListTitle[listPosition]]!!.size) { expandableListDetail[expandableListTitle[listPosition]]!![expandedListPosition].getTitle() - } else "Add" + } else { + "Add" + } } override fun getChildId(listPosition: Int, expandedListPosition: Int): Long { @@ -38,7 +39,9 @@ class CommandListAdapter(private val context: Context, private val expandableLis override fun getChildrenCount(listPosition: Int): Int { return if (listPosition == 0) { expandableListDetail[expandableListTitle[listPosition]]!!.size + 1 - } else expandableListDetail[expandableListTitle[listPosition]]!!.size + } else { + expandableListDetail[expandableListTitle[listPosition]]!!.size + } } override fun getGroup(listPosition: Int): Any { @@ -53,20 +56,18 @@ class CommandListAdapter(private val context: Context, private val expandableLis return listPosition.toLong() } - override fun getGroupView(listPosition: Int, isExpanded: Boolean, - convertView: View?, parent: ViewGroup): View { + override fun getGroupView(listPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View { var newView = convertView val listTitle = getGroup(listPosition) as String if (newView == null) { newView = getConvertView(R.layout.list_group) } - val listTitleTextView = newView - .findViewById(R.id.lblListHeader) as TextView + val listTitleTextView = newView.findViewById(R.id.lblListHeader) as TextView listTitleTextView.text = listTitle return newView } - fun getConvertView(layout_id: Int): View { + private fun getConvertView(layout_id: Int): View { val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater return layoutInflater.inflate(layout_id, null) } @@ -78,5 +79,4 @@ class CommandListAdapter(private val context: Context, private val expandableLis override fun isChildSelectable(listPosition: Int, expandedListPosition: Int): Boolean { return true } - } \ No newline at end of file diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/HelpAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/HelpAdapter.kt index f1764b582..929b4d62c 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/HelpAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/HelpAdapter.kt @@ -9,7 +9,6 @@ import io.treehouses.remote.databinding.RowHelpBinding import io.treehouses.remote.pojo.HelpCommand class HelpAdapter : RecyclerView.Adapter() { - private val sortedList: SortedList = SortedList(HelpCommand::class.java, object : SortedList.Callback() { override fun areItemsTheSame(item1: HelpCommand?, item2: HelpCommand?): Boolean { return item1?.title == item2?.title && item1?.preview == item2?.preview diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ProfilesListAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ProfilesListAdapter.kt index 1586bba34..531f57068 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ProfilesListAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ProfilesListAdapter.kt @@ -62,7 +62,6 @@ class ProfilesListAdapter(private val context: Context, private val titles: List private fun setLabelText(label: TextView, s: String, delete: Button) { label.text = s label.setTextColor(ContextCompat.getColor(context, R.color.expandable_child_text)) - delete.visibility = View.GONE } @@ -87,14 +86,13 @@ class ProfilesListAdapter(private val context: Context, private val titles: List private fun showConfirmation(name: String, groupPosition: Int, childPosition: Int) { val alertDialog = AlertDialog.Builder(ContextThemeWrapper(context, R.style.CustomAlertDialogStyle)) - .setTitle("Delete Profile?") - .setMessage("Are you sure you want to delete the following Network Profile: $name") - .setPositiveButton("Delete") { _, _ -> - deleteProfile(context, groupPosition, childPosition) - data[titles[groupPosition]]!!.removeAt(childPosition) - notifyDataSetChanged() - } - .setNegativeButton("Cancel") { dialog, _ -> dialog.dismiss() }.create() + .setTitle("Delete Profile?") + .setMessage("Are you sure you want to delete the following Network Profile: $name") + .setPositiveButton("Delete") { _, _ -> + deleteProfile(context, groupPosition, childPosition) + data[titles[groupPosition]]!!.removeAt(childPosition) + notifyDataSetChanged() + }.setNegativeButton("Cancel") { dialog, _ -> dialog.dismiss() }.create() alertDialog.window!!.setBackgroundDrawableResource(android.R.color.transparent) alertDialog.show() } @@ -102,5 +100,4 @@ class ProfilesListAdapter(private val context: Context, private val titles: List override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean { return true } - } \ No newline at end of file diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/RPIListAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/RPIListAdapter.kt index 4902f42f0..45e82c8f5 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/RPIListAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/RPIListAdapter.kt @@ -15,11 +15,8 @@ import io.treehouses.remote.pojo.DeviceInfo class RPIListAdapter(private val mContext: Context, private val data: List) : ArrayAdapter(mContext, 0, data) { var deviceListener: DeviceDeleteListener? = null override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - // Get the data item for this position var newView = convertView val deviceText = data[position].deviceName - - // Check if an existing view is being reused, otherwise inflate the view if (newView == null) { newView = LayoutInflater.from(mContext).inflate(R.layout.list_rpi_item, parent, false) } @@ -36,14 +33,10 @@ class RPIListAdapter(private val mContext: Context, private val data: List, private val headerColour: Int) : ArrayAdapter(mContext, 0, dataIn) { +class ServicesListAdapter(mContext: Context, private val dataIn: MutableList, private val headerColour: Int) : ArrayAdapter(mContext, 0, dataIn) { var data: MutableList = dataIn private var name: TextView? = null private var status: ImageView? = null @@ -81,8 +80,7 @@ class ServicesListAdapter //private Button start, install, restart, link, info; } private fun initView(position: Int, parent: ViewGroup): View { - val convertView: View? - convertView = if (flag(position)) { + val convertView: View = if (flag(position)) { LayoutInflater.from(context).inflate(R.layout.services_row_layout, parent, false) } else { LayoutInflater.from(context).inflate(R.layout.services_section_header, parent, false) diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/SystemListAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/SystemListAdapter.kt index a67ff1c5c..e75c35ccb 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/SystemListAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/SystemListAdapter.kt @@ -12,12 +12,11 @@ import io.treehouses.remote.R import io.treehouses.remote.callback.HomeInteractListener import io.treehouses.remote.pojo.NetworkListItem -class SystemListAdapter(val context: Context, list: List) : BaseExpandableListAdapter() { - private val list: List +class SystemListAdapter(val context: Context, private val list: List) : BaseExpandableListAdapter() { private val inflater: LayoutInflater = LayoutInflater.from(context) private var listener: HomeInteractListener? = null - private val views: MutableList - private val groupHeader: MutableList + private val views: MutableList = mutableListOf() + private val groupHeader: MutableList = mutableListOf() fun setListener(listener: HomeInteractListener?) { this.listener = listener if (listener == null) { @@ -67,9 +66,6 @@ class SystemListAdapter(val context: Context, list: List) : Bas @RequiresApi(api = Build.VERSION_CODES.O) override fun getChildView(i: Int, i1: Int, b: Boolean, convertView: View?, parent: ViewGroup): View { - - // Needs to recycle views instead of creating new ones each time. - // if (convertView == null) creating bugs if (views.size > i) { return views[i] } @@ -77,13 +73,13 @@ class SystemListAdapter(val context: Context, list: List) : Bas layout = list[i].layout position = i when (layout) { - R.layout.configure_shutdown_reboot -> ViewHolderShutdownReboot(newView, context, listener!!) - R.layout.open_vnc -> ViewHolderVnc(newView, context, listener!!) - R.layout.configure_tethering -> ViewHolderTether(newView, listener!!, context) - R.layout.configure_ssh_key -> ViewHolderSSHKey(newView, context, listener!!) - R.layout.configure_camera -> ViewHolderCamera(newView, context, listener!!) - R.layout.configure_blocker -> ViewHolderBlocker(newView, context, listener!!) - R.layout.configure_ssh2fa -> ViewHolderSSH2FA(newView, context, listener!!) + R.layout.configure_shutdown_reboot -> ViewHolderShutdownReboot(newView, context, listener) + R.layout.open_vnc -> ViewHolderVnc(newView, context, listener) + R.layout.configure_tethering -> ViewHolderTether(newView, listener, context) + R.layout.configure_ssh_key -> ViewHolderSSHKey(newView, context, listener) + R.layout.configure_camera -> ViewHolderCamera(newView, context, listener) + R.layout.configure_blocker -> ViewHolderBlocker(newView, context, listener) + R.layout.configure_ssh2fa -> ViewHolderSSH2FA(newView, context, listener) } views.add(newView) return newView @@ -98,10 +94,4 @@ class SystemListAdapter(val context: Context, list: List) : Bas private set var position = 0 } - - init { - this.list = list - views = mutableListOf() - groupHeader = mutableListOf() - } } diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/TerminalPagerAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/TerminalPagerAdapter.kt index c097d3d3a..f2cfcdbc2 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/TerminalPagerAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/TerminalPagerAdapter.kt @@ -23,21 +23,15 @@ class TerminalPagerAdapter : PagerAdapter() { override fun instantiateItem(container: ViewGroup, position: Int): Any { if (terminalPager.getManager() == null || terminalPager.getManager()!!.bridges.size <= position) Log.w(BaseSSHConsole.TAG, "Activity not bound when creating TerminalView.") val bridge = terminalPager.getManager()!!.bridges[position] - bridge.promptHelper!!.setHandler(terminalPager.getHandler()) + bridge.promptHelper?.setHandler(terminalPager.getHandler()) - // inflate each terminal view val view = terminalPager.getInflater().inflate(R.layout.item_terminal, container, false) as RelativeLayout - - // set the terminal name overlay text val terminalNameOverlay = view.findViewById(R.id.terminal_name_overlay) - terminalNameOverlay.text = bridge.host!!.nickname - - // and add our terminal view control, using index to place behind overlay + terminalNameOverlay.text = bridge.host?.nickname val terminal = TerminalView(container.context, bridge, terminalPager.getPager()) terminal.id = R.id.terminal_view view.addView(terminal, 0) - // Tag the view with its bridge so it can be retrieved later. view.tag = bridge container.addView(view) terminalNameOverlay.startAnimation(terminalPager.getAnimation()) diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/TunnelPortAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/TunnelPortAdapter.kt index c973086dd..b184c36e2 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/TunnelPortAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/TunnelPortAdapter.kt @@ -8,17 +8,14 @@ import android.widget.ArrayAdapter import android.widget.TextView import io.treehouses.remote.R - class TunnelPortAdapter(private val mContext: Context, private val data: List) : ArrayAdapter(mContext, 0, data) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val convertedView: View val deleteAllPortsButtonSelected = data.size > 1 && position == data.size-1 convertedView = if (deleteAllPortsButtonSelected) LayoutInflater.from(mContext).inflate(R.layout.select_dialog_item_delete_all, parent, false) else LayoutInflater.from(mContext).inflate(R.layout.select_dialog_item, parent, false) val text = convertedView as TextView text.text = getItem(position) - // Return the completed view to render on screen return convertedView } } \ No newline at end of file diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderBlocker.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderBlocker.kt index e4b3bed96..ed668aa95 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderBlocker.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderBlocker.kt @@ -14,7 +14,7 @@ import io.treehouses.remote.R import io.treehouses.remote.callback.HomeInteractListener import io.treehouses.remote.network.BluetoothChatService -class ViewHolderBlocker internal constructor(v: View, context: Context?, listener: HomeInteractListener) { +class ViewHolderBlocker internal constructor(v: View, context: Context?, listener: HomeInteractListener?) { private val blockerBar: SeekBar = v.findViewById(R.id.blockerBar) private val levelText: TextView = v.findViewById(R.id.levelText) private val blockerDesc: TextView = v.findViewById(R.id.blockerDesc) @@ -23,11 +23,8 @@ class ViewHolderBlocker internal constructor(v: View, context: Context?, listene private var blockerLevel:Int = 0 private var previousLevel:Int = 0 private var readMessage = "" - private val mChatService: BluetoothChatService = listener.getChatService() + private val mChatService: BluetoothChatService? = listener?.getChatService() - /** - * The Handler that gets information back from the BluetoothChatService - */ val mHandler: Handler = object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { when (msg.what) { @@ -56,10 +53,9 @@ class ViewHolderBlocker internal constructor(v: View, context: Context?, listene } } - init { - mChatService.updateHandler(mHandler) - listener.sendMessage(context!!.resources.getString(R.string.TREEHOUSES_BLOCKER_CHECK)) + mChatService?.updateHandler(mHandler) + listener?.sendMessage(context!!.resources.getString(R.string.TREEHOUSES_BLOCKER_CHECK)) blockerBar.max = 5 setBlocker.visibility = View.GONE moveText.visibility = View.VISIBLE @@ -88,7 +84,7 @@ class ViewHolderBlocker internal constructor(v: View, context: Context?, listene fun setBlocker(level:Int) { fun sendCommand(level:String) { - listener.sendMessage(context.resources.getString(R.string.TREEHOUSES_BLOCKER, level)) + listener?.sendMessage(context?.resources?.getString(R.string.TREEHOUSES_BLOCKER, level)) } when (level) { @@ -140,6 +136,4 @@ class ViewHolderBlocker internal constructor(v: View, context: Context?, listene fun Context?.toast(s: String): Toast { return Toast.makeText(this, s, Toast.LENGTH_SHORT).apply { show() } } - - } \ No newline at end of file diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderCamera.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderCamera.kt index 50826d4ef..02e9c32fd 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderCamera.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderCamera.kt @@ -6,16 +6,16 @@ import android.os.Looper import android.os.Message import android.view.View import android.widget.ImageView -import android.widget.Switch import android.widget.Toast +import androidx.appcompat.widget.SwitchCompat import io.treehouses.remote.Constants -import io.treehouses.remote.network.BluetoothChatService import io.treehouses.remote.R import io.treehouses.remote.callback.HomeInteractListener +import io.treehouses.remote.network.BluetoothChatService -class ViewHolderCamera internal constructor(v: View, private val c: Context, listener: HomeInteractListener) { - private val mChatService: BluetoothChatService = listener.getChatService() - private val cameraSwitch: Switch +class ViewHolderCamera internal constructor(v: View, private val c: Context, listener: HomeInteractListener?) { + private val mChatService: BluetoothChatService? = listener?.getChatService() + private val cameraSwitch: SwitchCompat private val icon: ImageView private val mHandler: Handler = object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { @@ -40,14 +40,14 @@ class ViewHolderCamera internal constructor(v: View, private val c: Context, lis } init { - mChatService.updateHandler(mHandler) + mChatService?.updateHandler(mHandler) cameraSwitch = v.findViewById(R.id.CameraSwitch) icon = v.findViewById(R.id.cameraIcon) - listener.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA)) + listener?.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA)) cameraSwitch.isEnabled = false cameraSwitch.setOnClickListener { - if (cameraSwitch.isChecked) listener.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA_ON)) - else listener.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA_OFF)) + if (cameraSwitch.isChecked) listener?.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA_ON)) + else listener?.sendMessage(c.resources.getString(R.string.TREEHOUSES_CAMERA_OFF)) cameraSwitch.isEnabled = false } } diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSH2FA.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSH2FA.kt index e630ef3ae..38632374f 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSH2FA.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSH2FA.kt @@ -11,6 +11,7 @@ import android.widget.Button import android.widget.EditText import android.widget.Switch import android.widget.TextView +import androidx.appcompat.widget.SwitchCompat import io.treehouses.remote.Constants import io.treehouses.remote.R import io.treehouses.remote.callback.HomeInteractListener @@ -19,15 +20,12 @@ import io.treehouses.remote.utils.Utils import io.treehouses.remote.utils.Utils.toast -class ViewHolderSSH2FA internal constructor(v: View, private val c: Context, listener: HomeInteractListener) { +class ViewHolderSSH2FA internal constructor(v: View, private val c: Context, listener: HomeInteractListener?) { val v = v - private val mChatService: BluetoothChatService = listener.getChatService() + private val mChatService: BluetoothChatService? = listener?.getChatService() private var readMessage = "" private var counter = 0 - /** - * The Handler that gets information back from the BluetoothChatService - */ val mHandler: Handler = object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { when (msg.what) { @@ -53,20 +51,20 @@ class ViewHolderSSH2FA internal constructor(v: View, private val c: Context, lis private val removeUser: Button = v.findViewById(R.id.removeBtn) private val showUser: Button = v.findViewById(R.id.showBtn) private val user:EditText = v.findViewById(R.id.user) - private val twoFASwitch: Switch = v.findViewById(R.id.switch2FA) + private val twoFASwitch: SwitchCompat = v.findViewById(R.id.switch2FA) private val keysDisplay: TextView = v.findViewById(R.id.keysDisplay) init { - mChatService.updateHandler(mHandler) + mChatService?.updateHandler(mHandler) fun sendCommand1(id:Int){ - listener.sendMessage(c.resources.getString(id)) + listener?.sendMessage(c.resources.getString(id)) } sendCommand1(R.string.TREEHOUSES_SSH_2FA) fun sendCommand2(id:Int){ - listener.sendMessage(c.resources.getString(id, user.text)) + listener?.sendMessage(c.resources.getString(id, user.text)) } addUser.setOnClickListener { @@ -128,7 +126,7 @@ class ViewHolderSSH2FA internal constructor(v: View, private val c: Context, lis } private fun openAuthenticator(key:String){ - val uri:String = "otpauth://totp/" + "pi@treehouses" + "?secret=" + key + "&issuer=treehouses" + val uri = "otpauth://totp/pi@treehouses?secret=$key&issuer=treehouses" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri)) if (Utils.checkAppIsInstalled(c, v, intent, arrayOf("No Authenticator Client Installed on your Device", "Install", "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2"))) return diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt index 356e7c2ff..7e22e6e39 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt @@ -13,12 +13,7 @@ import io.treehouses.remote.callback.KeyMenuListener import io.treehouses.remote.databinding.RowKeyBinding -class ViewHolderSSHAllKeyRow(private val binding: RowKeyBinding, private val listener: KeyMenuListener) : - RecyclerView.ViewHolder(binding.root), - View.OnCreateContextMenuListener, - MenuItem.OnMenuItemClickListener, - PopupMenu.OnMenuItemClickListener { - +class ViewHolderSSHAllKeyRow(private val binding: RowKeyBinding, private val listener: KeyMenuListener) : RecyclerView.ViewHolder(binding.root), View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener { fun bind(host: PubKeyBean) { itemView.setOnCreateContextMenuListener(this) binding.keyName.text = host.nickname diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHKey.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHKey.kt index 324a9f6f0..5bd25094a 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHKey.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHKey.kt @@ -14,8 +14,8 @@ import io.treehouses.remote.R import io.treehouses.remote.callback.HomeInteractListener import io.treehouses.remote.utils.Utils.toast -class ViewHolderSSHKey internal constructor(v: View, private val c: Context, listener: HomeInteractListener) { - private val mChatService: BluetoothChatService = listener.getChatService() +class ViewHolderSSHKey internal constructor(v: View, private val c: Context, listener: HomeInteractListener?) { + private val mChatService: BluetoothChatService? = listener?.getChatService() private val mHandler: Handler = object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { if (msg.what == Constants.MESSAGE_READ) { @@ -32,12 +32,12 @@ class ViewHolderSSHKey internal constructor(v: View, private val c: Context, lis } init { - mChatService.updateHandler(mHandler) + mChatService?.updateHandler(mHandler) val btnStartConfig = v.findViewById