Skip to content

Commit

Permalink
Added a note about not configured peers. Changed all dialog buttons t…
Browse files Browse the repository at this point in the history
…o greenish color.
  • Loading branch information
Revertron committed Nov 25, 2024
1 parent ff23d34 commit 1701045
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/eu/neilalexander/yggdrasil/DnsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DnsActivity : AppCompatActivity() {
addServerButton.setOnClickListener {
val view = inflater.inflate(R.layout.dialog_add_dns_server, null)
val input = view.findViewById<TextInputEditText>(R.id.addDnsInput)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.dns_add_server_dialog_title))
builder.setView(view)
builder.setPositiveButton(getString(R.string.add)) { _, _ ->
Expand Down Expand Up @@ -128,7 +128,7 @@ class DnsActivity : AppCompatActivity() {
view.findViewById<ImageButton>(R.id.deletePeerButton).tag = i

view.findViewById<ImageButton>(R.id.deletePeerButton).setOnClickListener { button ->
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.dns_remove_title, server))
builder.setPositiveButton(getString(R.string.remove)) { dialog, _ ->
servers.removeAt(button.tag as Int)
Expand Down Expand Up @@ -176,7 +176,7 @@ class DnsActivity : AppCompatActivity() {
}
}
view.setOnLongClickListener {
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.dns_server_info_dialog_title))
builder.setMessage("${infoPair.first}\n\n${infoPair.second}")
builder.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.core.app.NotificationCompat
import androidx.preference.PreferenceManager

const val PREF_KEY_ENABLED = "enabled"
const val PREF_KEY_PEERS_NOTE = "peers_note"
const val MAIN_CHANNEL_ID = "Yggdrasil Service"

class GlobalApplication: Application(), YggStateReceiver.StateReceiver {
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/eu/neilalexander/yggdrasil/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package eu.neilalexander.yggdrasil

import android.app.Activity
import android.app.AlertDialog
import android.content.*
import android.graphics.Color
import android.net.VpnService
import android.os.Bundle
import android.view.ContextThemeWrapper
import android.widget.Switch
import android.widget.TextView
import android.widget.Toast
Expand Down Expand Up @@ -161,6 +163,7 @@ class MainActivity : AppCompatActivity() {
}
}
enabledLabel.text = if (intent.getBooleanExtra("started", false)) {
showPeersNoteIfNeeded(peerState.length())
if (count == 0) {
enabledLabel.setTextColor(Color.RED)
getString(R.string.main_no_connectivity)
Expand Down Expand Up @@ -188,4 +191,26 @@ class MainActivity : AppCompatActivity() {
}
}
}

private fun showPeersNoteIfNeeded(peerCount: Int) {
if (peerCount > 0) return
val preferences = PreferenceManager.getDefaultSharedPreferences(this@MainActivity.baseContext)
if (!preferences.getBoolean(PREF_KEY_PEERS_NOTE, false)) {
this@MainActivity.runOnUiThread {
val builder: AlertDialog.Builder =
AlertDialog.Builder(ContextThemeWrapper(this@MainActivity, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.main_add_some_peers_title))
builder.setMessage(getString(R.string.main_add_some_peers_message))
builder.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
dialog.dismiss()
}
builder.show()
}
// Mark this note as shown
preferences.edit().apply {
putBoolean(PREF_KEY_PEERS_NOTE, true)
commit()
}
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/eu/neilalexander/yggdrasil/PeersActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PeersActivity : AppCompatActivity() {
addPeerButton.setOnClickListener {
val view = inflater.inflate(R.layout.dialog_addpeer, null)
val input = view.findViewById<TextInputEditText>(R.id.addPeerInput)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.peers_add_peer))
builder.setView(view)
builder.setPositiveButton(getString(R.string.peers_add)) { dialog, _ ->
Expand Down Expand Up @@ -153,7 +153,7 @@ class PeersActivity : AppCompatActivity() {
view.findViewById<ImageButton>(R.id.deletePeerButton).tag = i

view.findViewById<ImageButton>(R.id.deletePeerButton).setOnClickListener { button ->
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.peers_remove_title, peer))
builder.setPositiveButton(getString(R.string.peers_remove)) { dialog, _ ->
config.updateJSON { json ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SettingsActivity : AppCompatActivity() {

resetConfigurationRow.setOnClickListener {
val view = inflater.inflate(R.layout.dialog_resetconfig, null)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
builder.setTitle(getString(R.string.settings_warning_title))
builder.setView(view)
builder.setPositiveButton(getString(R.string.settings_reset)) { dialog, _ ->
Expand All @@ -92,7 +92,7 @@ class SettingsActivity : AppCompatActivity() {

findViewById<View>(R.id.setKeysRow).setOnClickListener {
val view = inflater.inflate(R.layout.dialog_set_keys, null)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.YggdrasilDialogs))
val privateKey = view.findViewById<EditText>(R.id.private_key)
builder.setTitle(getString(R.string.set_keys))
builder.setView(view)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<string name="main_no_peers">Нет пиров</string>
<string name="main_one_peer">1 пир</string>
<string name="main_many_peers">%d пира/пиров</string>
<string name="main_add_some_peers_title">Внимание</string>
<string name="main_add_some_peers_message">Кажется, вы не добавили ни одного пира. Зайдите в раздел пиров и подключите один из списка публичных, чтобы подключиться к сети.</string>
<string name="peers_add_peer">Добавить пира в конфиг</string>
<string name="peers_add">Добавить</string>
<string name="peers_remove_title">Убрать %s?</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="green">#5FBF9F</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="hintlight">#F2F1F5</color>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<string name="main_no_peers">No peers</string>
<string name="main_one_peer">1 peer</string>
<string name="main_many_peers">%d peers</string>
<string name="main_add_some_peers_title">Note</string>
<string name="main_add_some_peers_message">It seems that you didn\'t configure any peers. Go to peers section and add one from public list to get connected.</string>
<string name="peers_add_peer">Add Configured Peer</string>
<string name="peers_add">Add</string>
<string name="peers_remove_title">Remove %s?</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
<item name="tableBackgroundColor">@color/white</item>
<item name="textDefault">@color/black</item>
</style>

<style name="YggdrasilDialogs" parent="@style/Theme.MaterialComponents.DayNight.Dialog">
<item name="colorPrimary">@color/green</item>
</style>
</resources>

0 comments on commit 1701045

Please sign in to comment.