@@ -82,6 +82,7 @@ public void onServiceDisconnected(ComponentName componentName) {
8282 private MaterialPreferenceCategory notificationsCategory ;
8383 private LinearLayout logsContainer ;
8484 private MessageView logsMessage ;
85+ private LocalBroadcastManager broadcastManager ;
8586
8687 private static boolean isARM () {
8788 for (String abi : Build .SUPPORTED_ABIS )
@@ -114,8 +115,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
114115 Uri uri = data .getData ();
115116 if (uri != null ) {
116117 outputPath .setValue (FileUtil .getFullPathFromTreeUri (uri , this ));
117- int takeFlags = data . getFlags () & ( Intent . FLAG_GRANT_READ_URI_PERMISSION | Intent . FLAG_GRANT_WRITE_URI_PERMISSION );
118- getContentResolver (). takePersistableUriPermission ( uri , takeFlags );
118+ getContentResolver (). takePersistableUriPermission ( uri ,
119+ data . getFlags () & ( Intent . FLAG_GRANT_READ_URI_PERMISSION | Intent . FLAG_GRANT_WRITE_URI_PERMISSION ) );
119120 }
120121 }
121122 } else {
@@ -166,6 +167,7 @@ protected void onCreate(Bundle savedInstanceState) {
166167 }
167168
168169 setContentView (R .layout .activity_main );
170+ broadcastManager = LocalBroadcastManager .getInstance (this );
169171
170172 MaterialPreferences .instance ().setUserInputModule (new LovelyInput .Builder ()
171173 .addIcon (PK .OUTPUT_DIRECTORY .key (), R .drawable .baseline_folder_24 )
@@ -416,7 +418,7 @@ public void askRationale(@NonNull AlertDialog.Builder builder) {
416418 filter .addAction (action .toString ());
417419
418420 receiver = new ServiceBroadcastReceiver ();
419- LocalBroadcastManager . getInstance ( this ) .registerReceiver (receiver , filter );
421+ broadcastManager .registerReceiver (receiver , filter );
420422 try {
421423 bindService (new Intent (this , BinService .class ), serviceConnection , BIND_AUTO_CREATE );
422424 startService (new Intent (this , BinService .class )
@@ -425,7 +427,7 @@ public void askRationale(@NonNull AlertDialog.Builder builder) {
425427 return true ;
426428 } catch (JSONException ex ) {
427429 Toaster .with (this ).message (R .string .failedLoadingOptions ).ex (ex ).show ();
428- LocalBroadcastManager . getInstance ( this ) .unregisterReceiver (receiver );
430+ broadcastManager .unregisterReceiver (receiver );
429431 return false ;
430432 } /*catch (RemoteException ex) {
431433 Toaster.with(this).message(R.string.failedStarting).ex(ex).show();
@@ -463,6 +465,8 @@ private boolean stopService() {
463465 startService (new Intent (this , BinService .class )
464466 .setAction (BinService .ACTION_STOP_SERVICE ));
465467
468+ broadcastManager .unregisterReceiver (receiver );
469+
466470 Bundle bundle = null ;
467471 if (Prefs .getLong (PK .CURRENT_SESSION_START , -1 ) != -1 ) {
468472 bundle = new Bundle ();
@@ -471,7 +475,6 @@ private boolean stopService() {
471475 }
472476
473477 AnalyticsApplication .sendAnalytics (Utils .ACTION_TURN_OFF , bundle );
474-
475478 return true ;
476479 }
477480
@@ -576,15 +579,14 @@ public void onReceive(Context context, final Intent intent) {
576579 runOnUiThread (() -> {
577580 switch (action ) {
578581 case SERVER_STATUS :
579- System .out .println ("UPDATE!!" );
580- updateUiStatus (intent .getBooleanExtra ("on" , false ));
582+ updateUiStatus (intent .getBooleanExtra ("on" , false )); // FIXME: UI changes are not applied
581583 break ;
582584 case SERVER_START :
583585 addLog (new Logging .LogLine (Logging .LogLine .Type .INFO , getString (R .string .serverStarted )));
584586 break ;
585587 case SERVER_STOP :
586588 addLog (new Logging .LogLine (Logging .LogLine .Type .INFO , getString (R .string .serverStopped )));
587- LocalBroadcastManager . getInstance ( MainActivity . this ) .unregisterReceiver (receiver );
589+ broadcastManager .unregisterReceiver (receiver );
588590 updateUiStatus (false );
589591 break ;
590592 case SERVER_EX :
0 commit comments