Commit a057b510 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Always get Medialibrary from service locator

This will greatly improve app testability
parent 436dce3e
......@@ -43,6 +43,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.OtgAccess
import org.videolan.vlc.util.*
......@@ -74,7 +75,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
}
is MediaUnmounted -> {
delay(100L)
VLCApplication.mlInstance.removeDevice(action.uuid, action.path)
AbstractMedialibrary.getInstance().removeDevice(action.uuid, action.path)
if (storageUnplugged.hasActiveObservers()) storageUnplugged.postValue(action.uri)
}
}
......@@ -176,7 +177,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
private fun checkNewStorages(ctx: Context) {
if (VLCApplication.mlInstance.isStarted) {
if (AbstractMedialibrary.getInstance().isStarted) {
val scanOpt = if (Settings.showTvUi) ML_SCAN_ON
else Settings.getInstance(ctx).getInt(KEY_MEDIALIBRARY_SCAN, -1)
if (scanOpt == ML_SCAN_ON)
......
......@@ -450,7 +450,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
playlistManager = PlaylistManager(this)
Util.checkCpuCompatibility(this)
medialibrary = VLCApplication.mlInstance
medialibrary = AbstractMedialibrary.getInstance()
if (!medialibrary.isInitiated) registerMedialibrary(null)
detectHeadset = settings.getBoolean("enable_headset_detection", true)
......
......@@ -32,6 +32,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.vlc.gui.helpers.BitmapUtil
import org.videolan.vlc.gui.video.VideoPlayerActivity
......@@ -87,7 +88,7 @@ class RecommendationsService : IntentService("RecommendationService"), Coroutine
private fun doRecommendations() = launch {
mNotificationManager.cancelAll()
val videoList = withContext(Dispatchers.IO) { VLCApplication.mlInstance.recentVideos }
val videoList = withContext(Dispatchers.IO) { AbstractMedialibrary.getInstance().recentVideos }
if (Util.isArrayEmpty(videoList)) return@launch
for ((id, mediaWrapper) in videoList.withIndex()) {
buildRecommendation(mediaWrapper, id, NotificationManagerCompat.IMPORTANCE_DEFAULT)
......
......@@ -88,7 +88,6 @@ class VLCApplication : Application() {
init {
instance = this
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
}
@TargetApi(Build.VERSION_CODES.O)
......@@ -206,9 +205,6 @@ class VLCApplication : Application() {
dataMap.clear()
}
val mlInstance: AbstractMedialibrary
get() = AbstractMedialibrary.getInstance()
/**
* Check if application is currently displayed
* @return true if an activity is displayed, false if app is in background.
......
......@@ -22,6 +22,7 @@ import kotlinx.coroutines.*
import org.videolan.libvlc.Media
import org.videolan.libvlc.util.Extensions
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractArtist
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -69,7 +70,7 @@ class InfoActivity : AudioPlayerContainerActivity(), View.OnClickListener, PathA
}
this.item = item
if (item.id == 0L) {
val libraryItem = VLCApplication.mlInstance.getMedia((item as AbstractMediaWrapper).uri)
val libraryItem = AbstractMedialibrary.getInstance().getMedia((item as AbstractMediaWrapper).uri)
if (libraryItem != null)
this.item = libraryItem
}
......
......@@ -117,7 +117,7 @@ class MainActivity : ContentActivity(), ExtensionManagerService.ExtensionManager
/* Reload the latest preferences */
scanNeeded = savedInstanceState == null && settings.getBoolean("auto_rescan", true)
if (BuildConfig.DEBUG) extensionsManager = ExtensionsManager.getInstance()
mediaLibrary = VLCApplication.mlInstance
mediaLibrary = AbstractMedialibrary.getInstance()
val typedValue = TypedValue()
......
......@@ -47,6 +47,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.interfaces.media.AbstractPlaylist
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -81,7 +82,7 @@ import java.util.*
open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler, IListEventsHandler, ActionMode.Callback, View.OnClickListener, CtxActionReceiver {
private lateinit var audioBrowserAdapter: AudioBrowserAdapter
private val mediaLibrary = VLCApplication.mlInstance
private val mediaLibrary = AbstractMedialibrary.getInstance()
private lateinit var binding: PlaylistActivityBinding
private var actionMode: ActionMode? = null
private var isPlaylist: Boolean = false
......
......@@ -46,7 +46,7 @@ open class SearchActivity : BaseActivity(), TextWatcher, TextView.OnEditorAction
binding = DataBindingUtil.setContentView(this, R.layout.search_activity)
binding.handler = clickHandler
binding.searchAggregate = SearchAggregate()
medialibrary = VLCApplication.mlInstance
medialibrary = AbstractMedialibrary.getInstance()
if (Intent.ACTION_SEARCH == intent.action || "com.google.android.gms.actions.SEARCH_ACTION" == intent.action) {
val query = intent.getStringExtra(SearchManager.QUERY)
initializeLists()
......
......@@ -33,6 +33,7 @@ import androidx.fragment.app.Fragment
import com.google.android.material.appbar.AppBarLayout
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment
......@@ -105,7 +106,7 @@ class SecondaryActivity : ContentActivity() {
// Handle item selection
when (item.itemId) {
R.id.ml_menu_refresh -> {
val ml = VLCApplication.mlInstance
val ml = AbstractMedialibrary.getInstance()
if (!ml.isWorking) this.rescan()
return true
}
......
......@@ -90,7 +90,7 @@ abstract class MediaBrowserFragment<T : SortableModel> : Fragment(), ActionMode.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mediaLibrary = VLCApplication.mlInstance
mediaLibrary = AbstractMedialibrary.getInstance()
setHasOptionsMenu(!AndroidDevices.isAndroidTv)
}
......
......@@ -31,6 +31,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.Storage
......@@ -88,10 +89,10 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
fun updateMediaDirs(context: Context) {
mediaDirsLocation.clear()
val folders = if (!VLCApplication.mlInstance.isInitiated) {
val folders = if (!AbstractMedialibrary.getInstance().isInitiated) {
MediaParsingService.preselectedStorages.toTypedArray()
} else {
VLCApplication.mlInstance.foldersList
AbstractMedialibrary.getInstance().foldersList
}
......
......@@ -44,6 +44,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.MLServiceLocator
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.EntryPointsEventsCb
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
......@@ -104,14 +105,14 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb {
override fun onStart() {
super.onStart()
VLCApplication.mlInstance.addEntryPointsEventsCb(this)
AbstractMedialibrary.getInstance().addEntryPointsEventsCb(this)
snack?.show()
launch { if (isAdded) (adapter as StorageBrowserAdapter).updateListState(requireContext()) }
}
override fun onStop() {
super.onStop()
VLCApplication.mlInstance.removeEntryPointsEventsCb(this)
AbstractMedialibrary.getInstance().removeEntryPointsEventsCb(this)
snack?.dismiss()
alertDialog?.let { if (it.isShowing) it.dismiss() }
}
......
......@@ -66,7 +66,7 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
medialibrary = VLCApplication.mlInstance
medialibrary = AbstractMedialibrary.getInstance()
adapter = SimpleAdapter(this)
tracks = try {
@Suppress("UNCHECKED_CAST")
......
......@@ -18,6 +18,7 @@ import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding
import androidx.leanback.widget.ImageCardView
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.BR
......@@ -31,7 +32,7 @@ import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.ThumbnailsProvider
import org.videolan.vlc.util.ThumbnailsProvider.obtainBitmap
private val sMedialibrary = VLCApplication.mlInstance
private val sMedialibrary = AbstractMedialibrary.getInstance()
@Volatile
private var defaultImageWidth = 0
private var defaultImageWidthTV = 0
......
......@@ -4,6 +4,7 @@ package org.videolan.vlc.gui.helpers
import android.content.Context
import android.content.Intent
import androidx.core.content.ContextCompat
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.MediaParsingService
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.util.ACTION_DISCOVER
......@@ -14,7 +15,7 @@ import org.videolan.vlc.util.runIO
object MedialibraryUtils {
fun removeDir(path: String) {
runIO(Runnable { VLCApplication.mlInstance.removeFolder(path) })
runIO(Runnable { AbstractMedialibrary.getInstance().removeFolder(path) })
}
@JvmOverloads
......
......@@ -85,7 +85,7 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
.setTitle(R.string.clear_playback_history)
.setMessage(R.string.validation)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes) { dialog, _ -> VLCApplication.mlInstance.clearHistory() }
.setPositiveButton(android.R.string.yes) { dialog, _ -> AbstractMedialibrary.getInstance().clearHistory() }
.setNegativeButton(android.R.string.cancel, null).show()
return true
......@@ -102,7 +102,7 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
return true
}
"dump_media_db" -> {
if (VLCApplication.mlInstance.isWorking)
if (AbstractMedialibrary.getInstance().isWorking)
UiTools.snacker(view!!, getString(R.string.settings_ml_block_scan))
else
runIO(Runnable {
......
......@@ -33,6 +33,7 @@ import androidx.preference.Preference
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
......@@ -70,7 +71,7 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
when (preference.key) {
"directories" -> {
when {
VLCApplication.mlInstance.isWorking -> UiTools.snacker(view!!, getString(R.string.settings_ml_block_scan))
AbstractMedialibrary.getInstance().isWorking -> UiTools.snacker(view!!, getString(R.string.settings_ml_block_scan))
Permissions.canReadStorage(requireContext()) -> {
val activity = requireActivity()
val intent = Intent(activity.applicationContext, SecondaryActivity::class.java)
......
......@@ -34,6 +34,7 @@ import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import kotlinx.coroutines.*
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.tools.KeyHelper
import org.videolan.vlc.*
......@@ -59,7 +60,7 @@ abstract class BaseTvActivity : FragmentActivity(), CoroutineScope by MainScope(
//Init Medialibrary if KO
if (savedInstanceState != null) startMedialibrary(firstRun = false, upgrade = false, parse = true)
super.onCreate(savedInstanceState)
mediaLibrary = VLCApplication.mlInstance
mediaLibrary = AbstractMedialibrary.getInstance()
settings = Settings.getInstance(this)
registerLiveData()
launch { findViewById<View>(R.id.tv_time)?.let { registerTimeView(it as TextView) } }
......
......@@ -35,6 +35,7 @@ import androidx.preference.EditTextPreference
import androidx.preference.Preference
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
......@@ -84,7 +85,7 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
.setTitle(R.string.clear_playback_history)
.setMessage(R.string.validation)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes) { _, _ -> VLCApplication.mlInstance.clearHistory() }
.setPositiveButton(android.R.string.yes) { _, _ -> AbstractMedialibrary.getInstance().clearHistory() }
.setNegativeButton(android.R.string.cancel, null).show()
return true
}
......
......@@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentActivity
import androidx.preference.Preference
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.SecondaryActivity
......@@ -59,7 +60,7 @@ class PreferencesFragment : BasePreferenceFragment() {
return when (preference.key) {
"directories" -> {
when {
VLCApplication.mlInstance.isWorking -> Toast.makeText(context, getString(R.string.settings_ml_block_scan), Toast.LENGTH_SHORT).show()
AbstractMedialibrary.getInstance().isWorking -> Toast.makeText(context, getString(R.string.settings_ml_block_scan), Toast.LENGTH_SHORT).show()
Permissions.canReadStorage(context) -> {
val intent = Intent(context.applicationContext, SecondaryActivity::class.java)
intent.putExtra("fragment", SecondaryActivity.STORAGE_BROWSER)
......
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