From 064314824d36f4d19ecd13ef66ad3ac7156d145c Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 2 Oct 2023 18:31:24 +0300 Subject: [PATCH] handle null pointers --- .../io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt | 4 ++-- .../treehouses/remote/ssh/terminal/TerminalKeyListener.kt | 4 ++-- .../io/treehouses/remote/ssh/terminal/TerminalManager.kt | 6 +++--- .../io/treehouses/remote/ssh/terminal/TerminalView.kt | 6 +++--- .../kotlin/io/treehouses/remote/sshconsole/SSHConsole.kt | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) 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 3e7d7bb10..fabb79f94 100644 --- a/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt +++ b/app/src/main/kotlin/io/treehouses/remote/adapter/ViewHolderSSHAllKeyRow.kt @@ -37,8 +37,8 @@ class ViewHolderSSHAllKeyRow(private val binding: RowKeyBinding, private val lis menu?.children?.forEach { it.setOnMenuItemClickListener(this) } } - override fun onMenuItemClick(item: MenuItem?): Boolean { - when (item?.itemId) { + override fun onMenuItemClick(item: MenuItem): Boolean { + when (item.itemId) { R.id.copy_public -> listener.onCopyPub(adapterPosition) R.id.delete_key -> listener.onDelete(adapterPosition) R.id.send_key -> listener.onSendToRaspberry(adapterPosition) diff --git a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalKeyListener.kt b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalKeyListener.kt index d81639edf..e29e3087f 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalKeyListener.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalKeyListener.kt @@ -36,8 +36,8 @@ class TerminalKeyListener(tm: TerminalManager?, } else false } - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, - key: String) { + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, + key: String?) { if (PreferenceConstants.KEYMODE == key || PreferenceConstants.SHIFT_FKEYS == key || PreferenceConstants.CTRL_FKEYS == key || PreferenceConstants.VOLUME_FONT == key || PreferenceConstants.STICKY_MODIFIERS == key) { updatePrefs() } diff --git a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalManager.kt b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalManager.kt index 204b8e987..5acf7cd5f 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalManager.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalManager.kt @@ -357,9 +357,9 @@ class TerminalManager : Service(), BridgeDisconnectedListener, OnSharedPreferenc /* (non-Javadoc) * @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String) */ - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, - key: String) { - if (PreferenceConstants.BUMPY_ARROWS == key) wantKeyVibration = sharedPreferences.getBoolean(PreferenceConstants.BUMPY_ARROWS, true) + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, + key: String?) { + if (PreferenceConstants.BUMPY_ARROWS == key) wantKeyVibration = sharedPreferences!!.getBoolean(PreferenceConstants.BUMPY_ARROWS, true) else if (PreferenceConstants.WIFI_LOCK == key) { } else if (PreferenceConstants.MEMKEYS == key) savingKeys = prefs!!.getBoolean(PreferenceConstants.MEMKEYS, true) } diff --git a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalView.kt b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalView.kt index 1c5357e15..ebbdbfb9d 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalView.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ssh/terminal/TerminalView.kt @@ -313,10 +313,10 @@ class TerminalView(context: Context, bridge: TerminalBridge, pager: TerminalView * This should only handle scrolling when terminalTextViewOverlay is `null`, but * we need to handle the page up/down gesture if it's enabled. */ - override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean { + override fun onScroll(e1: MotionEvent?, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean { // activate consider if within x tolerance val touchSlop = ViewConfiguration.get(this@TerminalView.context).scaledTouchSlop - if (Math.abs(e1.x - e2.x) < touchSlop * 4) { + if (Math.abs(e1!!.x - e2.x) < touchSlop * 4) { // estimate how many rows we have scrolled through // accumulate distance that doesn't trigger immediate scroll totalY += distanceY @@ -346,7 +346,7 @@ class TerminalView(context: Context, bridge: TerminalBridge, pager: TerminalView return super.onSingleTapConfirmed(e) } - override fun onDoubleTap(e: MotionEvent?): Boolean { + override fun onDoubleTap(e: MotionEvent): Boolean { try { bridge.transport?.write(0x09) bridge.tryKeyVibrate() diff --git a/app/src/main/kotlin/io/treehouses/remote/sshconsole/SSHConsole.kt b/app/src/main/kotlin/io/treehouses/remote/sshconsole/SSHConsole.kt index f8746dfa9..0f12d53f9 100644 --- a/app/src/main/kotlin/io/treehouses/remote/sshconsole/SSHConsole.kt +++ b/app/src/main/kotlin/io/treehouses/remote/sshconsole/SSHConsole.kt @@ -188,7 +188,7 @@ open class SSHConsole : DerivedSSHConsole(), BridgeDisconnectedListener { return true } - override fun onOptionsItemSelected(item: MenuItem?): Boolean { + override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item == null) return false return when (item.itemId) { android.R.id.home -> {