summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-04-01 23:42:17 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2023-04-01 23:42:17 +0200
commite44d3abcef5492548a7b53c3f8fbeec2018b5c78 (patch)
tree4dd3dd37d42b960dc2f82b318ad2ad955dbf01a2
parent6c034ac841e49febe10e337d1e83f686784af4fb (diff)
WIP: httpproxyitemhttpproxyitems
Trying to make httpProxyItems load from string resources
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt13
-rw-r--r--ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt22
-rw-r--r--ui/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.kt24
-rw-r--r--ui/src/main/res/layout/tunnel_editor_fragment.xml2
-rw-r--r--ui/src/main/res/values/strings.xml5
5 files changed, 42 insertions, 24 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt
index 9597fef6..27c55d0b 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt
@@ -48,6 +48,14 @@ class TunnelEditorFragment : BaseFragment(), MenuProvider {
private var haveShownKeys = false
private var binding: TunnelEditorFragmentBinding? = null
private var tunnel: ObservableTunnel? = null
+ private var httpProxyItems: List<String>
+
+ init {
+ val ctx = activity ?: Application.get()
+ httpProxyItems = listOf(ctx.getString(R.string.http_proxy_none),
+ ctx.getString(R.string.http_proxy_manual),
+ ctx.getString(R.string.http_proxy_pac))
+ }
private class MaterialSpinnerAdapter<T>(context: Context, resource: Int, private val objects: List<T>) : ArrayAdapter<T>(context, resource, objects) {
private val _filter: Filter by lazy {
@@ -65,7 +73,7 @@ class TunnelEditorFragment : BaseFragment(), MenuProvider {
}
private fun onConfigLoaded(config: Config) {
- binding?.config = ConfigProxy(config)
+ binding?.config = ConfigProxy(httpProxyItems, config)
}
private fun onConfigSaved(savedTunnel: Tunnel, throwable: Throwable?) {
@@ -105,7 +113,6 @@ class TunnelEditorFragment : BaseFragment(), MenuProvider {
}
var httpProxyMenu = binding?.root?.findViewById<TextInputLayout>(R.id.http_proxy_menu)
- var httpProxyItems = listOf(Constants.HTTP_PROXY_NONE, Constants.HTTP_PROXY_MANUAL, Constants.HTTP_PROXY_PAC)
var httpProxyAdapter = MaterialSpinnerAdapter(requireContext(), R.layout.http_proxy_menu_item, httpProxyItems)
var httpProxyMenuText = httpProxyMenu?.editText as? AutoCompleteTextView
httpProxyMenuText?.setAdapter(httpProxyAdapter)
@@ -233,7 +240,7 @@ class TunnelEditorFragment : BaseFragment(), MenuProvider {
newTunnel: ObservableTunnel?) {
tunnel = newTunnel
if (binding == null) return
- binding!!.config = ConfigProxy()
+ binding!!.config = ConfigProxy(httpProxyItems)
if (tunnel != null) {
binding!!.name = tunnel!!.name
lifecycleScope.launch {
diff --git a/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt b/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt
index e29de2dd..7d25c086 100644
--- a/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt
+++ b/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt
@@ -16,15 +16,18 @@ import java.util.ArrayList
class ConfigProxy : Parcelable {
val `interface`: InterfaceProxy
val peers: ObservableList<PeerProxy> = ObservableArrayList()
+ val httpProxyItems: List<String>
- private constructor(parcel: Parcel) {
+ private constructor(httpProxyItems: List<String>, parcel: Parcel) {
+ this.httpProxyItems = httpProxyItems
`interface` = InterfaceProxy.CREATOR.createFromParcel(parcel)
parcel.readTypedList(peers, PeerProxy.CREATOR)
peers.forEach { it.bind(this) }
}
- constructor(other: Config) {
- `interface` = InterfaceProxy(other.getInterface())
+ constructor(httpProxyItems: List<String>, other: Config) {
+ this.httpProxyItems = httpProxyItems
+ `interface` = InterfaceProxy(httpProxyItems, other.getInterface())
other.peers.forEach {
val proxy = PeerProxy(it)
peers.add(proxy)
@@ -32,8 +35,9 @@ class ConfigProxy : Parcelable {
}
}
- constructor() {
- `interface` = InterfaceProxy()
+ constructor(httpProxyItems: List<String>) {
+ this.httpProxyItems = httpProxyItems
+ `interface` = InterfaceProxy(httpProxyItems)
}
fun addPeer(): PeerProxy {
@@ -60,9 +64,9 @@ class ConfigProxy : Parcelable {
dest.writeTypedList(peers)
}
- private class ConfigProxyCreator : Parcelable.Creator<ConfigProxy> {
+ private class ConfigProxyCreator() : Parcelable.Creator<ConfigProxy> {
override fun createFromParcel(parcel: Parcel): ConfigProxy {
- return ConfigProxy(parcel)
+ return ConfigProxy(httpProxyItems, parcel)
}
override fun newArray(size: Int): Array<ConfigProxy?> {
@@ -70,8 +74,8 @@ class ConfigProxy : Parcelable {
}
}
- companion object {
+// companion object {
@JvmField
val CREATOR: Parcelable.Creator<ConfigProxy> = ConfigProxyCreator()
- }
+// }
}
diff --git a/ui/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.kt b/ui/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.kt
index 16c3e6a3..33a2e8a0 100644
--- a/ui/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.kt
+++ b/ui/src/main/java/com/wireguard/android/viewmodel/InterfaceProxy.kt
@@ -21,12 +21,14 @@ import com.wireguard.crypto.KeyFormatException
import com.wireguard.crypto.KeyPair
object Constants {
- const val HTTP_PROXY_NONE = "None"
- const val HTTP_PROXY_MANUAL = "Manual"
- const val HTTP_PROXY_PAC = "Proxy Auto-Config"
+ const val HTTP_PROXY_NONE = 1
+ const val HTTP_PROXY_MANUAL = 2
+ const val HTTP_PROXY_PAC = 3
}
class InterfaceProxy : BaseObservable, Parcelable {
+ val httpProxyItems: List<String>
+
@get:Bindable
val excludedApplications: ObservableList<String> = ObservableArrayList()
@@ -72,7 +74,7 @@ class InterfaceProxy : BaseObservable, Parcelable {
@get:Bindable
var httpProxyManualVisibility: Int = 0
- get() = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) android.view.View.GONE else (if (httpProxyMenu == Constants.HTTP_PROXY_MANUAL) android.view.View.VISIBLE else android.view.View.GONE)
+ get() = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) android.view.View.GONE else (if (httpProxyMenu == httpProxyItems[Constants.HTTP_PROXY_MANUAL]) android.view.View.VISIBLE else android.view.View.GONE)
@get:Bindable
var httpProxyHostname: String = ""
@@ -115,7 +117,7 @@ class InterfaceProxy : BaseObservable, Parcelable {
""
}
- private constructor(parcel: Parcel) {
+ private constructor(httpProxyItems: List<String>, parcel: Parcel) : this(httpProxyItems) {
addresses = parcel.readString() ?: ""
dnsServers = parcel.readString() ?: ""
parcel.readStringList(excludedApplications)
@@ -129,7 +131,7 @@ class InterfaceProxy : BaseObservable, Parcelable {
privateKey = parcel.readString() ?: ""
}
- constructor(other: Interface) {
+ constructor(httpProxyItems: List<String>, other: Interface) : this(httpProxyItems) {
addresses = Attribute.join(other.addresses)
val dnsServerStrings = other.dnsServers.map { it.hostAddress }.plus(other.dnsSearchDomains)
dnsServers = Attribute.join(dnsServerStrings)
@@ -145,7 +147,9 @@ class InterfaceProxy : BaseObservable, Parcelable {
privateKey = keyPair.privateKey.toBase64()
}
- constructor()
+ constructor(httpProxyItems: List<String>) {
+ this.httpProxyItems = httpProxyItems
+ }
override fun describeContents() = 0
@@ -199,7 +203,7 @@ class InterfaceProxy : BaseObservable, Parcelable {
private class InterfaceProxyCreator : Parcelable.Creator<InterfaceProxy> {
override fun createFromParcel(parcel: Parcel): InterfaceProxy {
- return InterfaceProxy(parcel)
+ return InterfaceProxy(httpProxyItems, parcel)
}
override fun newArray(size: Int): Array<InterfaceProxy?> {
@@ -207,8 +211,8 @@ class InterfaceProxy : BaseObservable, Parcelable {
}
}
- companion object {
+// companion object {
@JvmField
val CREATOR: Parcelable.Creator<InterfaceProxy> = InterfaceProxyCreator()
- }
+// }
}
diff --git a/ui/src/main/res/layout/tunnel_editor_fragment.xml b/ui/src/main/res/layout/tunnel_editor_fragment.xml
index 42222399..191e8f74 100644
--- a/ui/src/main/res/layout/tunnel_editor_fragment.xml
+++ b/ui/src/main/res/layout/tunnel_editor_fragment.xml
@@ -318,7 +318,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
- android:hint="@string/http_proxy_pac"
+ android:hint="@string/http_proxy_pac_url"
android:visibility="@{config.interface.httpProxyPacVisibility}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml
index a6f66324..862bda9d 100644
--- a/ui/src/main/res/values/strings.xml
+++ b/ui/src/main/res/values/strings.xml
@@ -137,7 +137,10 @@
<string name="hint_random">(random)</string>
<string name="http_proxy">Proxy</string>
<string name="http_proxy_hostname">Proxy hostname</string>
- <string name="http_proxy_pac">Proxy Auto-Config URL</string>
+ <string name="http_proxy_manual">Manual</string>
+ <string name="http_proxy_none">None</string>
+ <string name="http_proxy_pac">Proxy Auto-Config</string>
+ <string name="http_proxy_pac_url">Proxy Auto-Config URL</string>
<string name="http_proxy_port">Proxy port</string>
<string name="illegal_filename_error">Illegal file name ā€œ%sā€</string>
<string name="import_error">Unable to import tunnel: %s</string>