@@ -24,10 +24,9 @@ import io.treehouses.remote.utils.SaveUtils
24
24
import io.treehouses.remote.utils.Utils.toast
25
25
import io.treehouses.remote.utils.logD
26
26
27
-
28
27
class SSHConfigFragment : BaseSSHConfig () {
29
28
30
- override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
29
+ override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View {
31
30
bind = DialogSshBinding .inflate(inflater, container, false )
32
31
if (listener.getChatService().state == Constants .STATE_CONNECTED ) {
33
32
listener.sendMessage(getString(R .string.TREEHOUSES_NETWORKMODE_INFO ))
@@ -42,24 +41,24 @@ class SSHConfigFragment : BaseSSHConfig() {
42
41
addTextValidation()
43
42
Tutorials .sshTutorial(bind, requireActivity())
44
43
bind.connectSsh.setOnClickListener {
45
- var uriString = bind.sshTextInput.text.toString()
44
+ val uriString = bind.sshTextInput.text.toString()
46
45
connect(uriString, false )
47
46
}
48
47
setUpAdapter()
49
48
bind.generateKeys.setOnClickListener { SSHKeyGenFragment ().show(childFragmentManager, " GenerateKey" ) }
50
49
bind.smartConnect.setOnClickListener {
51
50
val shouldConnect = checkForSmartConnectKey()
52
- var uriString = bind.sshTextInput.text.toString()
51
+ val uriString = bind.sshTextInput.text.toString()
53
52
if (shouldConnect) connect(uriString, true )
54
53
}
55
54
bind.showKeys.setOnClickListener { SSHAllKeyFragment ().show(childFragmentManager, " AllKeys" ) }
56
55
}
57
56
58
57
private fun checkForSmartConnectKey (): Boolean {
59
58
if (! KeyUtils .getAllKeyNames(requireContext()).contains(" SmartConnectKey" )) {
60
- if (listener? .getChatService()? .state == Constants .STATE_CONNECTED ) {
59
+ if (listener.getChatService().state == Constants .STATE_CONNECTED ) {
61
60
val key = KeyUtils .createSmartConnectKey(requireContext())
62
- listener? .sendMessage(getString(R .string.TREEHOUSES_SSHKEY_ADD , getOpenSSH(key)))
61
+ listener.sendMessage(getString(R .string.TREEHOUSES_SSHKEY_ADD , getOpenSSH(key)))
63
62
} else {
64
63
context.toast(" Bluetooth not connected. Could not send key to Pi." )
65
64
return false
@@ -115,14 +114,18 @@ class SSHConfigFragment : BaseSSHConfig() {
115
114
bind.sshTextInput.setText(hostAddress)
116
115
logD(" GOT IP $ipAddress " )
117
116
} else if (s.contains(" ip" ) || s.startsWith(" essid" )) {
118
- val ipString = s.split(" , " )[1 ]
119
- val ipAddress = ipString.substring(4 )
120
- val hostAddress = " pi@$ipAddress "
121
- bind.sshTextInput.setText(hostAddress)
122
- logD(" GOT IP $ipAddress " )
117
+ val splitResult = s.split(" , " )
118
+ if (splitResult.size > 1 ) {
119
+ val ipString = splitResult[1 ]
120
+ if (ipString.startsWith(" ip:" )) {
121
+ val ipAddress = ipString.substring(4 )
122
+ val hostAddress = " pi@$ipAddress "
123
+ bind.sshTextInput.setText(hostAddress)
124
+ logD(" GOT IP $ipAddress " )
125
+ }
126
+ }
123
127
}
124
128
}
125
-
126
129
override fun getMessage (msg : Message ) {
127
130
when (msg.what) {
128
131
Constants .MESSAGE_READ -> {
0 commit comments