summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/preference
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-03-20 20:45:47 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-20 22:22:56 -0600
commit55849cad65b699ff16886085db996fc6ce3dec3e (patch)
treefb5e9390feaf36bb59a1cae84045b8c9f86e40c5 /ui/src/main/java/com/wireguard/android/preference
parentedb76af8206d4c9f011087d9b5811fdc74fb764c (diff)
Replace PermissionRequestCallback with direct methods
These are much cleaner in Kotlin code. Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/preference')
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.kt16
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt19
2 files changed, 12 insertions, 23 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.kt b/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.kt
index e49de5e2..1b907530 100644
--- a/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.kt
+++ b/ui/src/main/java/com/wireguard/android/preference/LogExporterPreference.kt
@@ -13,7 +13,6 @@ import androidx.preference.Preference
import com.google.android.material.snackbar.Snackbar
import com.wireguard.android.Application
import com.wireguard.android.R
-import com.wireguard.android.activity.SettingsActivity
import com.wireguard.android.util.DownloadsFileSaver
import com.wireguard.android.util.ErrorMessages
import com.wireguard.android.util.FragmentUtils
@@ -82,15 +81,12 @@ class LogExporterPreference(context: Context, attrs: AttributeSet?) : Preference
override fun onClick() {
FragmentUtils.getPrefActivity(this)
- .ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
- object: SettingsActivity.PermissionRequestCallback {
- override fun done(permissions: Array<String>, grantResults: IntArray) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- isEnabled = false
- exportLog()
- }
- }
- })
+ .ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults ->
+ if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ isEnabled = false
+ exportLog()
+ }
+ }
}
companion object {
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 db1b7735..0c00a3ef 100644
--- a/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt
+++ b/ui/src/main/java/com/wireguard/android/preference/ZipExporterPreference.kt
@@ -13,16 +13,12 @@ import androidx.preference.Preference
import com.google.android.material.snackbar.Snackbar
import com.wireguard.android.Application
import com.wireguard.android.R
-import com.wireguard.android.activity.SettingsActivity
import com.wireguard.android.model.ObservableTunnel
import com.wireguard.android.util.DownloadsFileSaver
import com.wireguard.android.util.ErrorMessages
import com.wireguard.android.util.FragmentUtils
-import com.wireguard.android.util.ObservableSortedKeyedList
-import com.wireguard.config.Config
import java9.util.concurrent.CompletableFuture
import java.nio.charset.StandardCharsets
-import java.util.ArrayList
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
@@ -86,15 +82,12 @@ class ZipExporterPreference(context: Context, attrs: AttributeSet?) : Preference
override fun onClick() {
FragmentUtils.getPrefActivity(this)
- .ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
- object : SettingsActivity.PermissionRequestCallback {
- override fun done(permissions: Array<String>, grantResults: IntArray) {
- if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- isEnabled = false
- exportZip()
- }
- }
- })
+ .ensurePermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { _, grantResults ->
+ if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ isEnabled = false
+ exportZip()
+ }
+ }
}
companion object {