Commit e2056cdd authored by Geoffrey Métais's avatar Geoffrey Métais

Use AppScope when relevant

parent 766b02be
......@@ -39,7 +39,6 @@ import android.support.v4.content.LocalBroadcastManager
import android.text.TextUtils
import android.util.Log
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.actor
import org.videolan.libvlc.util.AndroidUtil
......@@ -421,7 +420,7 @@ fun reload(ctx: Context) {
ContextCompat.startForegroundService(ctx, Intent(ACTION_RELOAD, null, ctx, MediaParsingService::class.java))
}
fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = GlobalScope.launch(Dispatchers.Main.immediate) {
fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = AppScope.launch {
if (Medialibrary.getInstance().isStarted || !Permissions.canReadStorage(this@startMedialibrary)) return@launch
val prefs = withContext(Dispatchers.IO) { Settings.getInstance(this@startMedialibrary) }
val scanOpt = if (AndroidDevices.showTvUi(this@startMedialibrary)) ML_SCAN_ON else prefs.getInt(KEY_MEDIALIBRARY_SCAN, -1)
......
......@@ -21,11 +21,12 @@ package org.videolan.vlc
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.withContext
import org.videolan.libvlc.RendererDiscoverer
import org.videolan.libvlc.RendererItem
import org.videolan.vlc.util.AppScope
import org.videolan.vlc.util.LiveDataset
import org.videolan.vlc.util.VLCInstance
import org.videolan.vlc.util.retry
......@@ -41,7 +42,7 @@ object RendererDelegate : RendererDiscoverer.EventListener {
val selectedRenderer: LiveData<RendererItem> = MutableLiveData()
init {
ExternalMonitor.connected.observeForever { GlobalScope.launch(Dispatchers.Main.immediate) { if (it == true) start() else stop() } }
ExternalMonitor.connected.observeForever { AppScope.launch { if (it == true) start() else stop() } }
}
suspend fun start() {
......
......@@ -13,12 +13,14 @@ import android.support.v4.view.ViewCompat
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.withContext
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.BR
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.util.AppScope
import org.videolan.vlc.util.HttpImageLoader
import org.videolan.vlc.util.ThumbnailsProvider
......@@ -38,12 +40,12 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
val cacheKey = if (isGroup) "group: ${item.title}" else ThumbnailsProvider.getMediaCacheKey(isMedia, item)
val bitmap = if (cacheKey !== null) sBitmapCache.getBitmapFromMemCache(cacheKey) else null
if (bitmap !== null) updateImageView(bitmap, v, binding)
else GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED) { getImage(v, findInLibrary(item, isMedia, isGroup), binding) }
else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding) }
}
@BindingAdapter("imageUri")
fun downloadIcon(v: View, imageUri: Uri?) {
if (imageUri != null && imageUri.scheme == "http") GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED) {
if (imageUri != null && imageUri.scheme == "http") AppScope.launch {
val image = withContext(Dispatchers.IO) { HttpImageLoader.downloadBitmap(imageUri.toString()) }
updateImageView(image, v, DataBindingUtil.findBinding(v))
}
......
......@@ -27,15 +27,13 @@ import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.SendChannel
import kotlinx.coroutines.experimental.launch
import org.videolan.vlc.util.AppScope
open class BaseHeadlessFragment : Fragment() {
open class
BaseHeadlessFragment : Fragment() {
protected var mActivity: FragmentActivity? = null
var channel: SendChannel<Unit>? = null
......@@ -66,7 +64,7 @@ open class BaseHeadlessFragment : Fragment() {
companion object {
internal fun waitForIt(channel: Channel<Unit>, cb: Runnable) {
GlobalScope.launch(Dispatchers.Main.immediate) {
AppScope.launch {
channel.receive()
channel.close()
cb.run()
......
......@@ -36,8 +36,9 @@ import android.support.v17.leanback.widget.Row
import android.support.v4.content.ContextCompat
import android.text.TextUtils
import android.view.View
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.withContext
import org.videolan.medialibrary.media.DummyItem
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
......@@ -182,7 +183,7 @@ object TvUtil {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
fun updateBackground(bm: BackgroundManager?, item: Any?) {
if (bm === null || item === null) return
if (item is MediaLibraryItem) GlobalScope.launch(Dispatchers.Main.immediate){
if (item is MediaLibraryItem) AppScope.launch {
val crop = item.itemType != MediaLibraryItem.TYPE_MEDIA || (item as MediaWrapper).type == MediaWrapper.TYPE_AUDIO
val artworkMrl = item.artworkMrl
if (!TextUtils.isEmpty(artworkMrl)) {
......
......@@ -30,18 +30,12 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.IO
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.launch
import org.videolan.tools.coroutineScope
import org.videolan.vlc.R
import org.videolan.vlc.databinding.MlWizardActivityBinding
import org.videolan.vlc.startMedialibrary
import org.videolan.vlc.util.KEY_MEDIALIBRARY_SCAN
import org.videolan.vlc.util.ML_SCAN_OFF
import org.videolan.vlc.util.ML_SCAN_ON
import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.*
class MLWizardActivity : AppCompatActivity() {
......@@ -64,4 +58,4 @@ class MLWizardActivity : AppCompatActivity() {
}
}
fun Context.startMLWizard() = GlobalScope.launch(Dispatchers.Main.immediate) { startActivity(Intent(applicationContext, MLWizardActivity::class.java)) }
\ No newline at end of file
fun Context.startMLWizard() = AppScope.launch { startActivity(Intent(applicationContext, MLWizardActivity::class.java)) }
\ No newline at end of file
Markdown is supported
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