@@ -24,10 +24,9 @@ import io.treehouses.remote.utils.SaveUtils
2424import io.treehouses.remote.utils.Utils.toast
2525import io.treehouses.remote.utils.logD
2626
27-
2827class SSHConfigFragment : BaseSSHConfig () {
2928
30- override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
29+ override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View {
3130 bind = DialogSshBinding .inflate(inflater, container, false )
3231 if (listener.getChatService().state == Constants .STATE_CONNECTED ) {
3332 listener.sendMessage(getString(R .string.TREEHOUSES_NETWORKMODE_INFO ))
@@ -42,24 +41,24 @@ class SSHConfigFragment : BaseSSHConfig() {
4241 addTextValidation()
4342 Tutorials .sshTutorial(bind, requireActivity())
4443 bind.connectSsh.setOnClickListener {
45- var uriString = bind.sshTextInput.text.toString()
44+ val uriString = bind.sshTextInput.text.toString()
4645 connect(uriString, false )
4746 }
4847 setUpAdapter()
4948 bind.generateKeys.setOnClickListener { SSHKeyGenFragment ().show(childFragmentManager, " GenerateKey" ) }
5049 bind.smartConnect.setOnClickListener {
5150 val shouldConnect = checkForSmartConnectKey()
52- var uriString = bind.sshTextInput.text.toString()
51+ val uriString = bind.sshTextInput.text.toString()
5352 if (shouldConnect) connect(uriString, true )
5453 }
5554 bind.showKeys.setOnClickListener { SSHAllKeyFragment ().show(childFragmentManager, " AllKeys" ) }
5655 }
5756
5857 private fun checkForSmartConnectKey (): Boolean {
5958 if (! KeyUtils .getAllKeyNames(requireContext()).contains(" SmartConnectKey" )) {
60- if (listener? .getChatService()? .state == Constants .STATE_CONNECTED ) {
59+ if (listener.getChatService().state == Constants .STATE_CONNECTED ) {
6160 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)))
6362 } else {
6463 context.toast(" Bluetooth not connected. Could not send key to Pi." )
6564 return false
@@ -115,14 +114,18 @@ class SSHConfigFragment : BaseSSHConfig() {
115114 bind.sshTextInput.setText(hostAddress)
116115 logD(" GOT IP $ipAddress " )
117116 } 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+ }
123127 }
124128 }
125-
126129 override fun getMessage (msg : Message ) {
127130 when (msg.what) {
128131 Constants .MESSAGE_READ -> {
0 commit comments