Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: no unnecessary non null (fixes #1954) #1957

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class EditHostDialogFragment : FullScreenDialogFragment(), FragmentDialogInterfa

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
dismissListener?.onDismiss(dialog)
dismissListener.onDismiss(dialog)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}