X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FAboutVersionFragment.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FAboutVersionFragment.kt;h=0078fcc1fab5039c533b07a05064234b4da77b3b;hp=c4c522741f892e56f80ee0930bc4a7a8b9856d14;hb=83fa40449d1160836c4066c99fe3c141d982917a;hpb=2bd8b7edef80b4b10cb809a198b4624c6c740c86 diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt index c4c52274..0078fcc1 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutVersionFragment.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2022 Soren Stoutner . + * Copyright 2016-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -55,6 +55,11 @@ import com.stoutner.privacybrowser.R import com.stoutner.privacybrowser.BuildConfig import com.stoutner.privacybrowser.asynctasks.SaveAboutVersionImage +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + import java.io.ByteArrayInputStream import java.io.InputStream import java.lang.Exception @@ -165,11 +170,16 @@ class AboutVersionFragment : Fragment() { // Open an output stream. val outputStream = requireActivity().contentResolver.openOutputStream(fileUri)!! - // Write the about version string to the output stream. - outputStream.write(aboutVersionString.toByteArray(StandardCharsets.UTF_8)) + // Save about version using a coroutine with Dispatchers.IO. + CoroutineScope(Dispatchers.Main).launch { + withContext(Dispatchers.IO) { + // Write the about version string to the output stream. + outputStream.write(aboutVersionString.toByteArray(StandardCharsets.UTF_8)) - // Close the output stream. - outputStream.close() + // Close the output stream. + outputStream.close() + } + } // Initialize the file name string from the file URI last path segment. var fileNameString = fileUri.lastPathSegment @@ -895,4 +905,4 @@ class AboutVersionFragment : Fragment() { // Return the string. return aboutVersionStringBuilder.toString() } -} \ No newline at end of file +}