feat: Adds Field to Specify Device IP (#663)

This commit is contained in:
Jonathan Bennett 2023-07-17 18:28:32 -05:00 committed by GitHub
parent 4e410622d8
commit bbb9ca3921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.RemoteException
import android.util.Patterns
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -24,6 +25,7 @@ import android.widget.RadioButton
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.asLiveData
@ -455,6 +457,27 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
}
}
private fun addManualDeviceButton() {
val b = binding.radioButtonManual
val e = binding.editManualAddress
b.isEnabled = false
binding.deviceRadioGroup.addView(b)
b.setOnClickListener {
b.isChecked = onSelected(BTScanModel.DeviceListEntry("", "t" + e.text, true))
}
binding.deviceRadioGroup.addView(e)
e.doAfterTextChanged {
b.isEnabled = Patterns.IP_ADDRESS.matcher(e.text).matches()
}
}
private fun updateDevicesButtons(devices: MutableMap<String, BTScanModel.DeviceListEntry>?) {
// Remove the old radio buttons and repopulate
binding.deviceRadioGroup.removeAllViews()
@ -481,6 +504,8 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
}
}
addManualDeviceButton()
// get rid of the warning text once at least one device is paired.
// If we are running on an emulator, always leave this message showing so we can test the worst case layout
val curRadio = scanModel.selectedAddress

View file

@ -109,6 +109,22 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/test_devname2" />
<RadioButton
android:id="@+id/radioButtonManual"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/ip_address" />
<EditText
android:id="@+id/editManualAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/ip_address"
android:inputType="number|text"
android:visibility="visible" />
</RadioGroup>
<com.google.android.material.floatingactionbutton.FloatingActionButton

View file

@ -50,6 +50,7 @@
<string name="connected_count">Connected: %1$s of %2$s online</string>
<string name="list_of_nodes">A list of nodes in the network</string>
<string name="update_firmware">Update Firmware</string>
<string name="ip_address">IP Address:</string>
<string name="connected">Connected to radio</string>
<string name="connected_to">Connected to radio (%s)</string>
<string name="not_connected">Not connected</string>