- override fun afterTextChanged(editable: Editable) {
- // Cancel the get URL size AsyncTask if it is running.
- if (getUrlSize != null) {
- getUrlSize!!.cancel(true)
+ override fun afterTextChanged(editable: Editable?) {
+ // Get the contents of the edit texts.
+ val urlToSave = urlEditText.text.toString()
+ val fileName = fileNameEditText.text.toString()
+
+ // Determine if this is a blob URL.
+ val blobUrl = urlToSave.startsWith("blob:")
+
+ // Set the display status of the blob warning.
+ if (blobUrl)
+ blobUrlWarningTextView.visibility = View.VISIBLE
+ else
+ blobUrlWarningTextView.visibility = View.GONE
+
+ // Enable the save button if the edit texts are populated and this isn't a blob URL.
+ saveButton.isEnabled = urlToSave.isNotBlank() && fileName.isNotBlank() && !blobUrl
+
+ // Determine if this is a data URL.
+ val dataUrl = urlToSave.startsWith("data:")
+
+ // Only process the URL if it is not a data URL.
+ if (!dataUrl) {
+ CoroutineScope(Dispatchers.Main).launch {
+ // Create a URL size string.
+ var fileNameAndSize: Pair<String, String>
+
+ // Get the URL size on the IO thread.
+ withContext(Dispatchers.IO) {
+ // Get the updated file name and size.
+ fileNameAndSize = UrlHelper.getNameAndSize(requireContext(), urlToSave, userAgentString, cookiesEnabled)
+
+ // Save the updated file name.
+ fileNameString = fileNameAndSize.first
+ }
+
+ // Display the updated file size.
+ fileSizeTextView.text = fileNameAndSize.second
+ }