diff --git a/app/src/main/kotlin/io/treehouses/remote/adapter/ServicesListAdapter.kt b/app/src/main/kotlin/io/treehouses/remote/adapter/ServicesListAdapter.kt index c0783ab64..656a57eb4 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ServicesListAdapter.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ServicesListAdapter.kt @@ -25,7 +25,7 @@ class ServicesListAdapter //private Button start, install, restart, link, info; override fun getPosition(item: ServiceInfo?): Int { for (i in data.indices) { - if (data[i].name == item!!.name && data[i].serviceStatus == item!!.serviceStatus) { + if (data[i].name == item!!.name && data[i].serviceStatus == item.serviceStatus) { return i } } diff --git a/app/src/main/kotlin/io/treehouses/remote/fragments/dialogfragments/EditHostDialogFragment.kt b/app/src/main/kotlin/io/treehouses/remote/fragments/dialogfragments/EditHostDialogFragment.kt index d4d4fb786..be9ba38e1 100644 --- a/app/src/main/kotlin/io/treehouses/remote/fragments/dialogfragments/EditHostDialogFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/fragments/dialogfragments/EditHostDialogFragment.kt @@ -111,7 +111,7 @@ class EditHostDialogFragment : FullScreenDialogFragment(), FragmentDialogInterfa override fun onDismiss(dialog: DialogInterface) { super.onDismiss(dialog) - dismissListener?.onDismiss(dialog) + dismissListener.onDismiss(dialog) } companion object { diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/services/ServicesFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/services/ServicesFragment.kt index 485ffd8e9..d79668012 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/services/ServicesFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/services/ServicesFragment.kt @@ -64,7 +64,7 @@ class ServicesFragment : BaseFragment() { viewModel.clickedService.observe(viewLifecycleOwner) { viewModel.selectedService.value = it - Objects.requireNonNull(bind.tabLayout.getTabAt(1))?.select() + bind.tabLayout.getTabAt(1)?.select() currentTab = 1 replaceFragment(currentTab) } diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/BaseSSHTunnelViewModel.kt b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/BaseSSHTunnelViewModel.kt index 4ee564c47..41a780067 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/BaseSSHTunnelViewModel.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/BaseSSHTunnelViewModel.kt @@ -50,7 +50,8 @@ open class BaseSSHTunnelViewModel(application: Application) : FragmentViewModel( val inPhoneOnly = piPublicKey == "No public key found" && piPrivateKey == "No private key found " && !storedPublicKey.isNullOrBlank() && !storedPrivateKey.isNullOrBlank() val inNeither = piPublicKey == "No public key found" && piPrivateKey == "No private key found " && storedPublicKey.isNullOrBlank() && storedPrivateKey.isNullOrBlank() tunnelSSHKeyDialogObj = TunnelSSHKeyDialogData() - tunnelSSHKeyDialogObj.profile = profile;tunnelSSHKeyDialogObj.storedPrivateKey = storedPrivateKey!!;tunnelSSHKeyDialogObj.storedPublicKey = storedPublicKey!!;tunnelSSHKeyDialogObj.piPrivateKey = piPrivateKey!!;tunnelSSHKeyDialogObj.piPublicKey = piPublicKey!! + tunnelSSHKeyDialogObj.profile = profile;tunnelSSHKeyDialogObj.storedPrivateKey = storedPrivateKey!!;tunnelSSHKeyDialogObj.storedPublicKey = storedPublicKey!!;tunnelSSHKeyDialogObj.piPrivateKey = + piPrivateKey;tunnelSSHKeyDialogObj.piPublicKey = piPublicKey // Pi and phone keys are the same if (inPiAndPhone) Toast.makeText(context, "The same keys for $profile are already saved in both Pi and phone", Toast.LENGTH_SHORT).show() // Key exists in Pi but not phone diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt index 501a418fb..e38833a2c 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelFragment.kt @@ -43,7 +43,7 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { when (it.status) { Status.SUCCESS -> { if (it.data!!.showHandleDifferentKeysDialog) handleDifferentKeys(it.data) - if (it.data!!.showHandlePhoneKeySaveDialog) + if (it.data.showHandlePhoneKeySaveDialog) handlePhoneKeySave(it.data) if (it.data!!.showHandlePiKeySaveDialog) handlePiKeySave( @@ -95,7 +95,7 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { private fun handleAddPort() { if (dialogSshTunnelPortsBinding.ExternalTextInput.text!!.isNotEmpty() && dialogSshTunnelPortsBinding.InternalTextInput.text!!.isNotEmpty()) { - val parts = dialogSshTunnelPortsBinding.hosts?.selectedItem.toString().split(":")[0] + val parts = dialogSshTunnelPortsBinding.hosts.selectedItem.toString().split(":")[0] viewModel.addingPortButton(dialogSshTunnelPortsBinding.InternalTextInput.text.toString(), dialogSshTunnelPortsBinding.ExternalTextInput.text.toString(), parts) dialogPort.dismiss() } @@ -217,7 +217,7 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { if (s!!.isEmpty()) { dialogSshTunnelHostsBinding.btnAddingHost.isEnabled = false } else { - if (!s!!.toString().matches(regex.toRegex())) { + if (!s.toString().matches(regex.toRegex())) { dialogSshTunnelHostsBinding.btnAddingHost.isEnabled = false textInputLayout.error = error } else { @@ -239,10 +239,10 @@ class SSHTunnelFragment : BaseSSHTunnelFragment() { if (s!!.isEmpty()) { dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false } else { - if (!s!!.toString().matches(Constants.portRegex.toRegex())) { + if (!s.toString().matches(Constants.portRegex.toRegex())) { dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false textInputLayout.error = Constants.portError - } else if (textInputEditText == dialogSshTunnelPortsBinding.ExternalTextInput && viewModel.searchArray(portsName, s!!.toString())) { + } else if (textInputEditText == dialogSshTunnelPortsBinding.ExternalTextInput && viewModel.searchArray(portsName, s.toString())) { dialogSshTunnelPortsBinding.btnAddingPort.isEnabled = false dialogSshTunnelPortsBinding.TLexternal.error = "Port number already exists" } else { diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelViewModel.kt b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelViewModel.kt index e24d0acf7..796ad27bc 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelViewModel.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/sshtunnel/SSHTunnelViewModel.kt @@ -29,7 +29,7 @@ open class SSHTunnelViewModel(application: Application) : BaseSSHTunnelViewModel tunnelSSHObject.enableAddPort = false } s == TUNNEL_SSH_RESULTS.RESULT_ADDED -> sendMessage(getString(R.string.TREEHOUSES_SSHTUNNEL_NOTICE)) - s == TUNNEL_SSH_RESULTS.RESULT_REMOVED && lastCommand == getString(R.string.TREEHOUSES_SSHTUNNEL_REMOVE_ALL) -> { tunnelSSHObject.portNames!!.clear();tunnelSSHObject.enabledNotifyNow = false; sendMessage(getString(R.string.TREEHOUSES_SSHTUNNEL_NOTICE)); } + s == TUNNEL_SSH_RESULTS.RESULT_REMOVED && lastCommand == getString(R.string.TREEHOUSES_SSHTUNNEL_REMOVE_ALL) -> { tunnelSSHObject.portNames.clear();tunnelSSHObject.enabledNotifyNow = false; sendMessage(getString(R.string.TREEHOUSES_SSHTUNNEL_NOTICE)); } s == TUNNEL_SSH_RESULTS.RESULT_REMOVED -> handleModifiedList() s == TUNNEL_SSH_RESULTS.RESULT_MODIFIED_LIST -> handleModifiedList() s == TUNNEL_SSH_RESULTS.RESULT_SSH_PORT && lastCommand == getString(R.string.TREEHOUSES_SSHTUNNEL_PORTS) -> handleNewList(output) @@ -135,16 +135,16 @@ open class SSHTunnelViewModel(application: Application) : BaseSSHTunnelViewModel for (host in hosts) { val ports = host.split(' ') for (port in ports) { - if (port.length >= 3) tunnelSSHObject.portNames!!.add(port) + if (port.length >= 3) tunnelSSHObject.portNames.add(port) if (port.contains("@")) { - tunnelSSHObject.hostPosition!!.add(position) - tunnelSSHObject.hostNames!!.add(port) + tunnelSSHObject.hostPosition.add(position) + tunnelSSHObject.hostNames.add(port) } position += 1 } } - if (tunnelSSHObject.portNames!!.size > 1) tunnelSSHObject.portNames!!.add("All") + if (tunnelSSHObject.portNames.size > 1) tunnelSSHObject.portNames.add("All") tunnelSSHObject.enableSSHPort = true } @@ -226,7 +226,7 @@ open class SSHTunnelViewModel(application: Application) : BaseSSHTunnelViewModel } fun deleteHost(position: Int) { - val parts = tunnelSSHObject.portNames!![position].split(":")[0] + val parts = tunnelSSHObject.portNames[position].split(":")[0] sendMessage(getString(R.string.TREEHOUSES_SSHTUNNEL_REMOVE_HOST, parts)) tunnelSSHObject.addHostText = "deleting host ....." tunnelSSHObject.enableSSHPort = false @@ -237,20 +237,18 @@ open class SSHTunnelViewModel(application: Application) : BaseSSHTunnelViewModel fun deletePort(position: Int) { var myPos = 0 - for (pos in tunnelSSHObject.hostPosition!!.indices) { - if (tunnelSSHObject.hostPosition!![pos] > position) { + for (pos in tunnelSSHObject.hostPosition.indices) { + if (tunnelSSHObject.hostPosition[pos] > position) { myPos = pos break } } - if (tunnelSSHObject.hostPosition!!.last() < position) - myPos = tunnelSSHObject.hostPosition!!.lastIndex + if (tunnelSSHObject.hostPosition.last() < position) + myPos = tunnelSSHObject.hostPosition.lastIndex val portName = TunnelUtils.getPortName(tunnelSSHObject.portNames, position) val formatArgs = portName + " " + tunnelSSHObject.hostNames[myPos].split(":")[0] sendMessage(getString(R.string.TREEHOUSES_SSHTUNNEL_REMOVE_PORT, formatArgs)); tunnelSSHObject.addPortText = "deleting port ....." tunnelSSHObject.enableSSHPort = false; tunnelSSHObject.enableAddPort = false } - - } \ No newline at end of file diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/tor/TorFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/tor/TorFragment.kt index e12a1e3ca..5ffd26980 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/tor/TorFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/tor/TorFragment.kt @@ -54,7 +54,7 @@ class TorFragment : BaseFragment() { } private fun setListeners() { - bind.btnHostName.setOnClickListener() { + bind.btnHostName.setOnClickListener { val builder = AlertDialog.Builder(ContextThemeWrapper(context, R.style.CustomAlertDialogStyle)).setTitle("Tor Hostname") .setMessage(hostName).setPositiveButton("Copy") { _, _ -> viewModel.addHostName(hostName) } .setNegativeButton("Exit", null) @@ -154,7 +154,7 @@ class TorFragment : BaseFragment() { dialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) val window = dialog.window window!!.setGravity(Gravity.CENTER) - window!!.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) + window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) } }