mirror of
https://github.com/karasevm/PrivateDNSAndroid.git
synced 2025-06-28 20:29:56 +00:00
Cleanup
This commit is contained in:
parent
ca3574c427
commit
baff35d7b0
4 changed files with 39 additions and 43 deletions
|
@ -2,18 +2,15 @@ package ru.karasevm.privatednstoggle
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import ru.karasevm.privatednstoggle.databinding.DialogAddBinding
|
import ru.karasevm.privatednstoggle.databinding.DialogAddBinding
|
||||||
|
|
||||||
|
|
||||||
class AddServerDialogFragment() : DialogFragment() {
|
class AddServerDialogFragment : DialogFragment() {
|
||||||
// Use this instance of the interface to deliver action events
|
// Use this instance of the interface to deliver action events
|
||||||
internal lateinit var listener: NoticeDialogListener
|
private lateinit var listener: NoticeDialogListener
|
||||||
|
|
||||||
private var _binding: DialogAddBinding? = null
|
private var _binding: DialogAddBinding? = null
|
||||||
|
|
||||||
|
@ -50,7 +47,7 @@ class AddServerDialogFragment() : DialogFragment() {
|
||||||
return activity?.let {
|
return activity?.let {
|
||||||
val builder = AlertDialog.Builder(it)
|
val builder = AlertDialog.Builder(it)
|
||||||
// Get the layout inflater
|
// Get the layout inflater
|
||||||
val inflater = requireActivity().layoutInflater;
|
val inflater = requireActivity().layoutInflater
|
||||||
_binding = DialogAddBinding.inflate(inflater)
|
_binding = DialogAddBinding.inflate(inflater)
|
||||||
|
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
@ -59,17 +56,17 @@ class AddServerDialogFragment() : DialogFragment() {
|
||||||
builder.setTitle(R.string.add_server)
|
builder.setTitle(R.string.add_server)
|
||||||
.setView(view)
|
.setView(view)
|
||||||
// Add action buttons
|
// Add action buttons
|
||||||
.setPositiveButton(R.string.add,
|
.setPositiveButton(R.string.add
|
||||||
DialogInterface.OnClickListener { _, _ ->
|
) { _, _ ->
|
||||||
listener.onDialogPositiveClick(
|
listener.onDialogPositiveClick(
|
||||||
this,
|
this,
|
||||||
binding.editTextServerAddr.text.toString()
|
binding.editTextServerAddr.text.toString()
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
.setNegativeButton(R.string.cancel,
|
.setNegativeButton(R.string.cancel
|
||||||
DialogInterface.OnClickListener { _, _ ->
|
) { _, _ ->
|
||||||
getDialog()?.cancel()
|
dialog?.cancel()
|
||||||
})
|
}
|
||||||
builder.create()
|
builder.create()
|
||||||
} ?: throw IllegalStateException("Activity cannot be null")
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,14 @@ package ru.karasevm.privatednstoggle
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
|
|
||||||
|
|
||||||
class DeleteServerDialogFragment(val position: Int): DialogFragment() {
|
class DeleteServerDialogFragment(private val position: Int): DialogFragment() {
|
||||||
// Use this instance of the interface to deliver action events
|
// Use this instance of the interface to deliver action events
|
||||||
internal lateinit var listener: NoticeDialogListener
|
private lateinit var listener: NoticeDialogListener
|
||||||
|
|
||||||
/* The activity that creates an instance of this dialog fragment must
|
/* The activity that creates an instance of this dialog fragment must
|
||||||
* implement this interface in order to receive event callbacks.
|
* implement this interface in order to receive event callbacks.
|
||||||
|
@ -35,19 +34,16 @@ class DeleteServerDialogFragment(val position: Int): DialogFragment() {
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
return activity?.let {
|
return activity?.let {
|
||||||
val builder = AlertDialog.Builder(it)
|
val builder = AlertDialog.Builder(it)
|
||||||
// Get the layout inflater
|
|
||||||
val inflater = requireActivity().layoutInflater;
|
|
||||||
// Inflate and set the layout for the dialog
|
|
||||||
// Pass null as the parent view because its going in the dialog layout
|
|
||||||
builder.setMessage(R.string.delete_question)
|
builder.setMessage(R.string.delete_question)
|
||||||
.setPositiveButton(R.string.delete,
|
.setPositiveButton(R.string.delete
|
||||||
DialogInterface.OnClickListener { _, _ ->
|
) { _, _ ->
|
||||||
listener.onDialogPositiveClick(this, position)
|
listener.onDialogPositiveClick(this, position)
|
||||||
})
|
}
|
||||||
.setNegativeButton(R.string.cancel,
|
.setNegativeButton(R.string.cancel
|
||||||
DialogInterface.OnClickListener { _, _ ->
|
) { _, _ ->
|
||||||
getDialog()?.cancel()
|
dialog?.cancel()
|
||||||
})
|
}
|
||||||
// Create the AlertDialog object and return it
|
// Create the AlertDialog object and return it
|
||||||
builder.create()
|
builder.create()
|
||||||
} ?: throw IllegalStateException("Activity cannot be null")
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
|
|
|
@ -10,19 +10,19 @@ import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
|
|
||||||
const val DNS_MODE_OFF = "off";
|
const val DNS_MODE_OFF = "off"
|
||||||
const val DNS_MODE_AUTO = "opportunistic";
|
const val DNS_MODE_AUTO = "opportunistic"
|
||||||
const val DNS_MODE_PRIVATE = "hostname";
|
const val DNS_MODE_PRIVATE = "hostname"
|
||||||
|
|
||||||
class DnsTileService : TileService() {
|
class DnsTileService : TileService() {
|
||||||
|
|
||||||
|
|
||||||
fun checkForPermission(): Boolean {
|
private fun checkForPermission(): Boolean {
|
||||||
if (checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) == PackageManager.PERMISSION_GRANTED) {
|
if (checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) == PackageManager.PERMISSION_GRANTED) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
Toast.makeText(this, R.string.permission_missing, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.permission_missing, Toast.LENGTH_SHORT).show()
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTileAdded() {
|
override fun onTileAdded() {
|
||||||
|
@ -41,7 +41,7 @@ class DnsTileService : TileService() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val dnsMode = Settings.Global.getString(getContentResolver(), "private_dns_mode");
|
val dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
|
||||||
val dnsProvider = Settings.Global.getString(contentResolver, "private_dns_specifier")
|
val dnsProvider = Settings.Global.getString(contentResolver, "private_dns_specifier")
|
||||||
|
|
||||||
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
|
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
|
||||||
|
@ -89,8 +89,11 @@ class DnsTileService : TileService() {
|
||||||
|
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
super.onStartListening()
|
super.onStartListening()
|
||||||
var dnsMode = Settings.Global.getString(getContentResolver(), "private_dns_mode");
|
if (!checkForPermission()) {
|
||||||
Log.d("TEMP", "onStartListening: called " + dnsMode)
|
return
|
||||||
|
}
|
||||||
|
val dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
|
||||||
|
Log.d("TEMP", "onStartListening: called $dnsMode")
|
||||||
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
|
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
|
||||||
refreshTile(
|
refreshTile(
|
||||||
qsTile,
|
qsTile,
|
||||||
|
@ -170,7 +173,7 @@ class DnsTileService : TileService() {
|
||||||
* @return next address
|
* @return next address
|
||||||
*/
|
*/
|
||||||
private fun getNextAddress(currentAddress: String?): String? {
|
private fun getNextAddress(currentAddress: String?): String? {
|
||||||
val sharedPrefs = this.getSharedPreferences("app_prefs", 0);
|
val sharedPrefs = this.getSharedPreferences("app_prefs", 0)
|
||||||
val items = sharedPrefs.getString("dns_servers", "dns.google")!!.split(",").toMutableList()
|
val items = sharedPrefs.getString("dns_servers", "dns.google")!!.split(",").toMutableList()
|
||||||
|
|
||||||
// Fallback if list is empty
|
// Fallback if list is empty
|
||||||
|
|
|
@ -5,7 +5,7 @@ buildscript {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:7.0.0"
|
classpath 'com.android.tools.build:gradle:7.0.1'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue