Commit 3e9b3413 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Code cleanup

parent 3b3d42ba
......@@ -51,7 +51,7 @@ import java.util.logging.Level
*/
fun Context.canUseFingerprintAuthentication(): Boolean {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return false
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false
val mgr = getSystemService(Context.FINGERPRINT_SERVICE) as? FingerprintManager
if(mgr == null || !mgr.isHardwareDetected) return false
else if(!mgr.hasEnrolledFingerprints()) return false
......
......@@ -46,13 +46,13 @@ fun showPrivacyPolicyDialog(context: Context) {
fun showInfoTextDialog(context:Context, title:String, text:String,
positiveButton:Pair<String, (DialogInterface, Int) -> Unit>? = null,
negativeButton:Pair<String, (DialogInterface, Int) -> Unit>? = null,
neutralButton:Pair<String, ((DialogInterface, Int) -> Unit)?>? = context.getString(android.R.string.ok) to null): androidx.appcompat.app.AlertDialog {
var stringWithLinks = SpannableString(text)
neutralButton:Pair<String, ((DialogInterface, Int) -> Unit)?>? = context.getString(android.R.string.ok) to null): AlertDialog {
val stringWithLinks = SpannableString(text)
Linkify.addLinks(stringWithLinks, Linkify.ALL)
val span = Html.fromHtml(stringWithLinks.toString().replace("\n", "<br>"))
val dialogBuilder = androidx.appcompat.app.AlertDialog.Builder(context, context.getPreferences().theme.dialogStyle)
val dialogBuilder = AlertDialog.Builder(context, context.getPreferences().theme.dialogStyle)
.setTitle(title)
.setMessage(span)
if(neutralButton != null) dialogBuilder.setNeutralButton(neutralButton.first, neutralButton.second)
......
......@@ -44,7 +44,7 @@ class BackgroundVpnConfigureActivity : BaseActivity() {
companion object {
const val extraKeyServerConfig = "server_config"
const val extraKeyServerType = "config_type"
private const val extraKeyServerType = "config_type"
private const val VPN_REQUEST_CODE = 1
fun prepareVpn(context: Context, serverInfo:DnsServerInformation<*>? = null) {
......@@ -93,7 +93,7 @@ class BackgroundVpnConfigureActivity : BaseActivity() {
return null
}
fun getServerInfoType(serverInfo: DnsServerInformation<*>): String {
private fun getServerInfoType(serverInfo: DnsServerInformation<*>): String {
return when {
serverInfo is HttpsDnsServerInformation -> "https"
serverInfo.servers.any {
......@@ -103,7 +103,7 @@ class BackgroundVpnConfigureActivity : BaseActivity() {
}
}
fun serverInfoFromJson(json:String, type:String):DnsServerInformation<*> {
private fun serverInfoFromJson(json:String, type:String):DnsServerInformation<*> {
TLSUpstreamAddress
HttpsUpstreamAddress
return when(type) {
......@@ -114,7 +114,7 @@ class BackgroundVpnConfigureActivity : BaseActivity() {
}
}
var requestTime: Long = -1
private var requestTime: Long = -1
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(getPreferences().theme.dialogStyle)
......
......@@ -5,7 +5,6 @@ import android.content.Intent
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.frostnerd.encrypteddnstunnelproxy.AbstractHttpsDNSHandle
......@@ -98,7 +97,7 @@ class MainActivity : NavigationDrawerActivity() {
getPreferences().totalAppLaunches += 1
if(getPreferences().totalAppLaunches >= 3 && getPreferences().shouldShowCrashReportingConsentDialog()) {
CrashReportingEnableDialog(this, onConsentGiven = {
val bar = Snackbar.make(findViewById<View>(android.R.id.content), R.string.crashreporting_thankyou, Snackbar.LENGTH_INDEFINITE)
val bar = Snackbar.make(findViewById(android.R.id.content), R.string.crashreporting_thankyou, Snackbar.LENGTH_INDEFINITE)
bar.setAction(R.string.crashreporting_thankyou_gotit) {
bar.dismiss()
}.show()
......@@ -220,10 +219,6 @@ class MainActivity : NavigationDrawerActivity() {
}
}
override fun onDestroy() {
super.onDestroy()
}
override fun onBackPressed() {
val fragment = currentFragment
if (fragment != null && fragment is BackpressFragment) {
......@@ -238,7 +233,7 @@ class MainActivity : NavigationDrawerActivity() {
val openStore = {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")))
} catch (e: android.content.ActivityNotFoundException) {
} catch (e: ActivityNotFoundException) {
try {
startActivity(
Intent(
......
......@@ -172,16 +172,16 @@ class SpeedTestActivity : BaseActivity() {
runOnUiThread {
startTest.text = "0/${testsLeft.size}"
}
testsLeft.forEach {
testsLeft.forEach { pendingTest ->
if(testJob?.isCancelled == false) {
it.started = true
log("Running SpeedTest for ${it.server.name}")
val res = DnsSpeedTest(it.server, 500, 750) { line ->
pendingTest.started = true
log("Running SpeedTest for ${pendingTest.server.name}")
val res = DnsSpeedTest(pendingTest.server, 500, 750) { line ->
log(line)
}.runTest(3)
if (res != null) it.latency = res
else it.error = true
if (res != null) pendingTest.latency = res
else pendingTest.error = true
testResults!!.sortBy {
it.latency ?: Integer.MAX_VALUE
......
......@@ -23,9 +23,9 @@ import kotlinx.coroutines.*
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class CachedResponseRepository(val cachedResponseDao: CachedResponseDao) {
class CachedResponseRepository(private val cachedResponseDao: CachedResponseDao) {
@Insert
suspend fun insertAll(cachedResponses:List<CachedResponse>): Job {
fun insertAll(cachedResponses:List<CachedResponse>): Job {
return GlobalScope.launch {
cachedResponseDao.insertAll(cachedResponses)
}
......
......@@ -29,7 +29,7 @@ import java.io.FileWriter
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class DnsQueryRepository(val dnsQueryDao: DnsQueryDao) {
class DnsQueryRepository(private val dnsQueryDao: DnsQueryDao) {
fun updateAsync(dnsQuery: DnsQuery): Job {
return GlobalScope.launch {
......
......@@ -25,7 +25,7 @@ import kotlinx.coroutines.launch
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class DnsRuleRepository(val dnsRuleDao: DnsRuleDao) {
class DnsRuleRepository(private val dnsRuleDao: DnsRuleDao) {
fun updateAsync(dnsRule: DnsRule, coroutineScope: CoroutineScope = GlobalScope) {
coroutineScope.launch {
......
......@@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
*
* development@frostnerd.com
*/
class HostSourceRepository(val hostSourceDao: HostSourceDao) {
class HostSourceRepository(private val hostSourceDao: HostSourceDao) {
@Delete
fun deleteAsync(hostSource: HostSource, coroutineScope: CoroutineScope = GlobalScope) {
......
......@@ -198,7 +198,7 @@ class AppChoosalDialog(
inner class AppViewHolder(itemView: View) : BaseViewHolder(itemView) {
val icon = itemView.findViewById<ImageView>(R.id.icon)
val title = itemView.findViewById<TextView>(R.id.app_name)
val checkBox = itemView.findViewById<CheckBox>(R.id.checkbox)
private val checkBox = itemView.findViewById<CheckBox>(R.id.checkbox)
init {
checkBox.setOnCheckedChangeListener { _, isChecked ->
......
......@@ -46,7 +46,7 @@ class ChangelogDialog(context: Context, versionToStartFrom:Int, val showOptOut:B
}
}
}
val changes = TreeMap<Int, List<String>>()
private val changes = TreeMap<Int, List<String>>()
init {
val resources = context.resources
......
......@@ -91,7 +91,7 @@ class CrashReportingEnableDialog(
override fun destroy() {
}
private inner class UsedDataListAdapter() : BaseExpandableListAdapter() {
private inner class UsedDataListAdapter : BaseExpandableListAdapter() {
private val titles = context.resources.getStringArray(R.array.dialog_crashreportingusages_data)
private val children = listOf(
context.resources.getStringArray(R.array.dialog_crashreportingusages_data_user),
......
......@@ -50,7 +50,7 @@ class NewServerDialog(
onServerAdded: (serverInfo: DnsServerInformation<*>) -> Unit,
server: UserServerConfiguration? = null
) : BaseDialog(context, context.getPreferences().theme.dialogStyle) {
private var validationRegex = NewServerDialog.SERVER_URL_REGEX
private var validationRegex = SERVER_URL_REGEX
companion object {
val SERVER_URL_REGEX =
......@@ -120,7 +120,7 @@ class NewServerDialog(
serverType.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}
override fun onItemSelected(parent: AdapterView<*>?, v: View?, position: Int, id: Long) {
validationRegex = if (position == 0) NewServerDialog.SERVER_URL_REGEX else NewServerDialog.TLS_REGEX
validationRegex = if (position == 0) SERVER_URL_REGEX else TLS_REGEX
dnsOverHttps = position == 0
setHintAndTitle(view, dnsOverHttps, title)
primaryServer.text = primaryServer.text
......@@ -275,7 +275,7 @@ class NewServerDialog(
else TLSUpstreamAddress(parsedHost)
}
fun addUrlTextWatcher(input: TextInputLayout, editText: TextInputEditText, emptyAllowed: Boolean) {
private fun addUrlTextWatcher(input: TextInputLayout, editText: TextInputEditText, emptyAllowed: Boolean) {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
val valid =
......@@ -297,7 +297,7 @@ class NewServerDialog(
})
}
fun inputsValid(): Boolean = serverNameWrap.error == null &&
private fun inputsValid(): Boolean = serverNameWrap.error == null &&
primaryServerWrap.error == null &&
secondaryServerWrap.error == null
......
......@@ -41,7 +41,7 @@ import kotlin.random.Random
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class QueryGeneratorDialog(context: Context):AlertDialog(context, context.getPreferences().theme.dialogStyle){
val websiteDomains = setOf("bild.de", "washingtonpost.com", "cnn.com", "bbc.com", "nytimes.com", "huffingtonpost.com",
private val websiteDomains = setOf("bild.de", "washingtonpost.com", "cnn.com", "bbc.com", "nytimes.com", "huffingtonpost.com",
"reuters.com", "abcnews.go.com", "timesofindia.indiatimes.com", "theguardian.com", "bloomberg.com",
"Oneindia.com", "News18.com", "Hindustantimes.com", "Firstpost.com", "Indianexpress.com",
"Manoramaonline.com",
......@@ -220,7 +220,7 @@ class QueryGeneratorDialog(context: Context):AlertDialog(context, context.getPre
"chubbiesshorts.com", "ritual.com", "sugarbearhair.com", "thirdlove.com", "welleco.com", "mpgsport.com",
"viator.com", "lonelyplanet.com", "homeaway.com", "hotwire.com", "orbitz.com", "travelocity.com"
)
val websiteUrls = setOf("https://www.heise.de/newsticker/meldung/10-Jahre-Bitcoin-Am-Anfang-war-die-Blockchain-4262899.html",
private val websiteUrls = setOf("https://www.heise.de/newsticker/meldung/10-Jahre-Bitcoin-Am-Anfang-war-die-Blockchain-4262899.html",
"https://www.heise.de/newsticker/meldung/Gehackte-Daten-Politiker-beklagen-schweren-Angriff-auf-die-Demokratie-4265847.html",
"https://www.golem.de/news/xbox-microsoft-arbeitet-an-force-feedback-tasten-1901-138510.html",
"http://www.spiegel.de/plus/platz-da-jungs-a-00000000-0002-0001-0000-000161665893",
......
......@@ -14,7 +14,6 @@ import com.frostnerd.encrypteddnstunnelproxy.tls.AbstractTLSDnsHandle
import com.frostnerd.lifecyclemanagement.BaseDialog
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.util.preferences.UserServerConfiguration
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.dialog_server_configuration.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
......@@ -46,8 +45,8 @@ class ServerChoosalDialog(
BaseDialog(context, context.getPreferences().theme.dialogStyle) {
private var populationJob: Job? = null
private var currentSelectedServer: DnsServerInformation<*>
lateinit var defaultConfig: List<DnsServerInformation<*>>
lateinit var userConfig: List<UserServerConfiguration>
private lateinit var defaultConfig: List<DnsServerInformation<*>>
private lateinit var userConfig: List<UserServerConfiguration>
init {
val view = layoutInflater.inflate(R.layout.dialog_server_configuration, null, false)
......@@ -115,8 +114,8 @@ class ServerChoosalDialog(
private fun loadServerData(tls: Boolean) {
if (tls) {
val hiddenServers = context.getPreferences().removedDefaultDoTServers
defaultConfig = AbstractTLSDnsHandle.waitUntilKnownServersArePopulated {
it.filter {
defaultConfig = AbstractTLSDnsHandle.waitUntilKnownServersArePopulated { servers ->
servers.filter {
it.key !in hiddenServers
}.values.toList()
}
......@@ -125,8 +124,8 @@ class ServerChoosalDialog(
}.toList()
} else {
val hiddenServers = context.getPreferences().removedDefaultDoHServers
defaultConfig = AbstractHttpsDNSHandle.waitUntilKnownServersArePopulated {
it.filter {
defaultConfig = AbstractHttpsDNSHandle.waitUntilKnownServersArePopulated {servers ->
servers.filter {
it.key !in hiddenServers
}.values.toList()
}
......@@ -169,7 +168,7 @@ class ServerChoosalDialog(
}
}
fun markCurrentSelectedServer() {
private fun markCurrentSelectedServer() {
for (id in 0 until knownServersGroup.childCount) {
val child = knownServersGroup.getChildAt(id) as RadioButton
val payload = child.tag
......
......@@ -78,7 +78,7 @@ class ServerImportDialog(context: Context, loadedServers: List<DnsServerInformat
checkbox.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) selectedServerPositions.add(itemView.tag as Int)
else selectedServerPositions.remove(itemView.tag as Int)
getButton(DialogInterface.BUTTON_POSITIVE).isEnabled = !selectedServerPositions.isEmpty()
getButton(DialogInterface.BUTTON_POSITIVE).isEnabled = selectedServerPositions.isNotEmpty()
}
itemView
}
......@@ -104,10 +104,10 @@ class ServerImportDialog(context: Context, loadedServers: List<DnsServerInformat
class ServerViewHolder(itemView: View) : BaseViewHolder(itemView) {
val name: TextView = itemView.findViewById(R.id.name)
val urls = itemView.findViewById<TextView>(R.id.urls)
val capabilities = itemView.findViewById<TextView>(R.id.capabilities)
private val urls = itemView.findViewById<TextView>(R.id.urls)
private val capabilities = itemView.findViewById<TextView>(R.id.capabilities)
val selected = itemView.findViewById<CheckBox>(R.id.checkbox)
val serverType = itemView.findViewById<TextView>(R.id.serverType)
private val serverType = itemView.findViewById<TextView>(R.id.serverType)
override fun destroy() {
}
......
......@@ -35,7 +35,7 @@ import java.util.*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class AboutFragment : Fragment() {
var queryGenStepOne = false
private var queryGenStepOne = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_about, container, false)
......
......@@ -591,7 +591,7 @@ class DnsRuleFragment : Fragment() {
return getDefaultHostSources(versionStart..Integer.MAX_VALUE)
}
fun getDefaultHostSources(versionRange:IntRange): List<HostSource> {
private fun getDefaultHostSources(versionRange:IntRange): List<HostSource> {
if(versionRange.first > latestSourcesVersion) return emptyList()
return defaultHostSources.filter {
it.key in versionRange
......
......@@ -138,7 +138,7 @@ class MainFragment : Fragment() {
if (vpnStateReceiver != null) requireContext().unregisterLocalReceiver(vpnStateReceiver!!)
}
fun startVpn() {
private fun startVpn() {
val prepare = VpnService.prepare(requireContext()).apply {
this?.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
}
......
......@@ -94,7 +94,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
)
}
fun findPreference(key:String): Preference {
private fun findPreference(key:String): Preference {
return super.findPreference<Preference>(key)!!
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment