mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-28 14:15:08 +03:00
* Fixes #30, added quick settings icon. * Added saving of enabled state, added some fixes and refactorings. * Fixed a bug with turning on/off the VPN. * Fixed possibility to add duplicate servers in DNS settings.
This commit is contained in:
parent
ee81f4e902
commit
aa94ccad26
12 changed files with 441 additions and 60 deletions
|
@ -0,0 +1,53 @@
|
|||
package eu.neilalexander.yggdrasil
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
|
||||
const val STATE_ENABLED = "enabled"
|
||||
const val STATE_DISABLED = "disabled"
|
||||
const val STATE_CONNECTED = "connected"
|
||||
const val STATE_RECONNECTING = "reconnecting"
|
||||
|
||||
class YggStateReceiver(var receiver: StateReceiver): BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
const val YGG_STATE_INTENT = "eu.neilalexander.yggdrasil.YggStateReceiver.STATE"
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context == null) return
|
||||
|
||||
val state = when (intent?.getStringExtra("state")) {
|
||||
STATE_ENABLED -> State.Enabled
|
||||
STATE_DISABLED -> State.Disabled
|
||||
STATE_CONNECTED -> State.Connected
|
||||
STATE_RECONNECTING -> State.Reconnecting
|
||||
else -> State.Unknown
|
||||
}
|
||||
receiver.onStateChange(state)
|
||||
}
|
||||
|
||||
fun register(context: Context) {
|
||||
LocalBroadcastManager.getInstance(context).registerReceiver(
|
||||
this, IntentFilter(YGG_STATE_INTENT)
|
||||
)
|
||||
}
|
||||
|
||||
fun unregister(context: Context) {
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(this)
|
||||
}
|
||||
|
||||
interface StateReceiver {
|
||||
fun onStateChange(state: State)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class-supporter with an Yggdrasil state
|
||||
*/
|
||||
enum class State {
|
||||
Unknown, Disabled, Enabled, Connected, Reconnecting;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue