diff --git a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SettingsActivity.kt b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SettingsActivity.kt index 0b91838..7afe21d 100644 --- a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SettingsActivity.kt +++ b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SettingsActivity.kt @@ -58,6 +58,7 @@ class SettingsActivity : AppCompatActivity() { val statusView = findViewById(R.id.scaleGatewayStatus) val deviceView = findViewById(R.id.scaleDeviceInfo) val btnScaleAction = findViewById(R.id.btnConfigureGateway) + val btnReconfigureScale = findViewById(R.id.btnReconfigureScale) when { !hasScale || deviceAddr == null -> { @@ -83,6 +84,20 @@ class SettingsActivity : AppCompatActivity() { GatewayService.start(this) 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 Thread { val running = try { diff --git a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SetupActivity.kt b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SetupActivity.kt index 603379b..1f1825f 100644 --- a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SetupActivity.kt +++ b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/SetupActivity.kt @@ -161,9 +161,11 @@ class SetupActivity : AppCompatActivity() { bindViews() // Restore step from instance state (e.g. after recreate() for locale change) val savedStep = savedInstanceState?.getInt("step", -1) ?: -1 + val startStepExtra = intent.getIntExtra("start_step", -1) val langAlreadySet = prefs.getString(KEY_LANGUAGE, null) != null showStep(when { savedStep >= 0 -> savedStep + startStepExtra >= 0 -> startStepExtra langAlreadySet -> 1 else -> 0 }) diff --git a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/scale/GatewayService.kt b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/scale/GatewayService.kt index 69ceacd..3623f62 100644 --- a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/scale/GatewayService.kt +++ b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/scale/GatewayService.kt @@ -183,7 +183,10 @@ class GatewayService : Service(), BleScaleListener, ServerEventListener { 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) { Log.d(TAG, message) diff --git a/evershelf-kiosk/app/src/main/res/layout/activity_settings.xml b/evershelf-kiosk/app/src/main/res/layout/activity_settings.xml index 4b6fcd9..4e316ab 100644 --- a/evershelf-kiosk/app/src/main/res/layout/activity_settings.xml +++ b/evershelf-kiosk/app/src/main/res/layout/activity_settings.xml @@ -154,6 +154,19 @@ android:textColor="#34d399" android:layout_marginTop="12dp" android:visibility="gone" /> + +