mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Moved broadcast and ls_sleep in advanced settings
This commit is contained in:
parent
380ca1017f
commit
757c3867f2
6 changed files with 147 additions and 84 deletions
|
|
@ -52,6 +52,7 @@ import com.google.android.gms.common.ConnectionResult
|
|||
import com.google.android.gms.common.GoogleApiAvailability
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
import com.vorlonsoft.android.rate.AppRate
|
||||
|
|
@ -978,6 +979,15 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
handler.removeCallbacksAndMessages(null)
|
||||
return true
|
||||
}
|
||||
R.id.advanced_settings -> {
|
||||
val fragmentManager: FragmentManager = supportFragmentManager
|
||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||
val nameFragment = AdvancedSettingsFragment()
|
||||
fragmentTransaction.add(R.id.mainActivityLayout, nameFragment)
|
||||
fragmentTransaction.addToBackStack(null)
|
||||
fragmentTransaction.commit()
|
||||
return true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
package com.geeksville.mesh.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.Observer
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.android.hideKeyboard
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.databinding.AdvancedSettingsBinding
|
||||
import com.geeksville.mesh.model.ChannelOption
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.service.MeshService
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
||||
private val MAX_INT_DEVICE = 0xFFFFFFFF
|
||||
private var _binding: AdvancedSettingsBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val model: UIViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = AdvancedSettingsBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
model.radioConfig.observe(viewLifecycleOwner, { _ ->
|
||||
binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString())
|
||||
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
|
||||
})
|
||||
|
||||
model.isConnected.observe(viewLifecycleOwner, Observer { connectionState ->
|
||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
binding.positionBroadcastPeriodView.isEnabled = connected
|
||||
binding.lsSleepView.isEnabled = connected
|
||||
})
|
||||
|
||||
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
|
||||
val textEdit = binding.positionBroadcastPeriodEditText
|
||||
val n = textEdit.text.toString().toIntOrNull()
|
||||
val minBroadcastPeriodSecs =
|
||||
ChannelOption.fromConfig(model.radioConfig.value?.channelSettings?.modemConfig)?.minBroadcastPeriodSecs
|
||||
?: 9000
|
||||
info("edit broadcast $n min $minBroadcastPeriodSecs")
|
||||
if (n != null && n < MAX_INT_DEVICE && (n == 0 || n >= minBroadcastPeriodSecs)) {
|
||||
model.positionBroadcastSecs = n
|
||||
} else {
|
||||
// restore the value in the edit field
|
||||
textEdit.setText(model.positionBroadcastSecs.toString())
|
||||
val errorText = when {
|
||||
(n == null || n < 0 || n >= MAX_INT_DEVICE) -> "Bad value: ${textEdit.text.toString()}"
|
||||
else -> getString(R.string.broadcast_period_too_small).format(minBroadcastPeriodSecs)
|
||||
}
|
||||
Snackbar.make(requireView(), errorText, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
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 {
|
||||
Snackbar.make(requireView(), "Bad value: $str", Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
requireActivity().hideKeyboard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -463,7 +463,6 @@ 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.
|
||||
|
|
@ -575,28 +574,18 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
/// Setup the ui widgets unrelated to BLE scanning
|
||||
private fun initCommonUI() {
|
||||
// We want to leave these visible in the IDE, but make sure they default to not visible until we have valid data
|
||||
binding.positionBroadcastPeriodView.visibility = View.GONE
|
||||
binding.lsSleepView.visibility = View.GONE
|
||||
|
||||
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 { connectionState ->
|
||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
binding.usernameView.isEnabled = connected
|
||||
|
||||
// Don't even show advanced fields until after we have a connection
|
||||
binding.positionBroadcastPeriodView.visibility = if (connected) View.VISIBLE else View.GONE
|
||||
binding.lsSleepView.visibility = if (connected) View.VISIBLE else View.GONE
|
||||
|
||||
if (connectionState == MeshService.ConnectionState.DISCONNECTED)
|
||||
model.ownerName.value = ""
|
||||
|
||||
|
|
@ -620,36 +609,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
requireActivity().hideKeyboard()
|
||||
}
|
||||
|
||||
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
|
||||
val textEdit = binding.positionBroadcastPeriodEditText
|
||||
val n = textEdit.text.toString().toIntOrNull()
|
||||
val minBroadcastPeriodSecs =
|
||||
ChannelOption.fromConfig(model.radioConfig.value?.channelSettings?.modemConfig)?.minBroadcastPeriodSecs
|
||||
?: 9000
|
||||
info("edit broadcast $n min $minBroadcastPeriodSecs")
|
||||
if (n != null && n < MAX_INT_DEVICE && (n == 0 || n >= minBroadcastPeriodSecs)) {
|
||||
model.positionBroadcastSecs = n
|
||||
} else {
|
||||
// restore the value in the edit field
|
||||
textEdit.setText(model.positionBroadcastSecs.toString())
|
||||
val errorText = if (n == null || n < 0 || n >= MAX_INT_DEVICE) "Bad value: ${textEdit.text.toString()}" else
|
||||
getString(R.string.broadcast_period_too_small).format(minBroadcastPeriodSecs)
|
||||
Snackbar.make(requireView(), errorText, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
val app = (requireContext().applicationContext as GeeksvilleApplication)
|
||||
|
||||
|
|
|
|||
50
app/src/main/res/layout/advanced_settings.xml
Normal file
50
app/src/main/res/layout/advanced_settings.xml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFFFFF">
|
||||
|
||||
<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_toTopOf="parent">
|
||||
|
||||
<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>
|
||||
|
|
@ -152,48 +152,6 @@
|
|||
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>
|
||||
</ScrollView>
|
||||
|
|
@ -16,6 +16,10 @@
|
|||
android:checkable="true"
|
||||
android:checked="false"
|
||||
android:title="Protocol stress test" />
|
||||
<item
|
||||
android:id="@+id/advanced_settings"
|
||||
app:showAsAction="withText"
|
||||
android:title="Advanced settings" />
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue