mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Solving bugs with the fav feature.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Opus.Api.Services;
|
using Opus.Api.Services;
|
||||||
using Opus.DataStructure;
|
using Opus.DataStructure;
|
||||||
|
using Opus.Fragments;
|
||||||
using SQLite;
|
using SQLite;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -126,30 +127,37 @@ namespace Opus.Api
|
|||||||
/// Add a song to the favorite playlist.
|
/// Add a song to the favorite playlist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="song"></param>
|
/// <param name="song"></param>
|
||||||
public static void Fav(Song song)
|
public async static void Fav(Song song)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Console.WriteLine("&Fav " + song.Title);
|
||||||
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Favorites.sqlite"));
|
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Favorites.sqlite"));
|
||||||
db.CreateTable<Song>();
|
db.CreateTable<Song>();
|
||||||
|
|
||||||
db.Insert(song);
|
db.Insert(song);
|
||||||
});
|
});
|
||||||
|
Home.instance?.RefreshFavs();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove a song from the favorites.
|
/// Remove a song from the favorites.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="song"></param>
|
/// <param name="song"></param>
|
||||||
public static void UnFav(Song song)
|
public async static void UnFav(Song song)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Console.WriteLine("&UnFav " + song.Title);
|
||||||
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Favorites.sqlite"));
|
SQLiteConnection db = new SQLiteConnection(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Favorites.sqlite"));
|
||||||
db.CreateTable<Song>();
|
db.CreateTable<Song>();
|
||||||
|
|
||||||
db.Table<Song>().Delete(x => (x.IsYt && x.YoutubeID == song.YoutubeID) || (!x.IsYt && x.LocalID == song.LocalID));
|
if(song.IsYt)
|
||||||
|
db.Table<Song>().Delete(x => x.IsYt && x.YoutubeID == song.YoutubeID);
|
||||||
|
else
|
||||||
|
db.Table<Song>().Delete(x => !x.IsYt && x.LocalID == song.LocalID);
|
||||||
});
|
});
|
||||||
|
Home.instance?.RefreshFavs();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Opus.DataStructure
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class Song
|
public class Song
|
||||||
{
|
{
|
||||||
[PrimaryKey, Unique]
|
[PrimaryKey, Unique, AutoIncrement]
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
|||||||
@@ -206,6 +206,11 @@ namespace Opus.Fragments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshFavs()
|
||||||
|
{
|
||||||
|
adapterItems.Find(x => x.SectionTitle == GetString(Resource.String.favorite)).recycler.GetAdapter().NotifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public void NotifyQueueInserted(int position)
|
public void NotifyQueueInserted(int position)
|
||||||
{
|
{
|
||||||
if (adapterItems.Count > 0)
|
if (adapterItems.Count > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user