diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/extensions')
4 files changed, 57 insertions, 57 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/Android.kt b/app/src/main/java/org/pacien/tincapp/extensions/Android.kt index 84dcfde..6674cc3 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/Android.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/Android.kt | |||
@@ -10,16 +10,16 @@ import org.pacien.tincapp.context.App | |||
10 | */ | 10 | */ |
11 | object Android { | 11 | object Android { |
12 | 12 | ||
13 | fun <T> ArrayAdapter<T>.setElements(elems: Collection<T>) { | 13 | fun <T> ArrayAdapter<T>.setElements(elems: Collection<T>) { |
14 | setNotifyOnChange(false) | 14 | setNotifyOnChange(false) |
15 | clear() | 15 | clear() |
16 | addAll(elems) | 16 | addAll(elems) |
17 | notifyDataSetChanged() | 17 | notifyDataSetChanged() |
18 | setNotifyOnChange(true) | 18 | setNotifyOnChange(true) |
19 | } | 19 | } |
20 | 20 | ||
21 | fun TextView.setText(list: List<String>) { | 21 | fun TextView.setText(list: List<String>) { |
22 | text = if (list.isNotEmpty()) list.joinToString("\n") else App.getContext().getString(R.string.value_none) | 22 | text = if (list.isNotEmpty()) list.joinToString("\n") else App.getContext().getString(R.string.value_none) |
23 | } | 23 | } |
24 | 24 | ||
25 | } | 25 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt b/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt index 367a280..48d1118 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/ApacheConfiguration.kt | |||
@@ -9,10 +9,10 @@ import java.io.File | |||
9 | */ | 9 | */ |
10 | object ApacheConfiguration { | 10 | object ApacheConfiguration { |
11 | 11 | ||
12 | fun Configuration.getStringList(key: String): List<String> = getList(String::class.java, key, emptyList()) | 12 | fun Configuration.getStringList(key: String): List<String> = getList(String::class.java, key, emptyList()) |
13 | fun Configuration.getCidrList(key: String): List<CidrAddress> = getStringList(key).map { CidrAddress.fromSlashSeparated(it) } | 13 | fun Configuration.getCidrList(key: String): List<CidrAddress> = getStringList(key).map { CidrAddress.fromSlashSeparated(it) } |
14 | fun Configuration.getIntList(key: String): List<Int> = getList(Int::class.java, key, emptyList()) | 14 | fun Configuration.getIntList(key: String): List<Int> = getList(Int::class.java, key, emptyList()) |
15 | 15 | ||
16 | fun Configuration.getFile(key: String): File? = getString(key)?.let { File(it) } | 16 | fun Configuration.getFile(key: String): File? = getString(key)?.let { File(it) } |
17 | 17 | ||
18 | } | 18 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt index af3c1af..95fecbf 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt | |||
@@ -7,12 +7,12 @@ import java8.util.concurrent.CompletableFuture | |||
7 | */ | 7 | */ |
8 | object Java { | 8 | object Java { |
9 | 9 | ||
10 | fun <T> CompletableFuture<T>.exceptionallyAccept(fn: (Throwable) -> Unit) = exceptionally { fn(it); null }!! | 10 | fun <T> CompletableFuture<T>.exceptionallyAccept(fn: (Throwable) -> Unit) = exceptionally { fn(it); null }!! |
11 | 11 | ||
12 | fun <A, R> applyIgnoringException(f: (A) -> R, x: A, alt: R? = null) = try { | 12 | fun <A, R> applyIgnoringException(f: (A) -> R, x: A, alt: R? = null) = try { |
13 | f(x) | 13 | f(x) |
14 | } catch (_: Exception) { | 14 | } catch (_: Exception) { |
15 | alt | 15 | alt |
16 | } | 16 | } |
17 | 17 | ||
18 | } | 18 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt b/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt index 870668a..d70fa80 100644 --- a/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt +++ b/app/src/main/java/org/pacien/tincapp/extensions/VpnServiceBuilder.kt | |||
@@ -10,42 +10,42 @@ import org.pacien.tincapp.extensions.Java.applyIgnoringException | |||
10 | */ | 10 | */ |
11 | object VpnServiceBuilder { | 11 | object VpnServiceBuilder { |
12 | 12 | ||
13 | fun VpnService.Builder.addAddress(cidr: CidrAddress): VpnService.Builder = addAddress(cidr.address, cidr.prefix) | 13 | fun VpnService.Builder.addAddress(cidr: CidrAddress): VpnService.Builder = addAddress(cidr.address, cidr.prefix) |
14 | fun VpnService.Builder.addRoute(cidr: CidrAddress): VpnService.Builder = addRoute(cidr.address, cidr.prefix) | 14 | fun VpnService.Builder.addRoute(cidr: CidrAddress): VpnService.Builder = addRoute(cidr.address, cidr.prefix) |
15 | fun VpnService.Builder.allowBypass(allow: Boolean): VpnService.Builder = if (allow) allowBypass() else this | 15 | fun VpnService.Builder.allowBypass(allow: Boolean): VpnService.Builder = if (allow) allowBypass() else this |
16 | fun VpnService.Builder.overrideMtu(mtu: Int?): VpnService.Builder = if (mtu != null) setMtu(mtu) else this | 16 | fun VpnService.Builder.overrideMtu(mtu: Int?): VpnService.Builder = if (mtu != null) setMtu(mtu) else this |
17 | 17 | ||
18 | fun VpnService.Builder.addAddresses(cidrList: List<CidrAddress>): VpnService.Builder = | 18 | fun VpnService.Builder.addAddresses(cidrList: List<CidrAddress>): VpnService.Builder = |
19 | cidrList.fold(this, { net, cidr -> net.addAddress(cidr) }) | 19 | cidrList.fold(this, { net, cidr -> net.addAddress(cidr) }) |
20 | 20 | ||
21 | fun VpnService.Builder.addRoutes(cidrList: List<CidrAddress>): VpnService.Builder = | 21 | fun VpnService.Builder.addRoutes(cidrList: List<CidrAddress>): VpnService.Builder = |
22 | cidrList.fold(this, { net, cidr -> net.addRoute(cidr) }) | 22 | cidrList.fold(this, { net, cidr -> net.addRoute(cidr) }) |
23 | 23 | ||
24 | fun VpnService.Builder.addDnsServers(dnsList: List<String>): VpnService.Builder = | 24 | fun VpnService.Builder.addDnsServers(dnsList: List<String>): VpnService.Builder = |
25 | dnsList.fold(this, { net, dns -> net.addDnsServer(dns) }) | 25 | dnsList.fold(this, { net, dns -> net.addDnsServer(dns) }) |
26 | 26 | ||
27 | fun VpnService.Builder.addSearchDomains(domainList: List<String>): VpnService.Builder = | 27 | fun VpnService.Builder.addSearchDomains(domainList: List<String>): VpnService.Builder = |
28 | domainList.fold(this, { net, domain -> net.addSearchDomain(domain) }) | 28 | domainList.fold(this, { net, domain -> net.addSearchDomain(domain) }) |
29 | 29 | ||
30 | fun VpnService.Builder.allowFamilies(familyList: List<Int>): VpnService.Builder = | 30 | fun VpnService.Builder.allowFamilies(familyList: List<Int>): VpnService.Builder = |
31 | familyList.fold(this, { net, family -> net.allowFamily(family) }) | 31 | familyList.fold(this, { net, family -> net.allowFamily(family) }) |
32 | 32 | ||
33 | fun VpnService.Builder.addAllowedApplications(apps: List<String>): VpnService.Builder = | 33 | fun VpnService.Builder.addAllowedApplications(apps: List<String>): VpnService.Builder = |
34 | apps.fold(this, { net, app -> applyIgnoringException(net::addAllowedApplication, app, net)!! }) | 34 | apps.fold(this, { net, app -> applyIgnoringException(net::addAllowedApplication, app, net)!! }) |
35 | 35 | ||
36 | fun VpnService.Builder.addDisallowedApplications(apps: List<String>): VpnService.Builder = | 36 | fun VpnService.Builder.addDisallowedApplications(apps: List<String>): VpnService.Builder = |
37 | apps.fold(this, { net, app -> applyIgnoringException(net::addDisallowedApplication, app, net)!! }) | 37 | apps.fold(this, { net, app -> applyIgnoringException(net::addDisallowedApplication, app, net)!! }) |
38 | 38 | ||
39 | fun VpnService.Builder.applyCfg(cfg: VpnInterfaceConfiguration): VpnService.Builder = this | 39 | fun VpnService.Builder.applyCfg(cfg: VpnInterfaceConfiguration): VpnService.Builder = this |
40 | .addAddresses(cfg.addresses) | 40 | .addAddresses(cfg.addresses) |
41 | .addRoutes(cfg.routes) | 41 | .addRoutes(cfg.routes) |
42 | .addDnsServers(cfg.dnsServers) | 42 | .addDnsServers(cfg.dnsServers) |
43 | .addSearchDomains(cfg.searchDomains) | 43 | .addSearchDomains(cfg.searchDomains) |
44 | .addAllowedApplications(cfg.allowedApplications) | 44 | .addAllowedApplications(cfg.allowedApplications) |
45 | .addDisallowedApplications(cfg.disallowedApplications) | 45 | .addDisallowedApplications(cfg.disallowedApplications) |
46 | .allowFamilies(cfg.allowedFamilies) | 46 | .allowFamilies(cfg.allowedFamilies) |
47 | .allowBypass(cfg.allowBypass) | 47 | .allowBypass(cfg.allowBypass) |
48 | .setBlocking(cfg.blocking) | 48 | .setBlocking(cfg.blocking) |
49 | .overrideMtu(cfg.mtu) | 49 | .overrideMtu(cfg.mtu) |
50 | 50 | ||
51 | } | 51 | } |