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 | 6 |
1 files changed, 5 insertions, 1 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 9fb910b..4a4a475 100644 --- a/app/src/main/java/org/pacien/tincapp/context/App.kt +++ b/app/src/main/java/org/pacien/tincapp/context/App.kt | |||
@@ -4,6 +4,7 @@ import android.app.Application | |||
4 | import android.content.Context | 4 | import android.content.Context |
5 | import android.content.Intent | 5 | import android.content.Intent |
6 | import android.net.Uri | 6 | import android.net.Uri |
7 | import android.os.Handler | ||
7 | import android.support.annotation.StringRes | 8 | import android.support.annotation.StringRes |
8 | import android.support.v7.app.AlertDialog | 9 | import android.support.v7.app.AlertDialog |
9 | import android.view.WindowManager | 10 | import android.view.WindowManager |
@@ -16,20 +17,23 @@ class App : Application() { | |||
16 | override fun onCreate() { | 17 | override fun onCreate() { |
17 | super.onCreate() | 18 | super.onCreate() |
18 | appContext = applicationContext | 19 | appContext = applicationContext |
20 | handler = Handler() | ||
19 | } | 21 | } |
20 | 22 | ||
21 | companion object { | 23 | companion object { |
22 | private var appContext: Context? = null | 24 | private var appContext: Context? = null |
25 | private var handler: Handler? = null | ||
23 | 26 | ||
24 | fun getContext() = appContext!! | 27 | fun getContext() = appContext!! |
25 | fun getResources() = getContext().resources!! | 28 | fun getResources() = getContext().resources!! |
26 | 29 | ||
27 | fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) = | 30 | fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) = handler!!.post { |
28 | AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) | 31 | AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Dialog) |
29 | .setTitle(title).setMessage(msg) | 32 | .setTitle(title).setMessage(msg) |
30 | .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } | 33 | .apply { if (manualLink != null) setNeutralButton(R.string.action_open_manual) { _, _ -> openURL(manualLink) } } |
31 | .setPositiveButton(R.string.action_close, { _, _ -> Unit }) | 34 | .setPositiveButton(R.string.action_close, { _, _ -> Unit }) |
32 | .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() | 35 | .create().apply { window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR) }.show() |
36 | } | ||
33 | 37 | ||
34 | fun openURL(url: String) = | 38 | fun openURL(url: String) = |
35 | appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) | 39 | appContext?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) |