7777import androidx .appcompat .widget .Toolbar ;
7878import androidx .core .app .ActivityCompat ;
7979import androidx .core .content .ContextCompat ;
80+ import androidx .core .graphics .Insets ;
8081import androidx .core .splashscreen .SplashScreen ;
8182import androidx .core .view .GravityCompat ;
83+ import androidx .core .view .ViewCompat ;
84+ import androidx .core .view .WindowCompat ;
85+ import androidx .core .view .WindowInsetsCompat ;
8286import androidx .drawerlayout .widget .DrawerLayout ;
8387import androidx .swiperefreshlayout .widget .SwipeRefreshLayout ;
88+
89+ import com .google .android .material .appbar .MaterialToolbar ;
8490import com .google .android .material .navigation .NavigationView ;
8591
8692import java .util .Arrays ;
@@ -112,20 +118,21 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
112118 @ SuppressLint ({"SetJavaScriptEnabled" , "WrongViewCast" , "JavascriptInterface" })
113119 @ Override
114120 protected void onCreate (Bundle savedInstanceState ) {
121+ // Secure the app on startup if biometric or auth is forced on launch
115122 getWindow ().setFlags (WindowManager .LayoutParams .FLAG_SECURE , WindowManager .LayoutParams .FLAG_SECURE );
116123
117- if (SWVContext .ASWV_LAYOUT == 0 || (SWVContext .ASWV_LAYOUT == 1 && !SWVContext .ASWP_DRAWER_HEADER )) {
118- setTheme (R .style .Theme_SmartWebView_Fullscreen );
119- }
120-
121- final SplashScreen splashScreen = androidx .core .splashscreen .SplashScreen .installSplashScreen (this );
124+ // Enable edge-to-edge display
125+ WindowCompat .setDecorFitsSystemWindows (getWindow (), false );
122126
123127 super .onCreate (savedInstanceState );
124128
129+ // Handle splash screen
130+ final SplashScreen splashScreen = androidx .core .splashscreen .SplashScreen .installSplashScreen (this );
131+
125132 // If extending splash is enabled, set up a listener
126133 // Keep the splash screen on-screen if the extend feature is enabled
134+ final View content = findViewById (android .R .id .content );
127135 if (SWVContext .ASWP_EXTEND_SPLASH ) {
128- final View content = findViewById (android .R .id .content );
129136 content .getViewTreeObserver ().addOnPreDrawListener (
130137 new ViewTreeObserver .OnPreDrawListener () {
131138 @ Override
@@ -225,68 +232,72 @@ public boolean onPreDraw() {
225232 initializeWebView ();
226233
227234 // Setup features and handle intents
228- setupFeatures ();
229- handleIncomingIntents ();
235+ if (savedInstanceState == null ) {
236+ setupFeatures ();
237+ handleIncomingIntents ();
238+ }
230239
231240 // Debug mode logging
232241 if (SWVContext .SWV_DEBUGMODE ){
233242 Log .d (TAG , "URL: " + SWVContext .CURR_URL +"DEVICE INFO: " + Arrays .toString (fns .get_info (this )));
234243 }
244+
245+ ViewCompat .setOnApplyWindowInsetsListener (content , (v , windowInsets ) -> {
246+ // Get the insets for the system bars (status bar, navigation bar)
247+ Insets insets = windowInsets .getInsets (WindowInsetsCompat .Type .systemBars ());
248+
249+ // Apply the insets as padding to the root view.
250+ // This pushes the entire layout down from the status bar and up from the nav bar.
251+ v .setPadding (insets .left , insets .top , insets .right , insets .bottom );
252+
253+ // Return the insets so that other views can also process them if needed.
254+ return windowInsets ;
255+ });
235256 }
236257
237258 /**
238259 * Setup the UI layout based on configuration
239260 */
240261 private void setupLayout () {
241- final SwipeRefreshLayout pullRefresh = findViewById (R .id .pullfresh );
242- // Set content view based on configuration
243262 if (SWVContext .ASWV_LAYOUT == 1 ) {
244263 setContentView (R .layout .drawer_main );
264+ MaterialToolbar toolbar = findViewById (R .id .toolbar ); // Use MaterialToolbar
265+ final SwipeRefreshLayout pullRefresh = findViewById (R .id .pullfresh );
245266
246- Toolbar toolbar = findViewById (R .id .toolbar );
247- setSupportActionBar (toolbar );
248- Objects .requireNonNull (getSupportActionBar ()).setDisplayShowTitleEnabled (false );
249-
250- // Conditionally show or hide the header based on config
251267 if (SWVContext .ASWP_DRAWER_HEADER ) {
252- // Header is enabled: Setup Toolbar and Toggle
253268 findViewById (R .id .app_bar ).setVisibility (View .VISIBLE );
254269 setSupportActionBar (toolbar );
255270 Objects .requireNonNull (getSupportActionBar ()).setDisplayShowTitleEnabled (false );
256271
257272 DrawerLayout drawer = findViewById (R .id .drawer_layout );
258-
259273 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (this , drawer , toolbar , R .string .open , R .string .close ) {
260274 @ Override
261275 public void onDrawerSlide (View drawerView , float slideOffset ) {
262276 super .onDrawerSlide (drawerView , slideOffset );
263- // This is the key part: disable pull-to-refresh while drawer is opening.
264- if (slideOffset > 0 && pullRefresh .isEnabled ()) {
277+ if (pullRefresh != null && slideOffset > 0 && pullRefresh .isEnabled ()) {
265278 pullRefresh .setEnabled (false );
266279 }
267280 }
268281
269282 @ Override
270283 public void onDrawerClosed (View drawerView ) {
271284 super .onDrawerClosed (drawerView );
272- // Re-enable pull-to-refresh only if the feature is globally enabled.
273- if (!pullRefresh .isEnabled () && SWVContext .ASWP_PULLFRESH ) {
285+ if (pullRefresh != null && !pullRefresh .isEnabled () && SWVContext .ASWP_PULLFRESH ) {
274286 pullRefresh .setEnabled (true );
275287 }
276288 }
277289 };
278290 drawer .addDrawerListener (toggle );
279291 toggle .syncState ();
280-
281292 } else {
282- // Header is disabled: Hide the AppBarLayout completely
283293 findViewById (R .id .app_bar ).setVisibility (View .GONE );
284294 }
285295
286296 NavigationView navigationView = findViewById (R .id .nav_view );
287297 navigationView .setNavigationItemSelectedListener (this );
288298
289- // The footer is part of the NavigationView's own view hierarchy.
299+ /*
300+ // Temporarily disabled theme toggle logic
290301 MenuItem switchItem = navigationView.getMenu().findItem(R.id.nav_dark_mode_switch);
291302 SwitchCompat themeSwitch = (SwitchCompat) Objects.requireNonNull(switchItem.getActionView()).findViewById(R.id.drawer_theme_switch);
292303 if (themeSwitch != null) {
@@ -296,21 +307,18 @@ public void onDrawerClosed(View drawerView) {
296307 AppCompatDelegate.setDefaultNightMode(
297308 isChecked ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO
298309 );
310+ recreate();
299311 });
300312 }
313+ */
301314
302315 } else {
303316 setContentView (R .layout .activity_main );
304317 }
305318
306- // Initialize UI components
307319 SWVContext .asw_view = findViewById (R .id .msw_view );
308320 adContainer = findViewById (R .id .msw_ad_container );
309321 SWVContext .print_view = findViewById (R .id .print_view );
310-
311- // Setup window appearance
312- getWindow ().addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
313- getWindow ().setStatusBarColor (ContextCompat .getColor (this , R .color .colorPrimaryDark ));
314322 }
315323
316324 /**
@@ -779,6 +787,9 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
779787 protected void onSaveInstanceState (@ NonNull Bundle outState ) {
780788 super .onSaveInstanceState (outState );
781789 SWVContext .asw_view .saveState (outState );
790+ if (SWVContext .asw_view .getUrl () != null ) {
791+ outState .putString ("swv_last_url" , SWVContext .asw_view .getUrl ());
792+ }
782793 }
783794
784795 @ Override
0 commit comments