@@ -184,19 +184,38 @@ private void updateFabIcon() {
184184 }
185185 }
186186
187+ private void showFabProgress () {
188+ if (fab == null ) return ;
189+ fab .setImageResource (R .drawable .ic_loading_animated );
190+ fab .setEnabled (false );
191+ }
192+
193+ private void hideFabProgress () {
194+ if (fab == null ) return ;
195+ fab .setEnabled (true );
196+ updateFabIcon ();
197+ }
198+
187199 private void stopHub () {
188- Toast .makeText (requireContext (), R .string .stopping_sensorhub , Toast .LENGTH_SHORT ).show ();
200+ showFabProgress ();
201+ newStatusMessage (getString (R .string .stopping_sensorhub ));
189202 stopRefreshingStatus ();
190- provider .stopSensorHub ();
191- updateFabIcon ();
192203 hideVideoPreview ();
193204 clearTextureView ();
194205 videoStatusCard .setVisibility (View .GONE );
195206 if (videoControlsOverlay != null ) videoControlsOverlay .setVisibility (View .GONE );
196207 currentZoomLevel = 0 ;
197208 if (meshtasticCard != null ) meshtasticCard .setVisibility (View .GONE );
198- newStatusMessage (getString (R .string .sensorhub_stopped ));
199- requireActivity ().getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
209+ provider .stopSensorHub ();
210+
211+ // Brief delay to let the service finish stopping on its background thread
212+ displayHandler .postDelayed (() -> {
213+ if (!isAdded ()) return ;
214+ hideFabProgress ();
215+ updateFabIcon ();
216+ newStatusMessage (getString (R .string .sensorhub_stopped ));
217+ requireActivity ().getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
218+ }, 1000 );
200219 }
201220
202221 private void clearTextureView () {
@@ -248,7 +267,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
248267 showVideoConfigErrorPopup ();
249268 newStatusMessage (getString (R .string .video_config_error ));
250269 } else {
251- Toast . makeText ( requireContext (), R . string . starting_sensorhub , Toast . LENGTH_SHORT ). show ();
270+ showFabProgress ();
252271 newStatusMessage (getString (R .string .starting_sensorhub ));
253272 provider .getSostClients ().clear ();
254273 provider .getConSysClients ().clear ();
@@ -297,6 +316,7 @@ private void pollHubReady() {
297316
298317 if (!provider .isOshStarted ()) {
299318 provider .setOshStarted (true );
319+ hideFabProgress ();
300320 updateFabIcon ();
301321 serverStatusContainer .removeAllViews ();
302322 serverCardViews .clear ();
@@ -309,6 +329,7 @@ private void pollHubReady() {
309329 } else if (hubPollAttempts < HUB_POLL_MAX_ATTEMPTS ) {
310330 displayHandler .postDelayed (this ::pollHubReady , HUB_POLL_INTERVAL_MS );
311331 } else {
332+ hideFabProgress ();
312333 newStatusMessage (getString (R .string .sensorhub_start_failed ));
313334 updateFabIcon ();
314335 }
0 commit comments