Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate dns fallback and reports switch to dns changer
- Loading branch information
Showing
5 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
|
||
} |