aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/main/java/com/wireguard/android/util
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/util')
-rw-r--r--ui/src/main/java/com/wireguard/android/util/Extensions.kt10
-rw-r--r--ui/src/main/java/com/wireguard/android/util/FragmentUtils.kt21
2 files changed, 10 insertions, 21 deletions
diff --git a/ui/src/main/java/com/wireguard/android/util/Extensions.kt b/ui/src/main/java/com/wireguard/android/util/Extensions.kt
index a705401..9106ec7 100644
--- a/ui/src/main/java/com/wireguard/android/util/Extensions.kt
+++ b/ui/src/main/java/com/wireguard/android/util/Extensions.kt
@@ -9,6 +9,10 @@ import android.content.Context
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.fragment.app.Fragment
+import androidx.lifecycle.lifecycleScope
+import androidx.preference.Preference
+import com.wireguard.android.activity.SettingsActivity
+import kotlinx.coroutines.CoroutineScope
fun Context.resolveAttribute(@AttrRes attrRes: Int): Int {
val typedValue = TypedValue()
@@ -19,3 +23,9 @@ fun Context.resolveAttribute(@AttrRes attrRes: Int): Int {
fun Fragment.requireTargetFragment(): Fragment {
return requireNotNull(targetFragment) { "A target fragment should always be set for $this" }
}
+
+val Preference.activity: SettingsActivity
+ get() = if (this.context is SettingsActivity) this.context as SettingsActivity else throw IllegalStateException("Failed to resolve SettingsActivity")
+
+val Preference.lifecycleScope: CoroutineScope
+ get() = this.activity.lifecycleScope
diff --git a/ui/src/main/java/com/wireguard/android/util/FragmentUtils.kt b/ui/src/main/java/com/wireguard/android/util/FragmentUtils.kt
deleted file mode 100644
index 90e7ab0..0000000
--- a/ui/src/main/java/com/wireguard/android/util/FragmentUtils.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
- * SPDX-License-Identifier: Apache-2.0
- */
-package com.wireguard.android.util
-
-import android.view.ContextThemeWrapper
-import androidx.preference.Preference
-import com.wireguard.android.activity.SettingsActivity
-
-object FragmentUtils {
- fun getPrefActivity(preference: Preference): SettingsActivity {
- val context = preference.context
- if (context is ContextThemeWrapper) {
- if (context is SettingsActivity) {
- return context
- }
- }
- throw IllegalStateException("Failed to resolve SettingsActivity")
- }
-}