diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/intent')
3 files changed, 38 insertions, 14 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/intent/Actions.kt b/app/src/main/java/org/pacien/tincapp/intent/Actions.kt new file mode 100644 index 0000000..4650952 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/intent/Actions.kt | |||
@@ -0,0 +1,19 @@ | |||
1 | package org.pacien.tincapp.intent | ||
2 | |||
3 | import android.net.Uri | ||
4 | import org.pacien.tincapp.BuildConfig | ||
5 | |||
6 | /** | ||
7 | * @author pacien | ||
8 | */ | ||
9 | object Actions { | ||
10 | const val PREFIX = "${BuildConfig.APPLICATION_ID}.intent.action" | ||
11 | const val ACTION_CONNECT = "$PREFIX.CONNECT" | ||
12 | const val ACTION_DISCONNECT = "$PREFIX.DISCONNECT" | ||
13 | const val EVENT_CONNECTED = "$PREFIX.CONNECTED" | ||
14 | const val EVENT_DISCONNECTED = "$PREFIX.DISCONNECTED" | ||
15 | const val TINC_SCHEME = "tinc" | ||
16 | |||
17 | fun buildNetworkUri(netName: String, passphrase: String? = null): Uri = | ||
18 | Uri.Builder().scheme(Actions.TINC_SCHEME).opaquePart(netName).fragment(passphrase).build() | ||
19 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/intent/SimpleBroadcastReceiver.kt b/app/src/main/java/org/pacien/tincapp/intent/SimpleBroadcastReceiver.kt new file mode 100644 index 0000000..fb77174 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/intent/SimpleBroadcastReceiver.kt | |||
@@ -0,0 +1,19 @@ | |||
1 | package org.pacien.tincapp.intent | ||
2 | |||
3 | import android.content.BroadcastReceiver | ||
4 | import android.content.Context | ||
5 | import android.content.Intent | ||
6 | import android.content.IntentFilter | ||
7 | import android.support.v4.content.LocalBroadcastManager | ||
8 | import org.pacien.tincapp.context.App | ||
9 | |||
10 | /** | ||
11 | * @author pacien | ||
12 | */ | ||
13 | class SimpleBroadcastReceiver(private val intentFilter: IntentFilter, private val eventHandler: () -> Unit) : BroadcastReceiver() { | ||
14 | private val broadcastManager = LocalBroadcastManager.getInstance(App.getContext()) | ||
15 | |||
16 | fun register() = broadcastManager.registerReceiver(this, intentFilter) | ||
17 | fun unregister() = broadcastManager.unregisterReceiver(this) | ||
18 | override fun onReceive(context: Context?, intent: Intent?) = eventHandler() | ||
19 | } | ||
diff --git a/app/src/main/java/org/pacien/tincapp/intent/action/Actions.kt b/app/src/main/java/org/pacien/tincapp/intent/action/Actions.kt deleted file mode 100644 index ece9b68..0000000 --- a/app/src/main/java/org/pacien/tincapp/intent/action/Actions.kt +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | package org.pacien.tincapp.intent.action | ||
2 | |||
3 | import org.pacien.tincapp.BuildConfig | ||
4 | |||
5 | /** | ||
6 | * @author pacien | ||
7 | */ | ||
8 | |||
9 | private val PREFIX = "${BuildConfig.APPLICATION_ID}.intent.action" | ||
10 | |||
11 | val ACTION_CONNECT = "$PREFIX.CONNECT" | ||
12 | val ACTION_DISCONNECT = "$PREFIX.DISCONNECT" | ||
13 | |||
14 | val TINC_SCHEME = "tinc" | ||