summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt
blob: abc81998ddcc55463d3110e913f2703337eca25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.wireguard.android.viewmodel

import android.util.Log
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import androidx.databinding.Observable

import com.wireguard.android.BR
import com.wireguard.config.InetEndpoint
import com.wireguard.config.Peer

import java.util.Optional;


class PeerDetail : BaseObservable {
    var peer: Peer
    private var owner: ConfigDetail? = null

    @get:Bindable
    var endpoint: Optional<InetEndpoint> = Optional.empty()
        get() {
            if (!field.isEmpty()) {
                return field
            } else {
                return peer.endpoint
            }
        }

        set(value) {
            Log.i(TAG, "notifyPropertyChanged endpoint " + this + ", " + value)
            field = value
            notifyPropertyChanged(BR.endpoint)
        }

    constructor(other: Peer) {
        peer = other
    }

    fun bind(owner: ConfigDetail) {
        this.owner = owner
    }

    override fun addOnPropertyChangedCallback (callback: Observable.OnPropertyChangedCallback) {
        Log.i(TAG, "addOnPropertyChangedCallback " + this + ", " + callback)
        super.addOnPropertyChangedCallback(callback)
    }
    
    companion object {
        private const val TAG = "WireGuard/PeerDetail"
    }
}