This commit is contained in:
Maksim Karasev 2021-08-20 14:55:45 +03:00
parent ca3574c427
commit baff35d7b0
4 changed files with 39 additions and 43 deletions

View file

@ -2,18 +2,15 @@ package ru.karasevm.privatednstoggle
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import ru.karasevm.privatednstoggle.databinding.DialogAddBinding
class AddServerDialogFragment() : DialogFragment() {
class AddServerDialogFragment : DialogFragment() {
// 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
@ -50,7 +47,7 @@ class AddServerDialogFragment() : DialogFragment() {
return activity?.let {
val builder = AlertDialog.Builder(it)
// Get the layout inflater
val inflater = requireActivity().layoutInflater;
val inflater = requireActivity().layoutInflater
_binding = DialogAddBinding.inflate(inflater)
val view = binding.root
@ -59,17 +56,17 @@ class AddServerDialogFragment() : DialogFragment() {
builder.setTitle(R.string.add_server)
.setView(view)
// Add action buttons
.setPositiveButton(R.string.add,
DialogInterface.OnClickListener { _, _ ->
listener.onDialogPositiveClick(
this,
binding.editTextServerAddr.text.toString()
)
})
.setNegativeButton(R.string.cancel,
DialogInterface.OnClickListener { _, _ ->
getDialog()?.cancel()
})
.setPositiveButton(R.string.add
) { _, _ ->
listener.onDialogPositiveClick(
this,
binding.editTextServerAddr.text.toString()
)
}
.setNegativeButton(R.string.cancel
) { _, _ ->
dialog?.cancel()
}
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}

View file

@ -2,15 +2,14 @@ package ru.karasevm.privatednstoggle
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
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
internal lateinit var listener: NoticeDialogListener
private lateinit var listener: NoticeDialogListener
/* The activity that creates an instance of this dialog fragment must
* 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 {
return activity?.let {
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)
.setPositiveButton(R.string.delete,
DialogInterface.OnClickListener { _, _ ->
listener.onDialogPositiveClick(this, position)
})
.setNegativeButton(R.string.cancel,
DialogInterface.OnClickListener { _, _ ->
getDialog()?.cancel()
})
.setPositiveButton(R.string.delete
) { _, _ ->
listener.onDialogPositiveClick(this, position)
}
.setNegativeButton(R.string.cancel
) { _, _ ->
dialog?.cancel()
}
// Create the AlertDialog object and return it
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")

View file

@ -10,19 +10,19 @@ import android.util.Log
import android.widget.Toast
const val DNS_MODE_OFF = "off";
const val DNS_MODE_AUTO = "opportunistic";
const val DNS_MODE_PRIVATE = "hostname";
const val DNS_MODE_OFF = "off"
const val DNS_MODE_AUTO = "opportunistic"
const val DNS_MODE_PRIVATE = "hostname"
class DnsTileService : TileService() {
fun checkForPermission(): Boolean {
private fun checkForPermission(): Boolean {
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()
return false;
return false
}
override fun onTileAdded() {
@ -41,7 +41,7 @@ class DnsTileService : TileService() {
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")
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
@ -89,8 +89,11 @@ class DnsTileService : TileService() {
override fun onStartListening() {
super.onStartListening()
var dnsMode = Settings.Global.getString(getContentResolver(), "private_dns_mode");
Log.d("TEMP", "onStartListening: called " + dnsMode)
if (!checkForPermission()) {
return
}
val dnsMode = Settings.Global.getString(contentResolver, "private_dns_mode")
Log.d("TEMP", "onStartListening: called $dnsMode")
if (dnsMode.equals(DNS_MODE_OFF, ignoreCase = true)) {
refreshTile(
qsTile,
@ -170,7 +173,7 @@ class DnsTileService : TileService() {
* @return next address
*/
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()
// Fallback if list is empty

View file

@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
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"
// NOTE: Do not place your application dependencies here; they belong