Merge pull request #233 from vfurman-gh/settings

Added ability to edit broadcast_position and ls_sleep settings
pull/238/head
Kevin Hester 2021-02-06 14:21:32 +08:00 zatwierdzone przez GitHub
commit 67b1448a9d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 131 dodań i 6 usunięć

Wyświetl plik

@ -121,7 +121,7 @@
android:name="com.geeksville.mesh.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Wyświetl plik

@ -102,6 +102,49 @@ class UIViewModel(app: Application) : AndroidViewModel(app), Logging {
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
}
var positionBroadcastSecs: Int?
get() {
radioConfig.value?.preferences?.let {
if (it.locationShare == MeshProtos.LocationSharing.LocDisabled) return 0
if (it.positionBroadcastSecs > 0) return it.positionBroadcastSecs
// These default values are borrowed from the device code.
if (it.isRouter) return 60 * 60
return 15 * 60
}
return null
}
set(value) {
val config = radioConfig.value
if (value != null && config != null) {
val builder = config.toBuilder()
if (value > 0) {
builder.preferencesBuilder.positionBroadcastSecs = value
builder.preferencesBuilder.locationShare =
MeshProtos.LocationSharing.LocEnabled
} else
builder.preferencesBuilder.locationShare =
MeshProtos.LocationSharing.LocDisabled
setRadioConfig(builder.build())
}
}
var lsSleepSecs: Int?
get() {
radioConfig.value?.preferences?.let {
return it.lsSecs
}
return null
}
set(value) {
val config = radioConfig.value
if (value != null && config != null) {
val builder = config.toBuilder()
builder.preferencesBuilder.lsSecs = value
setRadioConfig(builder.build())
}
}
/// hardware info about our local device
val myNodeInfo = object : MutableLiveData<MyNodeInfo>(null) {}

Wyświetl plik

@ -30,6 +30,7 @@ import com.geeksville.android.Logging
import com.geeksville.android.hideKeyboard
import com.geeksville.android.isGooglePlayAvailable
import com.geeksville.mesh.MainActivity
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.R
import com.geeksville.mesh.android.bluetoothManager
import com.geeksville.mesh.android.usbManager
@ -461,7 +462,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
@SuppressLint("NewApi")
class SettingsFragment : ScreenFragment("Settings"), Logging {
private val MAX_INT_DEVICE = 0xFFFFFFFF
private var _binding: SettingsFragmentBinding? = null
// This property is only valid between onCreateView and onDestroyView.
@ -573,15 +574,25 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
/// Setup the ui widgets unrelated to BLE scanning
private fun initCommonUI() {
model.ownerName.observe(viewLifecycleOwner, Observer { name ->
model.ownerName.observe(viewLifecycleOwner, { name ->
binding.usernameEditText.setText(name)
})
model.radioConfig.observe(viewLifecycleOwner, { _ ->
binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString())
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
})
// Only let user edit their name or set software update while connected to a radio
model.isConnected.observe(viewLifecycleOwner, Observer { connected ->
binding.usernameView.isEnabled = connected == MeshService.ConnectionState.CONNECTED
if (connected == MeshService.ConnectionState.DISCONNECTED)
model.isConnected.observe(viewLifecycleOwner, Observer { connectionState ->
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.usernameView.isEnabled = connected
binding.positionBroadcastPeriodView.isEnabled = connected
binding.lsSleepView.isEnabled = connected
if (connectionState == MeshService.ConnectionState.DISCONNECTED)
model.ownerName.value = ""
initNodeInfo()
})
@ -599,7 +610,28 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
val n = binding.usernameEditText.text.toString().trim()
if (n.isNotEmpty())
model.setOwner(n)
requireActivity().hideKeyboard()
}
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
val str = binding.positionBroadcastPeriodEditText.text.toString()
val n = str.toIntOrNull()
if (n != null && n <= MAX_INT_DEVICE && n >= 0) {
model.positionBroadcastSecs = n
} else {
binding.scanStatusText.text = "Bad value: $str"
}
requireActivity().hideKeyboard()
}
binding.lsSleepEditText.on(EditorInfo.IME_ACTION_DONE) {
val str = binding.lsSleepEditText.text.toString()
val n = str.toIntOrNull()
if (n != null && n < MAX_INT_DEVICE && n >= 0) {
model.lsSleepSecs = n
} else {
binding.scanStatusText.text = "Bad value: $str"
}
requireActivity().hideKeyboard()
}

Wyświetl plik

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -19,6 +20,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/deviceRadioGroup" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/usernameView"
android:layout_width="0dp"
@ -39,6 +41,7 @@
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/scanStatusText"
android:layout_width="0dp"
@ -138,4 +141,49 @@
app:layout_constraintTop_toBottomOf="@+id/updateFirmwareButton" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/positionBroadcastPeriodView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/broadcast_position_secs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/warningNotPaired">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/positionBroadcastPeriodEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/lsSleepView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/ls_sleep_secs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/positionBroadcastPeriodView">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/lsSleepEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Wyświetl plik

@ -83,4 +83,6 @@
<string name="message_reception_time">message reception time</string>
<string name="message_reception_state">message reception state</string>
<string name="message_delivery_status">Message delivery status</string>
<string name="broadcast_position_secs">Broadcast position period (in seconds), 0 - disable</string>
<string name="ls_sleep_secs">Device sleep period (in seconds)</string>
</resources>