@@ -117,7 +117,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
117
117
/**
118
118
* The {@link TermuxActivity} broadcast receiver for various things like terminal style configuration changes.
119
119
*/
120
- private final BroadcastReceiver mTermuxActivityBroadcastReceiever = new TermuxActivityBroadcastReceiver ();
120
+ private final BroadcastReceiver mTermuxActivityBroadcastReceiver = new TermuxActivityBroadcastReceiver ();
121
121
122
122
/**
123
123
* The last toast shown, used cancel current toast before showing new in {@link #showToast(String, boolean)}.
@@ -222,7 +222,7 @@ public void onStart() {
222
222
termuxSessionListNotifyUpdated ();
223
223
}
224
224
225
- registerReceiver ( mTermuxActivityBroadcastReceiever , new IntentFilter ( TERMUX_ACTIVITY . ACTION_RELOAD_STYLE ) );
225
+ registerTermuxActivityBroadcastReceiver ( );
226
226
227
227
// If user changed the preference from {@link TermuxSettings} activity and returns, then
228
228
// update the {@link TerminalView#TERMINAL_VIEW_KEY_LOGGING_ENABLED} value.
@@ -309,7 +309,7 @@ protected void onStop() {
309
309
// {@link #onStart} if needed.
310
310
mTermuxTerminalSessionClient .setCurrentStoredSession ();
311
311
312
- unregisterReceiver ( mTermuxActivityBroadcastReceiever );
312
+ unregisterTermuxActivityBroadcastReceiever ( );
313
313
getDrawer ().closeDrawers ();
314
314
}
315
315
@@ -716,47 +716,79 @@ public TermuxAppSharedProperties getProperties() {
716
716
public static void updateTermuxActivityStyling (Context context ) {
717
717
// Make sure that terminal styling is always applied.
718
718
Intent stylingIntent = new Intent (TERMUX_ACTIVITY .ACTION_RELOAD_STYLE );
719
- stylingIntent .putExtra (TERMUX_ACTIVITY .EXTRA_RELOAD_STYLE , "styling" );
720
719
context .sendBroadcast (stylingIntent );
721
720
}
722
721
722
+ private void registerTermuxActivityBroadcastReceiver () {
723
+ IntentFilter intentFilter = new IntentFilter ();
724
+ intentFilter .addAction (TERMUX_ACTIVITY .ACTION_REQUEST_PERMISSIONS );
725
+ intentFilter .addAction (TERMUX_ACTIVITY .ACTION_RELOAD_STYLE );
726
+
727
+ registerReceiver (mTermuxActivityBroadcastReceiver , intentFilter );
728
+ }
729
+
730
+ private void unregisterTermuxActivityBroadcastReceiever () {
731
+ unregisterReceiver (mTermuxActivityBroadcastReceiver );
732
+ }
733
+
734
+ private void fixTermuxActivityBroadcastReceieverIntent (Intent intent ) {
735
+ if (intent == null ) return ;
736
+
737
+ String extraReloadStyle = intent .getStringExtra (TERMUX_ACTIVITY .EXTRA_RELOAD_STYLE );
738
+ if ("storage" .equals (extraReloadStyle )) {
739
+ intent .removeExtra (TERMUX_ACTIVITY .EXTRA_RELOAD_STYLE );
740
+ intent .setAction (TERMUX_ACTIVITY .ACTION_REQUEST_PERMISSIONS );
741
+ }
742
+ }
743
+
723
744
class TermuxActivityBroadcastReceiver extends BroadcastReceiver {
724
745
@ Override
725
746
public void onReceive (Context context , Intent intent ) {
747
+ if (intent == null ) return ;
748
+
726
749
if (mIsVisible ) {
727
- String whatToReload = intent .getStringExtra (TERMUX_ACTIVITY .EXTRA_RELOAD_STYLE );
728
- Logger .logDebug (LOG_TAG , "Reloading termux style for: " + whatToReload );
729
- if ("storage" .equals (whatToReload )) {
730
- if (ensureStoragePermissionGranted ())
731
- TermuxInstaller .setupStorageSymlinks (TermuxActivity .this );
732
- return ;
750
+ fixTermuxActivityBroadcastReceieverIntent (intent );
751
+
752
+ switch (intent .getAction ()) {
753
+ case TERMUX_ACTIVITY .ACTION_REQUEST_PERMISSIONS :
754
+ Logger .logDebug (LOG_TAG , "Received intent to request storage permissions" );
755
+ if (ensureStoragePermissionGranted ())
756
+ TermuxInstaller .setupStorageSymlinks (TermuxActivity .this );
757
+ return ;
758
+ case TERMUX_ACTIVITY .ACTION_RELOAD_STYLE :
759
+ Logger .logDebug (LOG_TAG , "Received intent to reload styling" );
760
+ reloadTermuxActivityStyling ();
761
+ return ;
762
+ default :
733
763
}
764
+ }
765
+ }
766
+ }
734
767
735
- if (mTermuxTerminalSessionClient != null ) {
736
- mTermuxTerminalSessionClient .checkForFontAndColors ();
737
- }
768
+ private void reloadTermuxActivityStyling () {
769
+ if (mTermuxTerminalSessionClient != null ) {
770
+ mTermuxTerminalSessionClient .checkForFontAndColors ();
771
+ }
738
772
739
- if (mProperties != null ) {
740
- mProperties .loadTermuxPropertiesFromDisk ();
773
+ if (mProperties != null ) {
774
+ mProperties .loadTermuxPropertiesFromDisk ();
741
775
742
- if (mExtraKeysView != null ) {
743
- mExtraKeysView .reload (mProperties .getExtraKeysInfo ());
744
- }
745
- }
776
+ if (mExtraKeysView != null ) {
777
+ mExtraKeysView .reload (mProperties .getExtraKeysInfo ());
778
+ }
779
+ }
746
780
747
- setTerminalToolbarHeight ();
781
+ setTerminalToolbarHeight ();
748
782
749
- setSoftKeyboardState ();
783
+ setSoftKeyboardState ();
750
784
751
- // To change the activity and drawer theme, activity needs to be recreated.
752
- // But this will destroy the activity, and will call the onCreate() again.
753
- // We need to investigate if enabling this is wise, since all stored variables and
754
- // views will be destroyed and bindService() will be called again. Extra keys input
755
- // text will we restored since that has already been implemented. Terminal sessions
756
- // and transcripts are also already preserved. Theme does change properly too.
757
- // TermuxActivity.this.recreate();
758
- }
759
- }
785
+ // To change the activity and drawer theme, activity needs to be recreated.
786
+ // But this will destroy the activity, and will call the onCreate() again.
787
+ // We need to investigate if enabling this is wise, since all stored variables and
788
+ // views will be destroyed and bindService() will be called again. Extra keys input
789
+ // text will we restored since that has already been implemented. Terminal sessions
790
+ // and transcripts are also already preserved. Theme does change properly too.
791
+ // TermuxActivity.this.recreate();
760
792
}
761
793
762
794
0 commit comments