]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/helpers/UrlHelper.kt
Fix a crash on restart by a new intent. https://redmine.stoutner.com/issues/981
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / helpers / UrlHelper.kt
index 68a760d23eb3d6df99129c80ca2487675ef7e61f..14e299ceff50385a89d94321a4aafc5c4dfca46e 100644 (file)
@@ -196,73 +196,6 @@ object UrlHelper {
         return Pair(fileNameString, formattedFileSize)
     }
 
-    /*  This entire method might not be needed.
-    fun getSize(context: Context, url: URL, userAgent: String, cookiesEnabled: Boolean): String {
-        // Initialize the formatted file size string.
-        var formattedFileSize = context.getString(R.string.unknown_size)
-
-        // Because everything relating to requesting data from a webserver can throw errors, the entire section must catch exceptions.
-        try {
-            // Instantiate the proxy helper.
-            val proxyHelper = ProxyHelper()
-
-            // Get the current proxy.
-            val proxy = proxyHelper.getCurrentProxy(context)
-
-            // Open a connection to the URL.  No data is actually sent at this point.
-            val httpUrlConnection = url.openConnection(proxy) as HttpURLConnection
-
-            // Add the user agent to the header property.
-            httpUrlConnection.setRequestProperty("User-Agent", userAgent)
-
-            // Add the cookies if they are enabled.
-            if (cookiesEnabled) {
-                // Get the cookies for the current domain.
-                val cookiesString = CookieManager.getInstance().getCookie(url.toString())
-
-                // Only add the cookies if they are not null.
-                if (cookiesString != null) {
-                    // Add the cookies to the header property.
-                    httpUrlConnection.setRequestProperty("Cookie", cookiesString)
-                }
-            }
-
-            // The actual network request is in a `try` bracket so that `disconnect()` is run in the `finally` section even if an error is encountered in the main block.
-            try {
-                // Get the status code.  This initiates a network connection.
-                val responseCode = httpUrlConnection.responseCode
-
-                // Check the response code.
-                if (responseCode >= 400) {  // The response code is an error message.
-                    // Set the formatted file size to indicate a bad URL.
-                    formattedFileSize = context.getString(R.string.invalid_url)
-                } else {  // The response code is not an error message.
-                    // Get the content length header.
-                    val contentLengthString = httpUrlConnection.getHeaderField("Content-Length")
-
-                    // Only process the content length string if it isn't null.
-                    if (contentLengthString != null) {
-                        // Convert the content length string to a long.
-                        val fileSize = contentLengthString.toLong()
-
-                        // Format the file size.
-                        formattedFileSize = NumberFormat.getInstance().format(fileSize) + " " + context.getString(R.string.bytes)
-                    }
-                }
-            } finally {
-                // Disconnect the HTTP URL connection.
-                httpUrlConnection.disconnect()
-            }
-        } catch (exception: Exception) {
-            // Set the formatted file size to indicate a bad URL.
-            formattedFileSize = context.getString(R.string.invalid_url)
-        }
-
-        // Return the formatted file size.
-        return formattedFileSize
-    }
-    */
-
     @JvmStatic
     fun highlightSyntax(urlEditText: EditText, initialGrayColorSpan: ForegroundColorSpan, finalGrayColorSpan: ForegroundColorSpan, redColorSpan: ForegroundColorSpan) {
         // Get the URL string.