mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Solving bugs with the playlist track tab.
This commit is contained in:
@@ -551,21 +551,27 @@ namespace Opus.Api
|
||||
/// <param name="RemovedCallback">A callback called when the user click ok in the dialog. You just need to remove the track from the UI, everything else is already handled.</param>
|
||||
/// <param name="CancelledCallback">A callback called when the user click cancel in the dialog</param>
|
||||
/// <param name="UndoCallback">A callback called when the user click undo in the snackbar</param>
|
||||
public static void RemoveTrackFromPlaylistDialog(PlaylistItem item, Song song, Action RemovedCallback, Action CancelledCallback, Action UndoCallback)
|
||||
public async static void RemoveTrackFromPlaylistDialog(PlaylistItem item, Song song, Action RemovedCallback, Action CancelledCallback, Action UndoCallback)
|
||||
{
|
||||
if (!await MainActivity.instance.GetWritePermission())
|
||||
return;
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(MainActivity.instance, MainActivity.dialogTheme)
|
||||
.SetTitle(MainActivity.instance.GetString(Resource.String.remove_from_playlist, song.Title))
|
||||
.SetPositiveButton(Resource.String.yes, async (sender, e) =>
|
||||
{
|
||||
RemovedCallback?.Invoke();
|
||||
if(item.LocalID != -1)
|
||||
RemoveFromLocalPlaylist(song, item.LocalID);
|
||||
|
||||
if (item.YoutubeID != null)
|
||||
{
|
||||
if (song.TrackID == null)
|
||||
song = await CompleteItem(song, item.YoutubeID);
|
||||
}
|
||||
RemoveTrackFromPlaylistCallback callback = new RemoveTrackFromPlaylistCallback(song, item.LocalID);
|
||||
|
||||
RemovedCallback?.Invoke();
|
||||
|
||||
RemoveTrackFromPlaylistCallback callback = new RemoveTrackFromPlaylistCallback(song, item.LocalID);
|
||||
Snackbar snackBar = Snackbar.Make(MainActivity.instance.FindViewById(Resource.Id.snackBar), (song.Title.Length > 20 ? song.Title.Substring(0, 17) + "..." : song.Title) + MainActivity.instance.GetString(Resource.String.removed_from_playlist), Snackbar.LengthLong)
|
||||
.SetAction(MainActivity.instance.GetString(Resource.String.undo), (v) =>
|
||||
{
|
||||
@@ -626,7 +632,7 @@ namespace Opus.Api
|
||||
CursorLoader cursorLoader = new CursorLoader(Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
playlists.Add(new PlaylistItem(name, id, musicCursor.Count));
|
||||
playlists.Add(new PlaylistItem(name, id, musicCursor.Count) { HasWritePermission = true });
|
||||
}
|
||||
while (cursor.MoveToNext());
|
||||
cursor.Close();
|
||||
@@ -943,14 +949,20 @@ namespace Opus.Api
|
||||
/// </summary>
|
||||
/// <param name="song"></param>
|
||||
/// <param name="LocalPlaylistID"></param>
|
||||
public async static void RemoveFromLocalPlaylist(Song song, long LocalPlaylistID)
|
||||
public /*async*/ static void RemoveFromLocalPlaylist(Song song, long LocalPlaylistID)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Console.WriteLine("&Remove Track From Local Playlist Called");
|
||||
Console.WriteLine("&Song localID: " + song.LocalID + " LocalPlaylistID: " + LocalPlaylistID);
|
||||
|
||||
//await Task.Run(() =>
|
||||
//{
|
||||
// if (Looper.MyLooper() == null)
|
||||
// Looper.Prepare();
|
||||
|
||||
ContentResolver resolver = MainActivity.instance.ContentResolver;
|
||||
Uri uri = MediaStore.Audio.Playlists.Members.GetContentUri("external", LocalPlaylistID);
|
||||
resolver.Delete(uri, MediaStore.Audio.Playlists.Members.AudioId + "=?", new string[] { song.LocalID.ToString() });
|
||||
});
|
||||
Uri uri = Playlists.Members.GetContentUri("external", LocalPlaylistID);
|
||||
resolver.Delete(uri, Playlists.Members.Id + "=?", new string[] { song.LocalID.ToString() });
|
||||
//});
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -411,7 +411,6 @@ namespace Opus
|
||||
|
||||
if (PlaylistTracks.instance != null)
|
||||
{
|
||||
PlaylistTracks.instance.navigating = true;
|
||||
SupportFragmentManager.BeginTransaction().Remove(PlaylistTracks.instance).Commit();
|
||||
SupportFragmentManager.PopBackStack(null, Android.Support.V4.App.FragmentManager.PopBackStackInclusive);
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace Opus.Others
|
||||
{
|
||||
PlaylistManager.RemoveFromYoutubePlaylist(song.TrackID);
|
||||
}
|
||||
if (LocalPlaylistID != 0)
|
||||
{
|
||||
PlaylistManager.RemoveFromLocalPlaylist(song, LocalPlaylistID);
|
||||
}
|
||||
}
|
||||
else if (LocalPlaylistID != 0)
|
||||
{
|
||||
LocalManager.AddToPlaylist(new[] { song }, null, LocalPlaylistID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace Opus.Adapter
|
||||
|
||||
public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
|
||||
{
|
||||
System.Console.WriteLine("&Binding, position: " + position + " BaseCount: " + BaseCount + " ItemCount: " + ItemCount);
|
||||
|
||||
if (position == ItemCount - 1 && !PlaylistTracks.instance.fullyLoadded)
|
||||
{
|
||||
int pad = MainActivity.instance.DpToPx(30);
|
||||
@@ -90,6 +92,7 @@ namespace Opus.Adapter
|
||||
else if (BaseCount == 0)
|
||||
{
|
||||
((TextView)viewHolder.ItemView).Text = MainActivity.instance.GetString(Resource.String.playlist_empty);
|
||||
System.Console.WriteLine("&Binding empty view");
|
||||
}
|
||||
else if (tracks != null)
|
||||
OnBindViewHolder(viewHolder, tracks[position - ItemBefore]);
|
||||
@@ -218,7 +221,7 @@ namespace Opus.Adapter
|
||||
|
||||
public void ItemDismissed(int position)
|
||||
{
|
||||
PlaylistTracks.instance.RemoveFromPlaylist(tracks[position], position);
|
||||
PlaylistTracks.instance.RemoveFromPlaylist(tracks == null ? GetItem(position) : tracks[position], position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,6 @@ namespace Opus.Fragments
|
||||
public bool fullyLoadded = true;
|
||||
public bool lastVisible = false;
|
||||
public bool useHeader = true;
|
||||
public bool navigating = false;
|
||||
private bool isForked;
|
||||
private bool loading = false;
|
||||
|
||||
@@ -349,7 +348,7 @@ namespace Opus.Fragments
|
||||
{
|
||||
adapter.SwapCursor((ICursor)data, false);
|
||||
|
||||
if (item.LocalID != -1)
|
||||
if (query == null && item.LocalID != -1 && adapter.BaseCount > 0)
|
||||
{
|
||||
Activity.FindViewById<TextView>(Resource.Id.headerNumber).Text = item.Count.ToString() + " " + GetString(Resource.String.elements);
|
||||
var songCover = Uri.Parse("content://media/external/audio/albumart");
|
||||
@@ -542,13 +541,19 @@ namespace Opus.Fragments
|
||||
{
|
||||
PlaylistManager.RemoveTrackFromPlaylistDialog(this.item, item, () =>
|
||||
{
|
||||
adapter.NotifyItemRemoved(position);
|
||||
if (position == 0)
|
||||
adapter.NotifyItemChanged(0);
|
||||
else
|
||||
adapter.NotifyItemRemoved(position);
|
||||
}, () =>
|
||||
{
|
||||
adapter.NotifyItemChanged(position);
|
||||
}, () =>
|
||||
{
|
||||
adapter.NotifyItemInserted(position);
|
||||
if (position == 0)
|
||||
adapter.NotifyItemChanged(position);
|
||||
else
|
||||
adapter.NotifyItemInserted(position);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user