diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context/App.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/context/App.kt | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/context/App.kt b/app/src/main/java/org/pacien/tincapp/context/App.kt index 7aaa3d0..0a365d0 100644 --- a/app/src/main/java/org/pacien/tincapp/context/App.kt +++ b/app/src/main/java/org/pacien/tincapp/context/App.kt | |||
@@ -14,30 +14,30 @@ import org.pacien.tincapp.R | |||
14 | */ | 14 | */ |
15 | class App : Application() { | 15 | class App : Application() { |
16 | 16 | ||
17 | override fun onCreate() { | 17 | override fun onCreate() { |
18 | super.onCreate() | 18 | super.onCreate() |
19 | appContext = applicationContext | 19 | appContext = applicationContext |
20 | } | 20 | } |
21 | 21 | ||
22 | companion object { | 22 | companion object { |
23 | 23 | ||
24 | private var appContext: Context? = null | 24 | private var appContext: Context? = null |
25 | 25 | ||
26 | fun getContext() = appContext!! | 26 | fun getContext() = appContext!! |
27 | fun getResources() = getContext().resources!! | 27 | fun getResources() = getContext().resources!! |
28 | 28 | ||
29 | fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) = | 29 | fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) = |
30 | AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) | 30 | AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) |
31 | .setTitle(title).setMessage(msg) | 31 | .setTitle(title).setMessage(msg) |
32 | .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } | 32 | .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } |
33 | .setPositiveButton(R.string.action_close, dismissAction) | 33 | .setPositiveButton(R.string.action_close, dismissAction) |
34 | .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() | 34 | .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() |
35 | 35 | ||
36 | fun openURL(url: String) = | 36 | fun openURL(url: String) = |
37 | appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | 37 | appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) |
38 | 38 | ||
39 | val dismissAction = { _: Any, _: Any -> /* nop */ } | 39 | val dismissAction = { _: Any, _: Any -> /* nop */ } |
40 | 40 | ||
41 | } | 41 | } |
42 | 42 | ||
43 | } | 43 | } |