Commit 1c6b7577 authored by Geoffrey Métais's avatar Geoffrey Métais

Change playlist/Album tracks deletion process

parent db08ffd9
......@@ -55,6 +55,8 @@
<string name="confirm_delete">Delete the file \'%1$s\'?</string>
<string name="confirm_delete_folder">Delete the folder \'%1$s\' and all its contents?</string>
<string name="confirm_delete_playlist">Delete playlist \'%1$s\'?</string>
<string name="confirm_remove_from_playlist">Remove \'%1$s\' from playlist?</string>
<string name="confirm_remove_from_playlist_anonymous">Remove from playlist?</string>
<string name="ringtone_set">The file \'%1$s\' was set as the ringtone.</string>
<string name="ringtone_error">An error occurred while setting the ringtone.</string>
<string name="pause">Pause</string>
......
......@@ -317,20 +317,14 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
showInfoDialog(media);
break;
case Constants.CTX_DELETE:
tracksModel.remove(media);
final Runnable cancel = new Runnable() {
@Override
public void run() {
tracksModel.refresh();
}
};
UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {
final int resId = mIsPlaylist ? R.string.confirm_remove_from_playlist : R.string.confirm_delete;
UiTools.snackerConfirm(mBinding.getRoot(), getString(resId, media.getTitle()), new Runnable() {
@Override
public void run() {
if (mIsPlaylist) ((Playlist) mPlaylist).remove(media.getId());
else deleteMedia(media, cancel);
else deleteMedia(media);
}
}, cancel);
});
break;
case Constants.CTX_APPEND:
MediaUtils.INSTANCE.appendMedia(this, media.getTracks());
......@@ -342,13 +336,13 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
UiTools.addToPlaylist(this, media.getTracks(), SavePlaylistDialog.KEY_NEW_TRACKS);
break;
case Constants.CTX_SET_RINGTONE:
AudioUtil.setRingtone((MediaWrapper) media, this);
AudioUtil.setRingtone(media, this);
break;
}
}
protected void deleteMedia(final MediaLibraryItem mw, final Runnable cancel) {
protected void deleteMedia(final MediaLibraryItem mw) {
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
......@@ -362,21 +356,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
mediaPaths.add(media.getLocation());
} else UiTools.snacker(mBinding.getRoot(), getString(R.string.msg_delete_failed, media.getTitle()));
}
for (String folder : foldersToReload)
mMediaLibrary.reload(folder);
if (PlaylistManager.Companion.hasMedia()) {
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
if (mediaPaths.isEmpty()) cancel.run();
//TODO
// else {
// for (String path : mediaPaths)
// mService.removeLocation(path);
// }
}
});
}
for (String folder : foldersToReload) mMediaLibrary.reload(folder);
}
});
}
......@@ -387,17 +367,14 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
}
private void removeFromPlaylist(final List<MediaWrapper> list){
for (MediaLibraryItem mediaItem : list) tracksModel.remove(mediaItem);
UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {
UiTools.snackerConfirm(mBinding.getRoot(), getString(R.string.confirm_remove_from_playlist_anonymous), new Runnable() {
@Override
public void run() {
for (MediaLibraryItem mediaItem : list) ((Playlist) mPlaylist).remove(mediaItem.getId());
if (mPlaylist.getTracks().length == 0) ((Playlist) mPlaylist).delete();
}
}, new Runnable() {
@Override
public void run() {
tracksModel.refresh();
if (mPlaylist.getTracks().length == 0) {
((Playlist) mPlaylist).delete();
finish();
}
}
});
}
......
......@@ -3,11 +3,20 @@ package org.videolan.vlc.viewmodels.paged
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import android.content.Context
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.launch
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.media.*
import org.videolan.vlc.util.EmptyMLCallbacks
import org.videolan.vlc.util.Settings
class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null): MLPagedModel<MediaWrapper>(context), Medialibrary.MediaCb {
class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null): MLPagedModel<MediaWrapper>(context),
Medialibrary.MediaCb,
Medialibrary.ArtistsCb by EmptyMLCallbacks,
Medialibrary.AlbumsCb by EmptyMLCallbacks,
Medialibrary.GenresCb by EmptyMLCallbacks,
Medialibrary.PlaylistsCb by EmptyMLCallbacks {
override val sortKey = "${super.sortKey}_${parent?.javaClass?.simpleName}"
override fun canSortByDuration() = true
......@@ -26,24 +35,26 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
override fun onMedialibraryReady() {
super.onMedialibraryReady()
medialibrary.addMediaCb(this)
launch(Dispatchers.Main) {
when (parent) {
is Artist -> medialibrary.addArtistsCb(this@PagedTracksModel)
is Album -> medialibrary.addAlbumsCb(this@PagedTracksModel)
is Genre -> medialibrary.addGenreCb(this@PagedTracksModel)
is Playlist -> medialibrary.addPlaylistCb(this@PagedTracksModel)
else -> medialibrary.addMediaCb(this@PagedTracksModel)
}
}
}
override fun onCleared() {
super.onCleared()
medialibrary.removeMediaCb(this)
}
override fun onMediaAdded() {
refresh()
}
override fun onMediaModified() {
refresh()
}
override fun onMediaDeleted() {
refresh()
when (parent) {
is Artist -> medialibrary.removeArtistsCb(this)
is Album -> medialibrary.removeAlbumsCb(this)
is Genre -> medialibrary.removeGenreCb(this)
is Playlist -> medialibrary.removePlaylistCb(this)
else -> medialibrary.removeMediaCb(this)
}
}
override fun getAll(): Array<MediaWrapper> = parent?.tracks ?: medialibrary.getAudio(sort, desc)
......@@ -62,8 +73,13 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
else -> medialibrary.searchAudio(filter, sort, desc, loadSize, startposition)
}
override fun getTotalCount() = if (filter == null) parent?.tracksCount ?: medialibrary.audioCount
else when(parent) {
override fun getTotalCount() = if (filter == null) when (parent) {
is Album -> parent.realTracksCount
is Playlist -> parent.realTracksCount
is Artist,
is Genre -> parent.tracksCount
else -> medialibrary.audioCount
} else when(parent) {
is Artist -> parent.searchTracksCount(filter)
is Album -> parent.searchTracksCount(filter)
is Genre -> parent.searchTracksCount(filter)
......@@ -77,4 +93,32 @@ class PagedTracksModel(context: Context, val parent: MediaLibraryItem? = null):
return PagedTracksModel(context.applicationContext, parent) as T
}
}
override fun onMediaAdded() {
refresh()
}
override fun onMediaModified() {
refresh()
}
override fun onMediaDeleted() {
refresh()
}
override fun onArtistsModified() {
refresh()
}
override fun onAlbumsModified() {
refresh()
}
override fun onGenresModified() {
refresh()
}
override fun onPlaylistsModified() {
refresh()
}
}
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