Merge pull request #327 from meshtastic/isAlwaysPowered

add is_always_powered
pull/329/head
Jm Casler 2021-12-23 15:13:14 -08:00 zatwierdzone przez GitHub
commit c4612f37b4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 32 dodań i 0 usunięć

Wyświetl plik

@ -136,6 +136,17 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
}
}
var isAlwaysPowered: Boolean?
get() = radioConfig.value?.preferences?.isAlwaysPowered
set(value) {
val config = radioConfig.value
if (value != null && config != null) {
val builder = config.toBuilder()
builder.preferencesBuilder.isAlwaysPowered = value
setRadioConfig(builder.build())
}
}
var region: RadioConfigProtos.RegionCode
get() = meshService?.region?.let { RadioConfigProtos.RegionCode.forNumber(it) }
?: RadioConfigProtos.RegionCode.Unset

Wyświetl plik

@ -39,12 +39,14 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
model.radioConfig.observe(viewLifecycleOwner, { _ ->
binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString())
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
binding.isAlwaysPoweredCheckbox.isChecked = model.isAlwaysPowered?: false
})
model.isConnected.observe(viewLifecycleOwner, Observer { connectionState ->
val connected = connectionState == MeshService.ConnectionState.CONNECTED
binding.positionBroadcastPeriodView.isEnabled = connected
binding.lsSleepView.isEnabled = connected
binding.isAlwaysPoweredCheckbox.isEnabled = connected
})
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
@ -84,5 +86,12 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
}
requireActivity().hideKeyboard()
}
binding.isAlwaysPoweredCheckbox.setOnCheckedChangeListener { view, isChecked ->
if (view.isPressed) {
model.isAlwaysPowered = isChecked
debug("User changed isAlwaysPowered to $isChecked")
}
}
}
}

Wyświetl plik

@ -47,4 +47,16 @@
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/isAlwaysPoweredCheckbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="isAlwaysPowered"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lsSleepView" />
</androidx.constraintlayout.widget.ConstraintLayout>