Skip to content
Permalink
Browse files

migrate dns fallback and reports switch to dns changer

  • Loading branch information...
kar committed Mar 5, 2019
1 parent 82a6595 commit 9f7eae09ec8f263e6ae6da52d2bc944845900c42
@@ -19,6 +19,7 @@ fun newFlavorModule(ctx: Context): Kodein.Module {
DashFilterWhitelist(ctx).activate(true),
NotificationDashKeepAlive(ctx).activate(true),
AutoStartDash(ctx).activate(true),
DnsSettingsDash(ctx).activate(true),
PatronDash(lazy).activate(false),
PatronAboutDash(lazy).activate(false),
DonateDash(lazy).activate(false),
@@ -19,6 +19,7 @@ import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch
import org.acra.ACRA
import org.blokada.R
import tunnel.DnsConfigView
import tunnel.TunnelConfigView
import java.net.URL

@@ -273,6 +274,29 @@ class SettingsDash(
}
}

class DnsSettingsDash(
val ctx: Context,
val d: gs.property.Device = ctx.inject().instance()
) : Dash(
"main_settings_dns",
icon = R.drawable.ic_tune,
text = ctx.getString(R.string.main_settings_text),
hasView = true
) {

override fun createView(parent: Any): Any? {
return createConfigView(parent as ViewGroup)
}

private var configView: DnsConfigView? = null

private fun createConfigView(parent: ViewGroup): DnsConfigView {
val ctx = parent.context
configView = LayoutInflater.from(ctx).inflate(R.layout.view_dns_config, parent, false) as DnsConfigView
return configView!!
}
}

class OpenInBrowserDash(
val ctx: Context,
val url: IProperty<URL>
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<tunnel.DnsConfigView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="8dp">

<!-- DNS Fallback -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@color/colorBackgroundThird"
android:orientation="vertical"
android:padding="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_server"
android:tint="@color/colorActive" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:singleLine="true"
android:text="@string/tunnel_config_fallback_title"
android:textColor="@color/colorActive"
android:textStyle="bold" />

</LinearLayout>

<gs.presentation.SwitchCompatView
android:id="@+id/switch_fallback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:theme="@style/Switch" />

</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/tunnel_config_fallback_description"
android:textColor="@color/colorText"
android:textColorLink="@color/colorAccent" />

</LinearLayout>

<!-- Reports -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackgroundThird"
android:orientation="vertical"
android:padding="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_code_tags"
android:tint="@color/colorActive" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:singleLine="true"
android:text="@string/tunnel_config_reports_title"
android:textColor="@color/colorActive"
android:textStyle="bold" />

</LinearLayout>

<gs.presentation.SwitchCompatView
android:id="@+id/switch_reports"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:theme="@style/Switch" />

</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/tunnel_config_reports_description"
android:textColor="@color/colorText"
android:textColorLink="@color/colorAccent" />

</LinearLayout>

</LinearLayout>

</tunnel.DnsConfigView>
@@ -560,7 +560,7 @@
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_code_tags"
android:src="@drawable/ic_server"
android:tint="@color/colorActive" />

<LinearLayout
@@ -0,0 +1,48 @@
package tunnel

import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
import com.github.salomonbrys.kodein.instance
import core.Dns
import gs.environment.inject
import gs.presentation.SwitchCompatView
import gs.property.Device
import org.blokada.R


class DnsConfigView(
ctx: Context,
attributeSet: AttributeSet
) : ScrollView(ctx, attributeSet) {

val reports by lazy { ctx.inject().instance<Device>().reports }
val fallback by lazy { ctx.inject().instance<Dns>().fallback }

private val reportsSwitch by lazy { findViewById<SwitchCompatView>(R.id.switch_reports) }
private val fallbackSwitch by lazy { findViewById<SwitchCompatView>(R.id.switch_fallback) }

override fun onFinishInflate() {
super.onFinishInflate()
reportsSwitch.setOnCheckedChangeListener { _, isChecked ->
reports %= isChecked }
fallbackSwitch.setOnCheckedChangeListener { _, isChecked ->
fallback %= isChecked }

syncView()

reports.doOnUiWhenSet().then {
reportsSwitch.isChecked = reports()
}

fallback.doOnUiWhenSet().then {
fallbackSwitch.isChecked = fallback()
}
}

private fun syncView() {
reportsSwitch.isChecked = reports()
fallbackSwitch.isChecked = fallback()
}

}

0 comments on commit 9f7eae0

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.