aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context/App.kt
diff options
context:
space:
mode:
authorpacien2018-08-07 00:19:57 +0200
committerpacien2018-08-07 00:19:57 +0200
commitdbba24ef009e5fa9ad428b0ba426b41672fa6b2e (patch)
treec7ff813d7ca0821b4866beeb59f7539cbff6bdca /app/src/main/java/org/pacien/tincapp/context/App.kt
parent123d40dbf3921c5b39938f3b18460eb4a11bf3d6 (diff)
downloadtincapp-dbba24ef009e5fa9ad428b0ba426b41672fa6b2e.tar.gz
Rename source directory
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.kt85
1 files changed, 0 insertions, 85 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
deleted file mode 100644
index 359cd23..0000000
--- a/app/src/main/java/org/pacien/tincapp/context/App.kt
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.context
20
21import android.app.Application
22import android.content.Context
23import android.content.Intent
24import android.net.Uri
25import android.os.Build
26import android.os.Handler
27import android.support.annotation.StringRes
28import org.pacien.tincapp.BuildConfig
29import org.pacien.tincapp.R
30import org.slf4j.LoggerFactory
31import java.io.File
32
33/**
34 * @author pacien
35 */
36class App : Application() {
37 override fun onCreate() {
38 super.onCreate()
39 appContext = applicationContext
40 handler = Handler()
41 AppLogger.configure()
42 setupCrashHandler()
43
44 val logger = LoggerFactory.getLogger(this.javaClass)
45 logger.info("Starting tinc app {} ({} build), running on {} ({})",
46 BuildConfig.VERSION_NAME, BuildConfig.BUILD_TYPE, Build.VERSION.CODENAME, Build.VERSION.RELEASE)
47 }
48
49 private fun setupCrashHandler() {
50 val logger = LoggerFactory.getLogger(this.javaClass)
51 val systemCrashHandler = Thread.getDefaultUncaughtExceptionHandler()
52 val crashRecorder = CrashRecorder(logger, systemCrashHandler)
53 Thread.setDefaultUncaughtExceptionHandler(crashRecorder)
54 }
55
56 companion object {
57 private var appContext: Context? = null
58 private var handler: Handler? = null
59
60 val notificationManager: AppNotificationManager by lazy { AppNotificationManager(appContext!!) }
61
62 fun getContext() = appContext!!
63 fun getResources() = getContext().resources!!
64
65 fun alert(@StringRes title: Int, msg: String, manualLink: String? = null) =
66 notificationManager.notifyError(appContext!!.getString(title), msg, manualLink)
67
68 fun openURL(url: String) {
69 val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
70 val chooser = Intent.createChooser(intent, getResources().getString(R.string.action_open_web_page))
71 appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
72 }
73
74 fun sendMail(recipient: String, subject: String, body: String? = null, attachment: File? = null) {
75 val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
76 .putExtra(Intent.EXTRA_EMAIL, arrayOf(recipient))
77 .putExtra(Intent.EXTRA_SUBJECT, subject)
78 .apply { if (body != null) putExtra(Intent.EXTRA_TEXT, body) }
79 .apply { if (attachment != null) putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment)) }
80
81 val chooser = Intent.createChooser(intent, getResources().getString(R.string.action_send_email))
82 appContext?.startActivity(chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
83 }
84 }
85}