Skip to content

Commit

Permalink
UI fixes, DNS infos. (yggdrasil-network#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron authored Nov 16, 2022
1 parent c9476a7 commit ee81f4e
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 148 deletions.
25 changes: 20 additions & 5 deletions app/src/main/java/eu/neilalexander/yggdrasil/DnsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.google.android.material.textfield.TextInputEditText

const val KEY_DNS_SERVERS = "dns_servers"
const val KEY_ENABLE_CHROME_FIX = "enable_chrome_fix"
const val DEFAULT_DNS_SERVERS = "302:7991::53,302:db60::53,300:6223::53,301:1088::53"

class DnsActivity : AppCompatActivity() {
private lateinit var config: ConfigurationProxy
Expand All @@ -28,6 +27,8 @@ class DnsActivity : AppCompatActivity() {
private lateinit var servers: MutableList<String>
private lateinit var preferences: SharedPreferences

private lateinit var defaultDnsServers: HashMap<String, Pair<String, String>>

@SuppressLint("ApplySharedPref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -36,6 +37,15 @@ class DnsActivity : AppCompatActivity() {
config = ConfigurationProxy(applicationContext)
inflater = LayoutInflater.from(this)

val descriptionRevertron = getString(R.string.dns_server_info_revertron)
// Here we can add some other DNS servers in a future
defaultDnsServers = hashMapOf(
"302:7991::53" to Pair(getString(R.string.location_amsterdam), descriptionRevertron),
"302:db60::53" to Pair(getString(R.string.location_prague), descriptionRevertron),
"300:6223::53" to Pair(getString(R.string.location_bratislava), descriptionRevertron),
"301:1088::53" to Pair(getString(R.string.location_buffalo), descriptionRevertron),
)

serversTableLayout = findViewById(R.id.configuredDnsTableLayout)
serversTableLabel = findViewById(R.id.configuredDnsLabel)
serversTableHint = findViewById(R.id.configuredDnsHint)
Expand Down Expand Up @@ -70,6 +80,11 @@ class DnsActivity : AppCompatActivity() {
}
}

val enableChromeFixPanel = findViewById<TableRow>(R.id.enableChromeFixPanel)
enableChromeFixPanel.setOnClickListener {
enableChromeFix.toggle()
}

preferences = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this.baseContext)
val serverString = preferences.getString(KEY_DNS_SERVERS, "")
servers = if (serverString!!.isNotEmpty()) {
Expand Down Expand Up @@ -132,10 +147,10 @@ class DnsActivity : AppCompatActivity() {
@SuppressLint("ApplySharedPref")
private fun updateUsableServers() {
val usableTableLayout: TableLayout = findViewById(R.id.usableDnsTableLayout)
val defaultServers = DEFAULT_DNS_SERVERS.split(",")

defaultServers.forEach {
val server = it
defaultDnsServers.forEach {
val server = it.key
val infoPair = it.value
val view = inflater.inflate(R.layout.dns_server_usable, null)
view.findViewById<TextView>(R.id.serverValue).text = server
val addButton = view.findViewById<ImageButton>(R.id.addButton)
Expand All @@ -152,7 +167,7 @@ class DnsActivity : AppCompatActivity() {
view.setOnLongClickListener {
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.dns_server_info_dialog_title))
builder.setMessage(getText(R.string.dns_server_info_revertron))
builder.setMessage("${infoPair.first}\n\n${infoPair.second}")
builder.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
dialog.dismiss()
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/eu/neilalexander/yggdrasil/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class MainActivity : AppCompatActivity() {
}
}

val enableYggdrasilPanel = findViewById<TableRow>(R.id.enableYggdrasilPanel)
enableYggdrasilPanel.setOnClickListener {
enabledSwitch.toggle()
}

peersRow.isClickable = true
peersRow.setOnClickListener {
val intent = Intent(this, PeersActivity::class.java)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/eu/neilalexander/yggdrasil/PeersActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class PeersActivity : AppCompatActivity() {
multicastListenSwitch.isChecked = config.multicastListen
multicastBeaconSwitch.isChecked = config.multicastBeacon

val multicastBeaconPanel = findViewById<TableRow>(R.id.enableMulticastBeaconPanel)
multicastBeaconPanel.setOnClickListener {
multicastBeaconSwitch.toggle()
}
val multicastListenPanel = findViewById<TableRow>(R.id.enableMulticastListenPanel)
multicastListenPanel.setOnClickListener {
multicastListenSwitch.toggle()
}

addPeerButton = findViewById(R.id.addPeerButton)
addPeerButton.setOnClickListener {
val view = inflater.inflate(R.layout.dialog_addpeer, null)
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/res/layout/activity_dns.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,8 @@
android:showDividers="middle">

<TableRow
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">
android:id="@+id/enableChromeFixPanel"
style="@style/SelectableSwitchItemStyle">

<TextView
android:layout_width="wrap_content"
Expand Down
88 changes: 12 additions & 76 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,8 @@
android:showDividers="middle">

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
android:id="@+id/enableYggdrasilPanel"
style="@style/SelectableSwitchItemStyle">

<TextView
android:id="@+id/enableYggdrasilLabel"
Expand All @@ -100,20 +94,14 @@

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
<TableRow style="@style/SelectableItemStyle">

<TextView
android:id="@+id/yggdrasilStatusLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:text="@string/main_disabled"
android:textSize="14sp"
android:textStyle="bold" />
Expand Down Expand Up @@ -160,15 +148,7 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
<TableRow style="@style/SelectableItemStyle">

<TextView
android:id="@+id/ipAddressLabel"
Expand All @@ -194,15 +174,7 @@
android:textSize="14sp" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
<TableRow style="@style/SelectableItemStyle">

<TextView
android:id="@+id/subnetLabel"
Expand All @@ -229,15 +201,7 @@

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
<TableRow style="@style/SelectableItemStyle">

<TextView
android:id="@+id/coordinatesLabel"
Expand Down Expand Up @@ -305,14 +269,7 @@

<TableRow
android:id="@+id/peersTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:paddingStart="4pt"
android:paddingTop="6pt"
android:paddingEnd="4pt"
android:paddingBottom="6pt">
style="@style/SelectableItemStyle">

<TextView
android:id="@+id/multicastLabel"
Expand Down Expand Up @@ -349,14 +306,7 @@

<TableRow
android:id="@+id/dnsTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:paddingStart="4pt"
android:paddingTop="6pt"
android:paddingEnd="4pt"
android:paddingBottom="6pt">
style="@style/SelectableItemStyle">

<TextView
android:id="@+id/dnsLabel"
Expand Down Expand Up @@ -393,13 +343,7 @@

<TableRow
android:id="@+id/settingsTableRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:paddingStart="4pt"
android:paddingTop="6pt"
android:paddingEnd="4pt"
android:paddingBottom="6pt">
style="@style/SelectableItemStyle">

<TextView
android:id="@+id/settingsLabel"
Expand Down Expand Up @@ -431,15 +375,7 @@

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="4pt"
android:layout_marginLeft="4pt"
android:layout_marginTop="6pt"
android:layout_marginEnd="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="6pt">
<TableRow style="@style/SelectableItemStyle">

<TextView
android:id="@+id/versionLabel"
Expand Down
21 changes: 4 additions & 17 deletions app/src/main/res/layout/activity_peers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8pt"
android:layout_marginLeft="8pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:background="@drawable/rounded"
android:divider="#46878787"
android:dividerPadding="4pt"
Expand Down Expand Up @@ -167,7 +165,6 @@
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:background="@drawable/rounded"
android:clickable="true"
android:divider="#46878787"
android:dividerPadding="4pt"
android:paddingLeft="4pt"
Expand All @@ -177,13 +174,8 @@
android:showDividers="middle">

<TableRow
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">
android:id="@+id/enableMulticastBeaconPanel"
style="@style/SelectableSwitchItemStyle">

<TextView
android:layout_width="wrap_content"
Expand All @@ -204,13 +196,8 @@
</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">
android:id="@+id/enableMulticastListenPanel"
style="@style/SelectableSwitchItemStyle">

<TextView
android:layout_width="wrap_content"
Expand Down
14 changes: 2 additions & 12 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,7 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4pt"
android:layout_marginTop="4pt"
android:layout_marginRight="4pt"
android:layout_marginBottom="4pt">
<TableRow style="@style/SelectableItemStyle">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -242,11 +236,7 @@

<TableRow
android:id="@+id/resetConfigurationRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:padding="4pt">
style="@style/SelectableItemStyle">

<TextView
android:layout_width="wrap_content"
Expand Down
23 changes: 8 additions & 15 deletions app/src/main/res/layout/dns_server_usable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,28 @@
android:id="@+id/serverValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="18dp"
android:layout_marginBottom="12dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="4dp"
android:gravity="center_vertical"
android:ellipsize="end"
android:singleLine="true"
android:text=""
android:textColor="?attr/textDefault"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/addButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/space" />

<Space
android:id="@+id/space"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/addButton"
app:layout_constraintEnd_toStartOf="@+id/addButton"
app:layout_constraintStart_toEndOf="@+id/serverValue"
app:layout_constraintTop_toTopOf="@+id/addButton" />
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit ee81f4e

Please sign in to comment.