From a31f0cf788d98d041943d0c36c7209b25a1356df Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 2 Oct 2020 12:11:48 +0200 Subject: DownloadsFileSaver: initialize callback in constructor, not on the fly Signed-off-by: Jason A. Donenfeld --- .../java/com/wireguard/android/preference/ZipExporterPreference.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui/src/main/java/com/wireguard/android/preference') diff --git a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt index aaea7703..b8a1da75 100644 --- a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt @@ -32,6 +32,8 @@ import java.util.zip.ZipOutputStream */ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) { private var exportedFilePath: String? = null + private val downloadsFileSaver = DownloadsFileSaver(activity) + private fun exportZip() { lifecycleScope.launch { val tunnels = Application.getTunnelManager().getTunnels() @@ -41,7 +43,7 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference if (configs.isEmpty()) { throw IllegalArgumentException(context.getString(R.string.no_tunnels_error)) } - val outputFile = DownloadsFileSaver.save(activity, "wireguard-export.zip", "application/zip", true) + val outputFile = downloadsFileSaver.save("wireguard-export.zip", "application/zip", true) if (outputFile == null) { withContext(Dispatchers.Main.immediate) { isEnabled = true -- cgit v1.2.3