// Declare the class variables.
private lateinit var appBar: ActionBar
+ private lateinit var blocklistHelper: BlocklistHelper
private lateinit var bookmarksCursorAdapter: CursorAdapter
private lateinit var bookmarksListView: ListView
private lateinit var bookmarksDrawerPinnedImageView: ImageView
private lateinit var bookmarksTitleTextView: TextView
private lateinit var coordinatorLayout: CoordinatorLayout
private lateinit var cookieManager: CookieManager
+ private lateinit var domainsSettingsSet: MutableSet<String>
private lateinit var drawerLayout: DrawerLayout
private lateinit var easyList: ArrayList<List<Array<String>>>
private lateinit var easyPrivacy: ArrayList<List<Array<String>>>
// Reset the reapply domain settings on restart flag.
reapplyDomainSettingsOnRestart = false
+ // Update the domains settings set.
+ updateDomainsSettingsSet()
+
// Reapply the domain settings for each tab.
for (i in 0 until webViewPagerAdapter!!.count) {
// Get the WebView tab fragment.
}
// Close the bookmarks cursor if it exists.
- if (bookmarksCursor != null) {
- bookmarksCursor!!.close()
- }
+ bookmarksCursor?.close()
- // Close the databases database if it exists.
+ // Close the databases if they exist.
bookmarksDatabaseHelper?.close()
domainsDatabaseHelper?.close()
// Destroy the bare WebView.
bareWebView.destroy()
+
+ // Update the domains settings set.
+ updateDomainsSettingsSet()
+
+ // Instantiate the blocklist helper.
+ blocklistHelper = BlocklistHelper()
}
private fun applyAppSettings() {
}
}
- // Get a full domain name cursor.
- val domainNameCursor = domainsDatabaseHelper!!.domainNameCursorOrderedByDomain
-
- // Initialize the domain settings set.
- val domainSettingsSet: MutableSet<String> = HashSet()
-
- // Get the domain name column index.
- val domainNameColumnIndex = domainNameCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.DOMAIN_NAME)
-
- // Populate the domain settings set.
- for (i in 0 until domainNameCursor.count) {
- // Move the domains cursor to the current row.
- domainNameCursor.moveToPosition(i)
-
- // Store the domain name in the domain settings set.
- domainSettingsSet.add(domainNameCursor.getString(domainNameColumnIndex))
- }
-
- // Close the domain name cursor.
- domainNameCursor.close()
-
// Initialize the domain name in database variable.
var domainNameInDatabase: String? = null
// Check the hostname against the domain settings set.
- if (domainSettingsSet.contains(newHostName)) { // The hostname is contained in the domain settings set.
+ if (domainsSettingsSet.contains(newHostName)) { // The hostname is contained in the domain settings set.
// Record the domain name in the database.
domainNameInDatabase = newHostName
// Check all the subdomains of the host name against wildcard domains in the domain cursor.
while (!nestedScrollWebView.domainSettingsApplied && newHostName!!.contains(".")) { // Stop checking if domain settings are already applied or there are no more `.` in the hostname.
- if (domainSettingsSet.contains("*.$newHostName")) { // Check the host name prepended by `*.`.
+ if (domainsSettingsSet.contains("*.$newHostName")) { // Check the host name prepended by `*.`.
// Set the domain settings applied tracker to true.
nestedScrollWebView.domainSettingsApplied = true
}
private fun clearAndExit() {
- // Close the cursor and databases. TODO: Also domains cursor.
+ // Close the bookmarks cursor if it exists.
bookmarksCursor?.close()
+
+ // Close the databases helpers if they exist.
bookmarksDatabaseHelper?.close()
domainsDatabaseHelper?.close()
// Get a handle for the input method manager.
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
- // Instantiate the blocklist helper. TODO. Make a class instance.
- val blocklistHelper = BlocklistHelper()
-
// Set the app bar scrolling.
nestedScrollWebView.isNestedScrollingEnabled = scrollAppBar
}
}
}
+
+ private fun updateDomainsSettingsSet() {
+ // Reset the domains settings set.
+ domainsSettingsSet = HashSet()
+
+ // Get a domains cursor.
+ val domainsCursor = domainsDatabaseHelper!!.domainNameCursorOrderedByDomain
+
+ // Get the current count of domains.
+ val domainsCount = domainsCursor.count
+
+ // Get the domain name column index.
+ val domainNameColumnIndex = domainsCursor.getColumnIndexOrThrow(DomainsDatabaseHelper.DOMAIN_NAME)
+
+ // Populate the domain settings set.
+ for (i in 0 until domainsCount) {
+ // Move the domains cursor to the current row.
+ domainsCursor.moveToPosition(i)
+
+ // Store the domain name in the domain settings set.
+ domainsSettingsSet.add(domainsCursor.getString(domainNameColumnIndex))
+ }
+
+ // Close the domains cursor.
+ domainsCursor.close()
+ }
}