This commit is contained in:
Neil Alexander 2021-06-28 18:51:42 +01:00
parent fa9532fb97
commit 27e1909aa2
6 changed files with 70 additions and 34 deletions

View file

@ -11,7 +11,7 @@ android {
applicationId "eu.neilalexander.yggdrasil"
minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionCode 5
versionName "0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -3,6 +3,7 @@ package eu.neilalexander.yggdrasil
import android.content.Context
import android.provider.Settings
import mobile.Mobile
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
@ -40,6 +41,18 @@ object ConfigurationProxy {
json.put("AdminListen", "none")
json.put("IfName", "none")
json.put("IfMTU", 65535)
if (json.getJSONArray("MulticastInterfaces").get(0) is String) {
var ar = JSONArray()
ar.put(0, JSONObject("""
{
"Regex": ".*",
"Beacon": true,
"Listen": true
}
""".trimIndent()))
json.put("MulticastInterfaces", ar)
}
}
}
@ -51,4 +64,20 @@ object ConfigurationProxy {
fun getJSONByteArray(): ByteArray {
return json.toString().toByteArray(Charsets.UTF_8)
}
var multicastListen: Boolean
get() = (json.getJSONArray("MulticastInterfaces").get(0) as JSONObject).getBoolean("Listen")
set(value) {
updateJSON { json ->
(json.getJSONArray("MulticastInterfaces").get(0) as JSONObject).put("Listen", value)
}
}
var multicastBeacon: Boolean
get() = (json.getJSONArray("MulticastInterfaces").get(0) as JSONObject).getBoolean("Beacon")
set(value) {
updateJSON { json ->
(json.getJSONArray("MulticastInterfaces").get(0) as JSONObject).put("Beacon", value)
}
}
}

View file

@ -13,7 +13,6 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import mobile.Mobile
import org.json.JSONArray
class MainActivity : AppCompatActivity() {
@ -34,7 +33,7 @@ class MainActivity : AppCompatActivity() {
findViewById<TextView>(R.id.versionValue).text = Mobile.getVersion()
enabledSwitch = findViewById(R.id.enableMulticastSwitch)
enabledSwitch = findViewById(R.id.enableMulticastBeacon)
enabledLabel = findViewById(R.id.yggdrasilStatusLabel)
ipAddressLabel = findViewById(R.id.ipAddressValue)
subnetLabel = findViewById(R.id.subnetValue)

View file

@ -1,13 +1,8 @@
package eu.neilalexander.yggdrasil
import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Layout
import android.util.AttributeSet
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
@ -24,7 +19,8 @@ class PeersActivity : AppCompatActivity() {
private lateinit var connectedTableLabel: TextView
private lateinit var configuredTableLayout: TableLayout
private lateinit var configuredTableLabel: TextView
private lateinit var multicastSwitch: Switch
private lateinit var multicastListenSwitch: Switch
private lateinit var multicastBeaconSwitch: Switch
private lateinit var addPeerButton: ImageButton
override fun onCreate(savedInstanceState: Bundle?) {
@ -40,29 +36,16 @@ class PeersActivity : AppCompatActivity() {
configuredTableLayout = findViewById(R.id.configuredPeersTableLayout)
configuredTableLabel = findViewById(R.id.configuredPeersLabel)
multicastSwitch = findViewById(R.id.enableMulticastSwitch)
multicastSwitch.setOnCheckedChangeListener { button, _ ->
when (button.isChecked) {
true -> {
config.updateJSON { json ->
json.put("MulticastInterfaces", JSONArray("[\"lo\", \".*\"]"))
multicastListenSwitch = findViewById(R.id.enableMulticastListen)
multicastListenSwitch.setOnCheckedChangeListener { button, _ ->
config.multicastListen = button.isChecked
}
multicastBeaconSwitch = findViewById(R.id.enableMulticastBeacon)
multicastBeaconSwitch.setOnCheckedChangeListener { button, _ ->
config.multicastBeacon = button.isChecked
}
false -> {
config.updateJSON { json ->
json.put("MulticastInterfaces", JSONArray("[\"lo\"]"))
}
}
}
}
var multicastInterfaceFound = false
val multicastInterfaces = config.getJSON().getJSONArray("MulticastInterfaces")
(0 until multicastInterfaces.length()).forEach {
if (multicastInterfaces[it] == ".*") {
multicastInterfaceFound = true
}
}
multicastSwitch.isChecked = multicastInterfaceFound
multicastListenSwitch.isChecked = config.multicastListen
multicastBeaconSwitch.isChecked = config.multicastBeacon
addPeerButton = findViewById(R.id.addPeerButton)
addPeerButton.setOnClickListener {

View file

@ -85,7 +85,7 @@
android:layout_weight="2" />
<Switch
android:id="@+id/enableMulticastSwitch"
android:id="@+id/enableMulticastBeacon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

View file

@ -168,17 +168,42 @@
android:showDividers="middle">
<TableRow
android:id="@+id/peersTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:paddingStart="4pt"
android:paddingTop="2pt"
android:paddingEnd="4pt"
android:paddingBottom="4pt">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Discoverable over multicast"
android:textColor="?attr/textDefault" />
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2" />
<Switch
android:id="@+id/enableMulticastBeacon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:paddingStart="4pt"
android:paddingTop="4pt"
android:paddingEnd="4pt"
android:paddingBottom="2pt">
<TextView
android:id="@+id/multicastLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search for multicast peers"
@ -190,7 +215,7 @@
android:layout_weight="2" />
<Switch
android:id="@+id/enableMulticastSwitch"
android:id="@+id/enableMulticastListen"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />