summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-04-15 19:19:12 +0200
committerArne Schwabe <arne@rfc2549.org>2021-04-15 19:19:12 +0200
commit4c7280b50e4fe044f39c42fadf1b3f1789c99658 (patch)
tree72dbdb9ba5479a8583aa9f635ed1df54202b8ab0
parent8d0f9d2abadbfd516b105294720f379f77fd9877 (diff)
Update gradle files, remove anko dependency
-rw-r--r--build.gradle.kts13
-rw-r--r--main/build.gradle.kts22
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt83
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/PackageAdapter.kt6
-rw-r--r--main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt2
5 files changed, 80 insertions, 46 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 8a42cedc..75144b16 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -5,20 +5,25 @@
buildscript {
+ var kotlin_version: String by extra
+ var fragment_version: String by extra
+
+ kotlin_version = "1.4.32"
+ fragment_version = "1.3.2"
repositories {
google()
- jcenter()
+ mavenCentral()
}
dependencies {
- classpath("com.android.tools.build:gradle:4.1.2")
- classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
+ classpath("com.android.tools.build:gradle:4.1.3")
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}
allprojects {
repositories {
google()
- jcenter()
+ mavenCentral()
maven(url = "https://jitpack.io")
}
}
diff --git a/main/build.gradle.kts b/main/build.gradle.kts
index 81445e0d..b9e98bbf 100644
--- a/main/build.gradle.kts
+++ b/main/build.gradle.kts
@@ -9,8 +9,7 @@ plugins {
id("com.android.application")
id("checkstyle")
- kotlin("android")
- kotlin("android.extensions")
+ id("kotlin-android")
}
android {
@@ -165,10 +164,10 @@ dependencies {
val preferenceVersion = "1.1.1"
val coreVersion = "1.2.0"
val materialVersion = "1.1.0"
- val fragment_version = "1.2.4"
+ val fragment_version = "1.3.2"
- implementation("androidx.annotation:annotation:1.1.0")
+ implementation("androidx.annotation:annotation:1.2.0")
implementation("androidx.core:core:$coreVersion")
// Is there a nicer way to do this?
@@ -181,16 +180,19 @@ dependencies {
dependencies.add("uiImplementation", "com.squareup.okhttp3:okhttp:3.2.0")
dependencies.add("uiImplementation", "androidx.core:core:$coreVersion")
dependencies.add("uiImplementation", "androidx.core:core-ktx:$coreVersion")
- dependencies.add("uiImplementation", "org.jetbrains.anko:anko-commons:0.10.4")
dependencies.add("uiImplementation", "androidx.fragment:fragment-ktx:$fragment_version")
dependencies.add("uiImplementation", "androidx.preference:preference:$preferenceVersion")
dependencies.add("uiImplementation", "androidx.preference:preference-ktx:$preferenceVersion")
dependencies.add("uiImplementation", "com.google.android.material:material:$materialVersion")
dependencies.add("uiImplementation", "androidx.webkit:webkit:1.2.0")
+ dependencies.add("uiImplementation", "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1")
+ dependencies.add("uiImplementation", "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
- testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72")
- testImplementation("junit:junit:4.13")
- testImplementation("org.mockito:mockito-core:3.3.3")
- testImplementation("org.robolectric:robolectric:4.3.1")
- testImplementation("androidx.test:core:1.2.0")
+
+
+ testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32")
+ testImplementation("junit:junit:4.13.2")
+ testImplementation("org.mockito:mockito-core:3.9.0")
+ testImplementation("org.robolectric:robolectric:4.5.1")
+ testImplementation("androidx.test:core:1.3.0")
}
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt
index 855caae6..71d1ee7c 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt
@@ -16,17 +16,22 @@ import android.text.InputType
import android.util.Base64
import android.util.Base64.NO_WRAP
import android.util.Log
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.EditText
import android.widget.Toast
import androidx.fragment.app.DialogFragment
+import androidx.lifecycle.lifecycleScope
import de.blinkt.openvpn.R
import de.blinkt.openvpn.activities.ConfigConverter
import de.blinkt.openvpn.core.Preferences
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import okhttp3.*
import okhttp3.internal.tls.OkHostnameVerifier
-import org.jetbrains.anko.doAsync
-import org.jetbrains.anko.runOnUiThread
import java.io.IOException
import java.security.MessageDigest
import java.security.cert.CertPathValidatorException
@@ -86,6 +91,8 @@ class ImportASConfig : DialogFragment() {
private lateinit var asServername: EditText
private lateinit var asUsername: EditText
private lateinit var asPassword: EditText
+ private lateinit var dialogView: View
+
internal fun getHostNameVerifier(prefs: SharedPreferences): HostnameVerifier {
@@ -210,67 +217,85 @@ class ImportASConfig : DialogFragment() {
return asUri
}
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ return dialogView
+ }
+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val inflater = requireActivity().layoutInflater
- val view = inflater.inflate(R.layout.import_as_config, null);
+ dialogView = inflater.inflate(R.layout.import_as_config, null);
val builder = AlertDialog.Builder(requireContext())
- builder.setView(view)
-
-
+ builder.setView(dialogView)
builder.setTitle(R.string.import_from_as)
- asServername = view.findViewById(R.id.as_servername)
- asUsername = view.findViewById(R.id.username)
- asPassword = view.findViewById(R.id.password)
- asUseAutlogin = view.findViewById(R.id.request_autologin)
+ asServername = dialogView.findViewById(R.id.as_servername)
+ asUsername = dialogView.findViewById(R.id.username)
+ asPassword = dialogView.findViewById(R.id.password)
+ asUseAutlogin = dialogView.findViewById(R.id.request_autologin)
builder.setPositiveButton(R.string.import_config, null)
builder.setNegativeButton(android.R.string.cancel) { _, _ -> }
val dialog = builder.create()
- dialog.setOnShowListener() { d2 ->
+ return dialog
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ dialog!!.setOnShowListener() { d2 ->
val d: AlertDialog = d2 as AlertDialog
d.getButton(AlertDialog.BUTTON_POSITIVE)?.setOnClickListener()
+
{ _ ->
- doAsImport(asUsername.text.toString(), asPassword.text.toString())
+ viewLifecycleOwner.lifecycleScope.launch {
+ doAsImport(asUsername.text.toString(), asPassword.text.toString())
+ }
}
}
- return dialog
}
val crvMessage = Pattern.compile(".*<Message>CRV1:R,E:(.*):(.*):(.*)</Message>.*", Pattern.DOTALL)
- internal fun doAsImport(user: String, password: String) {
- val ab = AlertDialog.Builder(requireContext())
- ab.setTitle("Downloading profile")
- ab.setMessage("Please wait")
- val pleaseWait = ab.show()
- Toast.makeText(context, "Downloading profile", Toast.LENGTH_LONG).show()
- val asProfileUri = getAsUrl(asServername.text.toString(), asUseAutlogin.isChecked)
+ suspend internal fun doAsImport(user: String, password: String) {
+ var pleaseWait:AlertDialog?
+ withContext(Dispatchers.IO)
+ {
+
+ withContext(Dispatchers.Main)
+ {
+ val ab = AlertDialog.Builder(requireContext())
+ ab.setTitle("Downloading profile")
+ ab.setMessage("Please wait")
+ pleaseWait = ab.show()
+
+ Toast.makeText(context, "Downloading profile", Toast.LENGTH_LONG).show()
+ }
+
+
+ val asProfileUri = getAsUrl(asServername.text.toString(), asUseAutlogin.isChecked)
- doAsync {
var e: Exception? = null
try {
val response = fetchProfile(requireContext(), asProfileUri, user, password)
-
if (response == null) {
throw Exception("No Response from Server")
}
val profile = response.body().string()
if (response.code() == 401 && crvMessage.matcher(profile).matches()) {
- requireContext().runOnUiThread {
+ withContext(Dispatchers.Main) {
pleaseWait?.dismiss()
showCRDialog(profile)
}
} else if (response.isSuccessful) {
- activity?.runOnUiThread {
+ withContext(Dispatchers.Main) {
pleaseWait?.dismiss()
val startImport = Intent(activity, ConfigConverter::class.java)
startImport.action = ConfigConverter.IMPORT_PROFILE_DATA
@@ -298,7 +323,7 @@ class ImportASConfig : DialogFragment() {
Log.i("OpenVPN", "Found cert with FP ${fp}: ${firstCert.subjectDN}")
- requireContext().runOnUiThread {
+ withContext(Dispatchers.Main) {
pleaseWait?.dismiss()
@@ -312,7 +337,7 @@ class ImportASConfig : DialogFragment() {
e = null
}
} else if (ce.message != null && ce.message!!.contains("Certificate pinning failure")) {
- requireContext().runOnUiThread {
+ withContext(Dispatchers.Main) {
pleaseWait?.dismiss()
AlertDialog.Builder(requireContext())
@@ -330,7 +355,7 @@ class ImportASConfig : DialogFragment() {
e = ge
}
if (e != null) {
- activity?.runOnUiThread() {
+ withContext(Dispatchers.Main) {
pleaseWait?.dismiss()
AlertDialog.Builder(requireContext())
.setTitle("Import failed")
@@ -364,7 +389,9 @@ class ImportASConfig : DialogFragment() {
.setView(entry)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.import_config) { _,_ ->
- doAsImport(username, pwprefix + entry.text.toString())
+ viewLifecycleOwner.lifecycleScope.launch {
+ doAsImport(username, pwprefix + entry.text.toString())
+ }
}
.show()
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/PackageAdapter.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/PackageAdapter.kt
index 29fcffc7..e2b8028d 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/PackageAdapter.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/PackageAdapter.kt
@@ -6,6 +6,7 @@
package de.blinkt.openvpn.fragments
import android.Manifest
+import android.app.Activity
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
@@ -17,7 +18,6 @@ import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import de.blinkt.openvpn.R
import de.blinkt.openvpn.VpnProfile
-import org.jetbrains.anko.runOnUiThread
import java.util.*
internal class AppViewHolder(var rootView : View) : RecyclerView.ViewHolder(rootView) {
@@ -72,7 +72,7 @@ internal class PackageAdapter(c: Context, vp: VpnProfile) : RecyclerView.Adapter
}
- fun populateList(c: Context) {
+ fun populateList(a: Activity) {
val installedPackages = mPm.getInstalledApplications(PackageManager.GET_META_DATA)
// Remove apps not using Internet
@@ -99,7 +99,7 @@ internal class PackageAdapter(c: Context, vp: VpnProfile) : RecyclerView.Adapter
Collections.sort(apps, ApplicationInfo.DisplayNameComparator(mPm))
mPackages = apps
mFilteredData = apps
- c.runOnUiThread { notifyDataSetChanged() }
+ a.runOnUiThread { notifyDataSetChanged() }
}
override fun getItemId(position: Int): Long {
diff --git a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt
index 2c113d71..9ad32a47 100644
--- a/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt
+++ b/main/src/ui/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.kt
@@ -90,7 +90,7 @@ class Settings_Allowed_Apps : Fragment(), AdapterView.OnItemClickListener, View.
mListView.adapter = packageAdapter
Thread(Runnable {
- packageAdapter.populateList(requireContext())
+ packageAdapter.populateList(activity!!)
activity?.runOnUiThread({
(v.findViewById<View>(R.id.loading_container)).visibility = View.GONE
(v.findViewById<View>(R.id.app_recycler_view)).visibility = View.VISIBLE