X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FSaveUrlCoroutine.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fcoroutines%2FSaveUrlCoroutine.kt;h=f8adc5b0f187862fbd611cab2d373becaad2645e;hp=7ce88146a7ef60501c914829058b2c4ce3dfd73a;hb=e065315a36c804626a7dba38d3edad05e9fdb473;hpb=7a54e6907e74196a4840a2434dd13e2b68a95db4 diff --git a/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveUrlCoroutine.kt b/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveUrlCoroutine.kt index 7ce88146..f8adc5b0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveUrlCoroutine.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/coroutines/SaveUrlCoroutine.kt @@ -22,7 +22,6 @@ package com.stoutner.privacybrowser.coroutines import android.app.Activity import android.content.Context import android.net.Uri -import android.os.Build import android.provider.OpenableColumns import android.util.Base64 import android.webkit.CookieManager @@ -53,26 +52,17 @@ class SaveUrlCoroutine { // Use a coroutine to save the URL. CoroutineScope(Dispatchers.Main).launch { - // Create a file name string. - val fileNameString: String + // Get a cursor from the content resolver. + val contentResolverCursor = activity.contentResolver.query(fileUri, null, null, null)!! - // Query the exact file name if the API >= 26. - if (Build.VERSION.SDK_INT >= 26) { - // Get a cursor from the content resolver. - val contentResolverCursor = activity.contentResolver.query(fileUri, null, null, null)!! + // Move to the first row. + contentResolverCursor.moveToFirst() - // Move to the first row. - contentResolverCursor.moveToFirst() + // Get the file name from the cursor. + val fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) - // Get the file name from the cursor. - fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)) - - // Close the cursor. - contentResolverCursor.close() - } else { - // Use the file URI last path segment as the file name string. - fileNameString = fileUri.lastPathSegment!! - } + // Close the cursor. + contentResolverCursor.close() // Get a handle for the no swipe view pager. val webViewViewPager2 = activity.findViewById(R.id.webview_viewpager2) @@ -155,9 +145,9 @@ class SaveUrlCoroutine { val inputStream: InputStream = BufferedInputStream(httpUrlConnection.inputStream) // Initialize the conversion buffer byte array. - // This is set to a 100,000 bytes so that frequent updating of the snackbar doesn't freeze the interface on download, although `inputStream.read` currently used 8,000 as an upper limit. + // This is set to a 50,000 bytes so that frequent updating of the snackbar doesn't freeze the interface on download, although `inputStream.read` currently uses 8,000 as an upper limit. // - val conversionBufferByteArray = ByteArray(100_000) + val conversionBufferByteArray = ByteArray(50_000) // Initialize the longs. var downloadedBytesCounterLong: Long = 0 @@ -242,4 +232,4 @@ class SaveUrlCoroutine { } } } -} \ No newline at end of file +}