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 | 21 |
1 files changed, 21 insertions, 0 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 4b7e44e..7aaa3d0 100644 --- a/app/src/main/java/org/pacien/tincapp/context/App.kt +++ b/app/src/main/java/org/pacien/tincapp/context/App.kt | |||
@@ -2,6 +2,12 @@ package org.pacien.tincapp.context | |||
2 | 2 | ||
3 | import android.app.Application | 3 | import android.app.Application |
4 | import android.content.Context | 4 | import android.content.Context |
5 | import android.content.Intent | ||
6 | import android.net.Uri | ||
7 | import android.support.annotation.StringRes | ||
8 | import android.support.v7.app.AlertDialog | ||
9 | import android.view.WindowManager | ||
10 | import org.pacien.tincapp.R | ||
5 | 11 | ||
6 | /** | 12 | /** |
7 | * @author pacien | 13 | * @author pacien |
@@ -14,9 +20,24 @@ class App : Application() { | |||
14 | } | 20 | } |
15 | 21 | ||
16 | companion object { | 22 | companion object { |
23 | |||
17 | private var appContext: Context? = null | 24 | private var appContext: Context? = null |
25 | |||
18 | fun getContext() = appContext!! | 26 | fun getContext() = appContext!! |
19 | fun getResources() = getContext().resources!! | 27 | fun getResources() = getContext().resources!! |
28 | |||
29 | fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) = | ||
30 | AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) | ||
31 | .setTitle(title).setMessage(msg) | ||
32 | .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } | ||
33 | .setPositiveButton(R.string.action_close, dismissAction) | ||
34 | .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() | ||
35 | |||
36 | fun openURL(url: String) = | ||
37 | appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | ||
38 | |||
39 | val dismissAction = { _: Any, _: Any -> /* nop */ } | ||
40 | |||
20 | } | 41 | } |
21 | 42 | ||
22 | } | 43 | } |