Skip to content

Commit

Permalink
Replaced async task
Browse files Browse the repository at this point in the history
  • Loading branch information
rsiebert committed Mar 26, 2021
1 parent 1dff4b7 commit 8349d31
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package org.tvheadend.tvhclient.ui.features.playback.external

import android.os.AsyncTask
import kotlinx.coroutines.CoroutineScope
import org.tvheadend.tvhclient.util.extensions.executeAsyncTask
import timber.log.Timber
import java.net.InetAddress
import java.net.UnknownHostException

internal class ConvertHostnameToAddressTask(private val hostname: String) : AsyncTask<Void, Void, String>() {
class ConvertHostnameToAddressTask(lifecycleScope: CoroutineScope, private val hostname: String) {

override fun doInBackground(vararg voids: Void): String {
return try {
InetAddress.getByName(hostname).hostAddress
} catch (e: UnknownHostException) {
Timber.d(e, "Could not get ip address from $hostname, using hostname as fallback")
hostname
}
init {
lifecycleScope.executeAsyncTask(onPreExecute = {
// ... runs in Main Thread
Timber.d("onPreExecute")
}, doInBackground = {
Timber.d("doInBackground")
try {
InetAddress.getByName(hostname).hostAddress
} catch (e: UnknownHostException) {
Timber.d(e, "Could not get ip address from $hostname, using hostname as fallback")
hostname
}
}, onPostExecute = {
// runs in Main Thread
Timber.d("onPostExecute")
})
}
}

0 comments on commit 8349d31

Please sign in to comment.