mirror of
https://github.com/karasevm/PrivateDNSAndroid.git
synced 2025-06-28 20:29:56 +00:00
Adjust tile selection dialog
This commit is contained in:
parent
48bb2698bd
commit
c5f2aed736
2 changed files with 52 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
package ru.karasevm.privatednstoggle
|
package ru.karasevm.privatednstoggle
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -12,7 +13,7 @@ import ru.karasevm.privatednstoggle.utils.PreferenceHelper.defaultPreference
|
||||||
import ru.karasevm.privatednstoggle.utils.PreferenceHelper.dns_servers
|
import ru.karasevm.privatednstoggle.utils.PreferenceHelper.dns_servers
|
||||||
import ru.karasevm.privatednstoggle.utils.PrivateDNSUtils
|
import ru.karasevm.privatednstoggle.utils.PrivateDNSUtils
|
||||||
|
|
||||||
class DNSServerDialogFragment: DialogFragment() {
|
class DNSServerDialogFragment : DialogFragment() {
|
||||||
|
|
||||||
private var _binding: SheetDnsSelectorBinding? = null
|
private var _binding: SheetDnsSelectorBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
@ -35,20 +36,28 @@ class DNSServerDialogFragment: DialogFragment() {
|
||||||
|
|
||||||
sharedPrefs = defaultPreference(requireContext())
|
sharedPrefs = defaultPreference(requireContext())
|
||||||
items = sharedPrefs.dns_servers
|
items = sharedPrefs.dns_servers
|
||||||
if(items[0] == "") {
|
if (items[0] == "") {
|
||||||
items.removeAt(0)
|
items.removeAt(0)
|
||||||
items.add("dns.google")
|
items.add("dns.google")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
items.add(0, resources.getString(R.string.dns_auto))
|
||||||
|
items.add(0, resources.getString(R.string.dns_off))
|
||||||
|
|
||||||
adapter = RecyclerAdapter(items)
|
adapter = RecyclerAdapter(items)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
|
|
||||||
|
|
||||||
|
val startIntent = Intent(context, MainActivity::class.java)
|
||||||
|
|
||||||
builder.setTitle(R.string.select_server)
|
builder.setTitle(R.string.select_server)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.setPositiveButton(R.string.done
|
.setPositiveButton(
|
||||||
|
R.string.done
|
||||||
) { _, _ ->
|
) { _, _ ->
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
.setNeutralButton(R.string.open_app) { _, _ -> context?.startActivity(startIntent) }
|
||||||
builder.create()
|
builder.create()
|
||||||
} ?: throw IllegalStateException("Activity cannot be null")
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
}
|
}
|
||||||
|
@ -56,25 +65,46 @@ class DNSServerDialogFragment: DialogFragment() {
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
val dnsMode = PrivateDNSUtils.getPrivateMode(requireActivity().contentResolver)
|
val dnsMode = PrivateDNSUtils.getPrivateMode(requireActivity().contentResolver)
|
||||||
binding.autoSwitch.isChecked = dnsMode.lowercase() == "opportunistic"
|
|
||||||
|
|
||||||
adapter.onItemClick = { position ->
|
adapter.onItemClick = { position ->
|
||||||
binding.autoSwitch.isChecked = false
|
when (position) {
|
||||||
val server = items[position]
|
0 -> {
|
||||||
PrivateDNSUtils.setPrivateMode(requireActivity().contentResolver, PrivateDNSUtils.DNS_MODE_PRIVATE)
|
PrivateDNSUtils.setPrivateMode(
|
||||||
PrivateDNSUtils.setPrivateProvider(requireActivity().contentResolver, server)
|
requireActivity().contentResolver,
|
||||||
Toast.makeText(context, "DNS Server Set", Toast.LENGTH_SHORT).show()
|
PrivateDNSUtils.DNS_MODE_OFF
|
||||||
|
)
|
||||||
|
Toast.makeText(context, R.string.set_to_off_toast, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
1 -> {
|
||||||
|
PrivateDNSUtils.setPrivateMode(
|
||||||
|
requireActivity().contentResolver,
|
||||||
|
PrivateDNSUtils.DNS_MODE_AUTO
|
||||||
|
)
|
||||||
|
Toast.makeText(context, R.string.set_to_auto_toast, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
val server = items[position]
|
||||||
|
PrivateDNSUtils.setPrivateMode(
|
||||||
|
requireActivity().contentResolver,
|
||||||
|
PrivateDNSUtils.DNS_MODE_PRIVATE
|
||||||
|
)
|
||||||
|
PrivateDNSUtils.setPrivateProvider(
|
||||||
|
requireActivity().contentResolver,
|
||||||
|
server
|
||||||
|
)
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
getString(R.string.set_to_provider_toast, server),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.autoSwitch.setOnClickListener {
|
|
||||||
if(binding.autoSwitch.isChecked) {
|
|
||||||
PrivateDNSUtils.setPrivateMode(requireActivity().contentResolver, PrivateDNSUtils.DNS_MODE_AUTO)
|
|
||||||
Toast.makeText(context, "DNS Server Set to Auto", Toast.LENGTH_SHORT).show()
|
|
||||||
} else {
|
|
||||||
PrivateDNSUtils.setPrivateMode(requireActivity().contentResolver, PrivateDNSUtils.DNS_MODE_PRIVATE)
|
|
||||||
Toast.makeText(context, "DNS Server Set", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -24,4 +24,8 @@
|
||||||
<string name="auto_option_only_off">Only off</string>
|
<string name="auto_option_only_off">Only off</string>
|
||||||
<string name="auto_option_only_auto">Only auto</string>
|
<string name="auto_option_only_auto">Only auto</string>
|
||||||
<string name="auto_option_off_and_auto">Off and auto</string>
|
<string name="auto_option_off_and_auto">Off and auto</string>
|
||||||
|
<string name="open_app">Open app</string>
|
||||||
|
<string name="set_to_off_toast">Private DNS turned off</string>
|
||||||
|
<string name="set_to_auto_toast">Private DNS set to auto</string>
|
||||||
|
<string name="set_to_provider_toast">Private DNS set to %1$s</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue