// `reapplyDomainSettingsOnRestart` is used in `onCreate()`, `onOptionsItemSelected()`, `onNavigationItemSelected()`, `onRestart()`, and `onAddDomain()`, .
private boolean reapplyDomainSettingsOnRestart;
+ // `reapplyAppSettingsOnRestart` is used in `onNavigationItemSelected()` and `onRestart()`.
+ private boolean reapplyAppSettingsOnRestert;
+
// `currentDomainName` is used in `onCreate()`, `onOptionsItemSelected()`, `onNavigationItemSelected()`, `onAddDomain()`, and `applyDomainSettings()`.
private String currentDomainName;
return true;
} else { // Load the URL in Privacy Browser.
// Apply the domain settings for the new URL.
- applyDomainSettings(url);
+ applyDomainSettings(url, true);
// Returning `false` causes the current `WebView` to handle the URL and prevents it from adding redirects to the history list.
return false;
// Apply any custom domain settings if the URL was loaded by navigating history.
if (navigatingHistory) {
- applyDomainSettings(url);
+ applyDomainSettings(url, true);
}
// Set `urlIsLoading` to `true`, so that redirects while loading do not trigger changes in the user agent, which forces another reload of the existing page.
@Override
public void onPageFinished(WebView view, String url) {
// Flush any cookies to persistent storage. `CookieManager` has become very lazy about flushing cookies in recent versions.
- if (Build.VERSION.SDK_INT >= 21) {
+ if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
cookieManager.flush();
}
inputMethodManager.showSoftInput(urlTextBox, 0);
// Apply the domain settings. This clears any settings from the previous domain.
- applyDomainSettings(formattedUrlString);
+ applyDomainSettings(formattedUrlString, true);
} else { // `WebView` has loaded a webpage.
// Set `formattedUrlString`.
formattedUrlString = url;
// Sets the new intent as the activity intent, so that any future `getIntent()`s pick up this one instead of creating a new activity.
setIntent(intent);
+ // Check to see if the intent contains a new URL.
if (intent.getData() != null) {
// Get the intent data and convert it to a string.
final Uri intentUriData = intent.getData();
formattedUrlString = intentUriData.toString();
- }
- // Close the navigation drawer if it is open.
- if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
- drawerLayout.closeDrawer(GravityCompat.START);
- }
+ // Load the website.
+ loadUrl(formattedUrlString);
- // Load the website.
- loadUrl(formattedUrlString);
+ // Close the navigation drawer if it is open.
+ if (drawerLayout.isDrawerVisible(GravityCompat.START)) {
+ drawerLayout.closeDrawer(GravityCompat.START);
+ }
- // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it.
- mainWebView.requestFocus();
+ // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it.
+ mainWebView.requestFocus();
+ }
}
@Override
// Run the default commands.
super.onRestart();
- // Apply the app settings, which may have been changed in `SettingsActivity`.
- applyAppSettings();
+ // Apply the app settings if returning from the Settings activity..
+ if (reapplyAppSettingsOnRestert) {
+ // Apply the app settings.
+ applyAppSettings();
- // Apply the domain settings if returning from the Domains Activity.
- if (reapplyDomainSettingsOnRestart) {
- // Reset `reapplyDomainSettingsOnRestart`.
- reapplyDomainSettingsOnRestart = false;
-
- // Reapply the domain settings.
- applyDomainSettings(formattedUrlString);
- }
+ // Reload the webpage if displaying of images has been disabled in the Settings activity.
+ if (reloadOnRestart) {
+ // Reload `mainWebView`.
+ mainWebView.reload();
- // Update the privacy icon. `true` runs `invalidateOptionsMenu` as the last step.
- updatePrivacyIcons(true);
+ // Reset `reloadOnRestartBoolean`.
+ reloadOnRestart = false;
+ }
- // Set the display webpage images mode.
- setDisplayWebpageImages();
+ // Reset the return from settings flag.
+ reapplyAppSettingsOnRestert = false;
+ }
- // Reload the webpage if displaying of images has been disabled in `SettingsFragment`.
- if (reloadOnRestart) {
- // Reload `mainWebView`.
- mainWebView.reload();
+ // Apply the domain settings if returning from the Domains activity.
+ if (reapplyDomainSettingsOnRestart) {
+ // Reapply the domain settings.
+ applyDomainSettings(formattedUrlString, false);
- // Reset `reloadOnRestartBoolean`.
- reloadOnRestart = false;
+ // Reset `reapplyDomainSettingsOnRestart`.
+ reapplyDomainSettingsOnRestart = false;
}
// Load the URL on restart to apply changes to night mode.
loadUrlOnRestart = false;
}
- //
+ // Update the bookmarks drawer if returning from the Bookmarks activity.
if (restartFromBookmarksActivity) {
// Close the bookmarks drawer.
drawerLayout.closeDrawer(GravityCompat.END);
// Reset `restartFromBookmarksActivity`.
restartFromBookmarksActivity = false;
}
+
+ // Update the privacy icon. `true` runs `invalidateOptionsMenu` as the last step. This can be important if the screen was rotated.
+ updatePrivacyIcons(true);
}
// `onResume()` runs after `onStart()`, which runs after `onCreate()` and `onRestart()`.
break;
case R.id.domains:
- // Reapply the domain settings on returning to `MainWebViewActivity`.
+ // Set the flag to reapply the domain settings on restart when returning from Domain Settings.
reapplyDomainSettingsOnRestart = true;
currentDomainName = "";
break;
case R.id.settings:
- // Reapply the domain settings on returning to `MainWebViewActivity`.
+ // Set the flag to reapply app settings on restart when returning from Settings.
+ reapplyAppSettingsOnRestert = true;
+
+ // Set the flag to reapply the domain settings on restart when returning from Settings.
reapplyDomainSettingsOnRestart = true;
currentDomainName = "";
private void loadUrl(String url) {
// Apply any custom domain settings.
- applyDomainSettings(url);
+ applyDomainSettings(url, true);
// Load the URL.
mainWebView.loadUrl(url, customHeaders);
}
}
- // We have to use the deprecated `.getDrawable()` until the minimum API >= 21.
+ //
+ // The deprecated `.getDrawable()` must be used until the minimum API >= 21.
@SuppressWarnings("deprecation")
- private void applyDomainSettings(String url) {
+ private void applyDomainSettings(String url, boolean resetFavoriteIcon) {
// Reset `navigatingHistory`.
navigatingHistory = false;
// Reset `ignorePinnedSslCertificate`.
ignorePinnedSslCertificate = false;
- // Reset `favoriteIconBitmap` and display it in the `appbar`.
- favoriteIconBitmap = favoriteIconDefaultBitmap;
- favoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(favoriteIconBitmap, 64, 64, true));
+ // Reset the favorite icon if specified.
+ if (resetFavoriteIcon) {
+ favoriteIconBitmap = favoriteIconDefaultBitmap;
+ favoriteIconImageView.setImageBitmap(Bitmap.createScaledBitmap(favoriteIconBitmap, 64, 64, true));
+ }
// Initialize the database handler. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`.
// The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.