Skip to content

Commit

Permalink
Update gradle files, remove anko dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
schwabe committed Apr 15, 2021
1 parent 8d0f9d2 commit 4c7280b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 46 deletions.
13 changes: 9 additions & 4 deletions build.gradle.kts
Expand Up @@ -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")
}
}
22 changes: 12 additions & 10 deletions main/build.gradle.kts
Expand Up @@ -9,8 +9,7 @@ plugins {
id("com.android.application")
id("checkstyle")

kotlin("android")
kotlin("android.extensions")
id("kotlin-android")
}

android {
Expand Down Expand Up @@ -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?
Expand All @@ -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")
}
83 changes: 55 additions & 28 deletions main/src/ui/java/de/blinkt/openvpn/fragments/ImportASConfig.kt
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -298,7 +323,7 @@ class ImportASConfig : DialogFragment() {


Log.i("OpenVPN", "Found cert with FP ${fp}: ${firstCert.subjectDN}")
requireContext().runOnUiThread {
withContext(Dispatchers.Main) {

pleaseWait?.dismiss()

Expand All @@ -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())
Expand All @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 4c7280b

Please sign in to comment.