fix: scale auto-reconnect + reconfigure button in kiosk settings
GatewayService: - onScanStopped() now calls scheduleReconnect() when not connected, so if the scale is off at startup the service keeps retrying every 8s instead of giving up after the first 20s scan window SettingsActivity: - Add 'Riconfigura bilancia' button (yellow outline) when a scale is already configured — clears saved device, stops the gateway service, and opens SetupActivity directly at step 4 (scale scan step) SetupActivity: - Accept 'start_step' intent extra to jump directly to a specific step (used by SettingsActivity reconfigure flow)
This commit is contained in:
@@ -58,6 +58,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
val statusView = findViewById<TextView>(R.id.scaleGatewayStatus)
|
val statusView = findViewById<TextView>(R.id.scaleGatewayStatus)
|
||||||
val deviceView = findViewById<TextView>(R.id.scaleDeviceInfo)
|
val deviceView = findViewById<TextView>(R.id.scaleDeviceInfo)
|
||||||
val btnScaleAction = findViewById<MaterialButton>(R.id.btnConfigureGateway)
|
val btnScaleAction = findViewById<MaterialButton>(R.id.btnConfigureGateway)
|
||||||
|
val btnReconfigureScale = findViewById<MaterialButton>(R.id.btnReconfigureScale)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
!hasScale || deviceAddr == null -> {
|
!hasScale || deviceAddr == null -> {
|
||||||
@@ -83,6 +84,20 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
GatewayService.start(this)
|
GatewayService.start(this)
|
||||||
Toast.makeText(this, "Servizio bilancia riavviato", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "Servizio bilancia riavviato", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
btnReconfigureScale.visibility = android.view.View.VISIBLE
|
||||||
|
btnReconfigureScale.setOnClickListener {
|
||||||
|
GatewayService.stop(this)
|
||||||
|
prefs.edit()
|
||||||
|
.remove("scale_device_address")
|
||||||
|
.remove("scale_device_name")
|
||||||
|
.putBoolean(KEY_HAS_SCALE, false)
|
||||||
|
.putBoolean(KEY_SETUP_COMPLETE, false)
|
||||||
|
.apply()
|
||||||
|
val intent = Intent(this, SetupActivity::class.java)
|
||||||
|
intent.putExtra("start_step", 4)
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
// Probe WebSocket port to show live status
|
// Probe WebSocket port to show live status
|
||||||
Thread {
|
Thread {
|
||||||
val running = try {
|
val running = try {
|
||||||
|
|||||||
@@ -161,9 +161,11 @@ class SetupActivity : AppCompatActivity() {
|
|||||||
bindViews()
|
bindViews()
|
||||||
// Restore step from instance state (e.g. after recreate() for locale change)
|
// Restore step from instance state (e.g. after recreate() for locale change)
|
||||||
val savedStep = savedInstanceState?.getInt("step", -1) ?: -1
|
val savedStep = savedInstanceState?.getInt("step", -1) ?: -1
|
||||||
|
val startStepExtra = intent.getIntExtra("start_step", -1)
|
||||||
val langAlreadySet = prefs.getString(KEY_LANGUAGE, null) != null
|
val langAlreadySet = prefs.getString(KEY_LANGUAGE, null) != null
|
||||||
showStep(when {
|
showStep(when {
|
||||||
savedStep >= 0 -> savedStep
|
savedStep >= 0 -> savedStep
|
||||||
|
startStepExtra >= 0 -> startStepExtra
|
||||||
langAlreadySet -> 1
|
langAlreadySet -> 1
|
||||||
else -> 0
|
else -> 0
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-1
@@ -183,7 +183,10 @@ class GatewayService : Service(), BleScaleListener, ServerEventListener {
|
|||||||
scheduleReconnect()
|
scheduleReconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScanStopped() { /* auto-reconnect handles retries */ }
|
override fun onScanStopped() {
|
||||||
|
// If not connected yet, schedule a retry so we keep searching after the scale powers on
|
||||||
|
if (!bleManager.isConnected) scheduleReconnect()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDebugEvent(message: String) {
|
override fun onDebugEvent(message: String) {
|
||||||
Log.d(TAG, message)
|
Log.d(TAG, message)
|
||||||
|
|||||||
@@ -154,6 +154,19 @@
|
|||||||
android:textColor="#34d399"
|
android:textColor="#34d399"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btnReconfigureScale"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:text="🔄 Riconfigura bilancia"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
|
android:strokeColor="#fbbf24"
|
||||||
|
android:textColor="#fbbf24"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Screensaver Section -->
|
<!-- Screensaver Section -->
|
||||||
|
|||||||
Reference in New Issue
Block a user