aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/context
diff options
context:
space:
mode:
authorpacien2018-02-10 14:16:15 +0100
committerpacien2018-02-10 14:16:15 +0100
commit87ec3620d2259064831356c2f4000ae591756fd2 (patch)
tree9312da1d357fdd3790d5b80af221653696b23089 /app/src/main/java/org/pacien/tincapp/context
parentd1c39ba87bb32308c2d3a7a749abffeb773541ef (diff)
downloadtincapp-87ec3620d2259064831356c2f4000ae591756fd2.tar.gz
Reformat code
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/context')
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/App.kt36
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppInfo.kt30
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt54
3 files changed, 60 insertions, 60 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 */
15class App : Application() { 15class 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}
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
index 39ef0f1..0f61185 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
@@ -9,23 +9,23 @@ import org.pacien.tincapp.R
9 */ 9 */
10object AppInfo { 10object AppInfo {
11 11
12 fun appVersion(): String = App.getResources().getString( 12 fun appVersion(): String = App.getResources().getString(
13 R.string.info_version_format, 13 R.string.info_version_format,
14 BuildConfig.VERSION_NAME, 14 BuildConfig.VERSION_NAME,
15 BuildConfig.BUILD_TYPE) 15 BuildConfig.BUILD_TYPE)
16 16
17 fun androidVersion(): String = App.getResources().getString( 17 fun androidVersion(): String = App.getResources().getString(
18 R.string.info_running_on_format, 18 R.string.info_running_on_format,
19 Build.VERSION.CODENAME, 19 Build.VERSION.CODENAME,
20 Build.VERSION.RELEASE) 20 Build.VERSION.RELEASE)
21 21
22 fun supportedABIs(): String = App.getResources().getString( 22 fun supportedABIs(): String = App.getResources().getString(
23 R.string.info_supported_abis_format, 23 R.string.info_supported_abis_format,
24 Build.SUPPORTED_ABIS.joinToString(",")) 24 Build.SUPPORTED_ABIS.joinToString(","))
25 25
26 fun all(): String = listOf( 26 fun all(): String = listOf(
27 appVersion(), 27 appVersion(),
28 androidVersion(), 28 androidVersion(),
29 supportedABIs()).joinToString("\n") 29 supportedABIs()).joinToString("\n")
30 30
31} 31}
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
index 005cded..2d5e2e4 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
@@ -11,40 +11,40 @@ import java.io.FileNotFoundException
11 */ 11 */
12object AppPaths { 12object AppPaths {
13 13
14 private val TINCD_BIN = "libtincd.so" 14 private val TINCD_BIN = "libtincd.so"
15 private val TINC_BIN = "libtinc.so" 15 private val TINC_BIN = "libtinc.so"
16 16
17 private val LOGFILE_FORMAT = "tinc.%s.log" 17 private val LOGFILE_FORMAT = "tinc.%s.log"
18 private val PIDFILE_FORMAT = "tinc.%s.pid" 18 private val PIDFILE_FORMAT = "tinc.%s.pid"
19 19
20 private val NET_CONF_FILE = "network.conf" 20 private val NET_CONF_FILE = "network.conf"
21 private val NET_TINC_CONF_FILE = "tinc.conf" 21 private val NET_TINC_CONF_FILE = "tinc.conf"
22 private val NET_HOSTS_DIR = "hosts" 22 private val NET_HOSTS_DIR = "hosts"
23 private val NET_INVITATION_FILE = "invitation-data" 23 private val NET_INVITATION_FILE = "invitation-data"
24 private val NET_DEFAULT_ED25519_PRIVATE_KEY_FILE = "ed25519_key.priv" 24 private val NET_DEFAULT_ED25519_PRIVATE_KEY_FILE = "ed25519_key.priv"
25 private val NET_DEFAULT_RSA_PRIVATE_KEY_FILE = "rsa_key.priv" 25 private val NET_DEFAULT_RSA_PRIVATE_KEY_FILE = "rsa_key.priv"
26 26
27 fun storageAvailable() = 27 fun storageAvailable() =
28 Environment.getExternalStorageState().let { it == Environment.MEDIA_MOUNTED && it != Environment.MEDIA_MOUNTED_READ_ONLY } 28 Environment.getExternalStorageState().let { it == Environment.MEDIA_MOUNTED && it != Environment.MEDIA_MOUNTED_READ_ONLY }
29 29
30 fun cacheDir() = App.getContext().externalCacheDir 30 fun cacheDir() = App.getContext().externalCacheDir
31 fun confDir() = App.getContext().getExternalFilesDir(null) 31 fun confDir() = App.getContext().getExternalFilesDir(null)
32 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir) 32 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir)
33 33
34 fun confDir(netName: String) = File(confDir(), netName) 34 fun confDir(netName: String) = File(confDir(), netName)
35 fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR) 35 fun hostsDir(netName: String) = File(confDir(netName), NET_HOSTS_DIR)
36 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE) 36 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
37 fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE) 37 fun tincConfFile(netName: String) = File(confDir(netName), NET_TINC_CONF_FILE)
38 fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE) 38 fun invitationFile(netName: String) = File(confDir(netName), NET_INVITATION_FILE)
39 fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName)) 39 fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName))
40 fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName)) 40 fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName))
41 41
42 fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) } 42 fun existing(f: File) = f.apply { if (!exists()) throw FileNotFoundException(f.absolutePath) }
43 43
44 fun defaultEd25519PrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_ED25519_PRIVATE_KEY_FILE) 44 fun defaultEd25519PrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_ED25519_PRIVATE_KEY_FILE)
45 fun defaultRsaPrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_RSA_PRIVATE_KEY_FILE) 45 fun defaultRsaPrivateKeyFile(netName: String) = File(confDir(netName), NET_DEFAULT_RSA_PRIVATE_KEY_FILE)
46 46
47 fun tincd() = File(binDir(), TINCD_BIN) 47 fun tincd() = File(binDir(), TINCD_BIN)
48 fun tinc() = File(binDir(), TINC_BIN) 48 fun tinc() = File(binDir(), TINC_BIN)
49 49
50} 50}