musikr: resolve playlist imports by probe-and-lock
This commit is contained in:
@@ -53,6 +53,7 @@ class MusicViewModel
|
||||
constructor(
|
||||
@ApplicationContext context: Context,
|
||||
private val listSettings: ListSettings,
|
||||
private val musicSettings: MusicSettings,
|
||||
private val musicRepository: MusicRepository,
|
||||
) : ViewModel(), MusicRepository.UpdateListener, MusicRepository.IndexingListener {
|
||||
private val externalPlaylistManager = ExternalPlaylistManager.from(context)
|
||||
@@ -160,24 +161,19 @@ constructor(
|
||||
fun importPlaylist(uri: Uri? = null, target: Playlist? = null) {
|
||||
if (uri != null) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val importedPlaylist = externalPlaylistManager.import(uri)
|
||||
val library = musicRepository.library ?: return@launch
|
||||
val importedPlaylist =
|
||||
externalPlaylistManager.import(
|
||||
uri,
|
||||
musicSettings.safQuery.source.map { it.path },
|
||||
library,
|
||||
)
|
||||
if (importedPlaylist == null) {
|
||||
L.e("Could not import playlist")
|
||||
playlistMessage.put(PlaylistMessage.ImportFailed)
|
||||
return@launch
|
||||
}
|
||||
|
||||
val library = musicRepository.library ?: return@launch
|
||||
val songs =
|
||||
importedPlaylist.paths.mapNotNull {
|
||||
it.firstNotNullOfOrNull(library::findSongByPath)
|
||||
}
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
L.e("No songs found")
|
||||
playlistMessage.put(PlaylistMessage.ImportFailed)
|
||||
return@launch
|
||||
}
|
||||
val songs = importedPlaylist.songs
|
||||
|
||||
if (target !== null) {
|
||||
if (importedPlaylist.name != null && importedPlaylist.name != target.name.raw) {
|
||||
|
||||
Reference in New Issue
Block a user