Use coroutine

This commit is contained in:
PabloG02 2023-01-12 01:04:38 +01:00
parent b2de510b2b
commit d6eab932a7

View File

@ -18,12 +18,14 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.startActivity import androidx.core.content.ContextCompat.startActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONTokener import org.json.JSONTokener
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.net.URL import java.net.URL
import java.util.concurrent.Executors
class AppUpdater : BroadcastReceiver() { class AppUpdater : BroadcastReceiver() {
private var downloadID = 0L private var downloadID = 0L
@ -68,14 +70,14 @@ class AppUpdater : BroadcastReceiver() {
companion object { companion object {
private const val baseUrl = "https://skyline-builds.alula.gay" private const val baseUrl = "https://skyline-builds.alula.gay"
private const val branch = "ftx1" private const val branch = "ftx1"
@JvmStatic @JvmStatic
fun checkForUpdates(applicationContext : Context) { fun checkForUpdates(applicationContext : Context) {
val myExecutor = Executors.newSingleThreadExecutor()
val myHandler = Handler(Looper.getMainLooper()) val myHandler = Handler(Looper.getMainLooper())
val builder = AlertDialog.Builder(applicationContext) val builder = AlertDialog.Builder(applicationContext)
val url = URL("$baseUrl/builds") val url = URL("$baseUrl/builds")
myExecutor.execute { CoroutineScope(Dispatchers.IO).launch {
try { try {
val response = url.readText() val response = url.readText()
val jsonBuilds = JSONTokener(response).nextValue() as JSONArray val jsonBuilds = JSONTokener(response).nextValue() as JSONArray