mirror of
https://github.com/zoriya/Opus.git
synced 2026-06-06 15:42:09 +00:00
Reworking queue display for chromecast. Removing this weird effect of flashing.
This commit is contained in:
@@ -1546,7 +1546,7 @@ namespace MusicApp
|
||||
public void OnSessionResumed(Java.Lang.Object session, bool wasSuspended)
|
||||
{
|
||||
Console.WriteLine("&Session Resumed");
|
||||
SwitchRemote(((CastSession)session).RemoteMediaClient);
|
||||
SwitchRemote(((CastSession)session).RemoteMediaClient, false);
|
||||
}
|
||||
|
||||
public void OnSessionResuming(Java.Lang.Object session, string sessionId) { }
|
||||
@@ -1556,7 +1556,7 @@ namespace MusicApp
|
||||
public void OnSessionStarted(Java.Lang.Object session, string sessionId)
|
||||
{
|
||||
Console.WriteLine("&Session Started");
|
||||
SwitchRemote(((CastSession)session).RemoteMediaClient);
|
||||
SwitchRemote(((CastSession)session).RemoteMediaClient, true);
|
||||
}
|
||||
|
||||
public void OnSessionStarting(Java.Lang.Object session) { }
|
||||
@@ -1567,7 +1567,7 @@ namespace MusicApp
|
||||
SwitchRemote(null);
|
||||
}
|
||||
|
||||
private async void SwitchRemote(RemoteMediaClient remoteClient)
|
||||
private async void SwitchRemote(RemoteMediaClient remoteClient, bool justStarted = true)
|
||||
{
|
||||
Console.WriteLine("&Switching to another remote player: (null check)" + (remoteClient == null));
|
||||
|
||||
@@ -1606,7 +1606,19 @@ namespace MusicApp
|
||||
|
||||
await Task.Delay(1000);
|
||||
if (MusicPlayer.UseCastPlayer)
|
||||
MusicPlayer.GetQueueFromCast();
|
||||
{
|
||||
if (justStarted)
|
||||
{
|
||||
Intent intent = new Intent(this, typeof(MusicPlayer));
|
||||
intent.SetAction("StartCasting");
|
||||
StartService(intent);
|
||||
}
|
||||
else
|
||||
{
|
||||
MusicPlayer.Initialized = true;
|
||||
MusicPlayer.GetQueueFromCast();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,6 @@
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Json" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -286,7 +285,6 @@
|
||||
<Compile Include="Resources\Portable Class\PlaylistHolder.cs" />
|
||||
<Compile Include="Resources\Portable Class\PlaylistLocationAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\PlaylistTrackAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\QueueCallback.cs" />
|
||||
<Compile Include="Resources\Portable Class\RemoveBlackBorder.cs" />
|
||||
<Compile Include="Resources\Portable Class\SearchableActivity.cs" />
|
||||
<Compile Include="Resources\Portable Class\Downloader.cs" />
|
||||
@@ -314,7 +312,7 @@
|
||||
<Compile Include="Resources\Portable Class\Preferences.cs" />
|
||||
<Compile Include="Resources\Portable Class\Queue.cs" />
|
||||
<Compile Include="Resources\Portable Class\QueueFooter.cs" />
|
||||
<Compile Include="Resources\Portable Class\RecyclerAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\QueueAdapter.cs" />
|
||||
<Compile Include="Resources\Portable Class\RecyclerHolder.cs" />
|
||||
<Compile Include="Resources\Portable Class\SeekbarPreference.cs" />
|
||||
<Compile Include="Resources\Portable Class\Sleeper.cs" />
|
||||
|
||||
@@ -8,17 +8,24 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public override void ItemsUpdatedAtIndexes(int[] indexes)
|
||||
{
|
||||
base.ItemsUpdatedAtIndexes(indexes);
|
||||
System.Console.WriteLine("&Index has come");
|
||||
foreach (int index in indexes)
|
||||
{
|
||||
Song song = (Song)MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(index);
|
||||
|
||||
if (MusicPlayer.queue.Count > index)
|
||||
MusicPlayer.queue[index] = (Song)MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(index);
|
||||
MusicPlayer.queue[index] = song;
|
||||
else
|
||||
{
|
||||
while (MusicPlayer.queue.Count < index)
|
||||
MusicPlayer.queue.Add(null);
|
||||
|
||||
MusicPlayer.queue.Add((Song)MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(index));
|
||||
MusicPlayer.queue.Add(song);
|
||||
}
|
||||
|
||||
if(song != null)
|
||||
{
|
||||
Queue.instance?.adapter.NotifyItemChanged(index, song.Title);
|
||||
Home.instance?.QueueAdapter?.NotifyItemChanged(index, song.Title);
|
||||
}
|
||||
|
||||
MusicPlayer.WaitForIndex.Remove(index);
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public static Home instance;
|
||||
public RecyclerView ListView;
|
||||
public HomeAdapter adapter;
|
||||
public LineAdapter QueueAdapter;
|
||||
public ItemTouchHelper itemTouchHelper;
|
||||
public static List<HomeSection> adapterItems = new List<HomeSection>();
|
||||
public List<string> selectedTopics = new List<string>();
|
||||
@@ -446,13 +447,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void RefreshQueue()
|
||||
{
|
||||
if (MusicPlayer.UseCastPlayer && adapterItems.Count > 0)
|
||||
if (adapterItems.Count > 0)
|
||||
{
|
||||
adapterItems[0].recycler?.SetAdapter(new LineAdapter(adapterItems[0].recycler));
|
||||
}
|
||||
else if (adapterItems.Count > 0)
|
||||
{
|
||||
adapterItems[0].recycler?.GetAdapter()?.NotifyDataSetChanged();
|
||||
QueueAdapter?.NotifyDataSetChanged();
|
||||
if (MusicPlayer.CurrentID() != -1 && MusicPlayer.CurrentID() <= MusicPlayer.queue.Count)
|
||||
adapterItems[0].recycler?.ScrollToPosition(MusicPlayer.CurrentID());
|
||||
}
|
||||
|
||||
@@ -84,7 +84,9 @@ namespace MusicApp.Resources.Portable_Class
|
||||
holder.recycler.SetLayoutManager(new LinearLayoutManager(MainActivity.instance, LinearLayoutManager.Horizontal, false));
|
||||
if (items[position].SectionTitle == "Queue")
|
||||
{
|
||||
holder.recycler.SetAdapter(new LineAdapter(holder.recycler));
|
||||
LineAdapter adapter = new LineAdapter(holder.recycler);
|
||||
Home.instance.QueueAdapter = adapter;
|
||||
holder.recycler.SetAdapter(adapter);
|
||||
holder.more.Click += (sender, e) =>
|
||||
{
|
||||
Intent intent = new Intent(MainActivity.instance, typeof(Queue));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Gms.Cast.Framework.Media;
|
||||
using Android.Graphics;
|
||||
using Android.Support.V7.Widget;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
@@ -50,12 +51,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
this.recycler = recycler;
|
||||
UseQueue = true;
|
||||
|
||||
if (MusicPlayer.UseCastPlayer)
|
||||
MusicPlayer.RemotePlayer.MediaQueue.RegisterCallback(new QueueCallback(this));
|
||||
|
||||
songList = MusicPlayer.queue;
|
||||
|
||||
}
|
||||
|
||||
public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
|
||||
@@ -71,10 +67,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
RecyclerHolder holder = (RecyclerHolder)viewHolder;
|
||||
|
||||
Song song = UseQueue && MusicPlayer.UseCastPlayer ? (Song)MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(position) : songList[position];
|
||||
Song song = songList.Count <= position ? null : songList[position];
|
||||
|
||||
if (song == null)
|
||||
|
||||
if (song == null && UseQueue)
|
||||
{
|
||||
holder.Title.Text = "";
|
||||
holder.AlbumArt.SetImageResource(Resource.Color.background_material_dark);
|
||||
|
||||
MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(position);
|
||||
return;
|
||||
}
|
||||
|
||||
holder.Title.Text = song.Title;
|
||||
|
||||
@@ -93,6 +96,14 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position, IList<Java.Lang.Object> payloads)
|
||||
{
|
||||
if (payloads.Count > 0 && payloads[0].ToString() == ((RecyclerHolder)holder).Title.Text)
|
||||
return;
|
||||
|
||||
base.OnBindViewHolder(holder, position, payloads);
|
||||
}
|
||||
|
||||
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
if (viewType == 0)
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
public static bool userStopped = true;
|
||||
public static bool isLiveStream = false;
|
||||
public static bool ShouldResumePlayback;
|
||||
public static bool Initialized = false;
|
||||
|
||||
private static long LastTimer = -1;
|
||||
private Notification notification;
|
||||
@@ -166,6 +167,10 @@ namespace MusicApp.Resources.Portable_Class
|
||||
InitializeService();
|
||||
CastCallback.OnStatusUpdated();
|
||||
return StartCommandResult.Sticky;
|
||||
|
||||
case "StartCasting":
|
||||
StartCasting();
|
||||
break;
|
||||
}
|
||||
|
||||
if (intent.Action != null)
|
||||
@@ -340,11 +345,11 @@ namespace MusicApp.Resources.Portable_Class
|
||||
ParseNextSong();
|
||||
}
|
||||
|
||||
public void Play(Song song, long progress = -1)
|
||||
public async void Play(Song song, long progress = -1)
|
||||
{
|
||||
if (!song.IsParsed)
|
||||
{
|
||||
ParseAndPlay("Play", song.YoutubeID, song.Title, song.Artist, song.Album);
|
||||
song = await ParseSong(song);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -449,124 +454,87 @@ namespace MusicApp.Resources.Portable_Class
|
||||
UpdateQueueDataBase();
|
||||
}
|
||||
|
||||
private async Task<Song> ParseSong(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient();
|
||||
var mediaStreamInfo = await client.GetVideoMediaStreamInfosAsync(song.YoutubeID);
|
||||
AudioStreamInfo streamInfo = mediaStreamInfo.Audio.OrderBy(s => s.Bitrate).Last();
|
||||
if (mediaStreamInfo.HlsLiveStreamUrl != null)
|
||||
{
|
||||
song.Path = mediaStreamInfo.HlsLiveStreamUrl;
|
||||
song.IsLiveStream = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
song.Path = streamInfo.Url;
|
||||
song.IsLiveStream = false;
|
||||
}
|
||||
|
||||
Video video = await client.GetVideoAsync(song.YoutubeID);
|
||||
|
||||
if (song.Title == null)
|
||||
{
|
||||
song.Title = video.Title;
|
||||
song.Artist = video.Author;
|
||||
song.Album = video.Thumbnails.HighResUrl;
|
||||
}
|
||||
|
||||
if (!song.IsLiveStream)
|
||||
song.ExpireDate = mediaStreamInfo.ValidUntil;
|
||||
|
||||
song.IsParsed = true;
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
Console.WriteLine("&Parse time out");
|
||||
MainActivity.instance.Timout();
|
||||
parsing = false;
|
||||
if (MainActivity.instance != null)
|
||||
MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress).Visibility = ViewStates.Gone;
|
||||
return null;
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
private async void ParseAndPlay(string action, string videoID, string title, string artist, string thumbnailURL, bool showPlayer = true)
|
||||
{
|
||||
if (!parsing)
|
||||
if (MainActivity.instance != null && action == "Play")
|
||||
{
|
||||
parsing = true;
|
||||
|
||||
if (MainActivity.instance != null && action == "Play")
|
||||
{
|
||||
ProgressBar parseProgress = MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress);
|
||||
parseProgress.Visibility = ViewStates.Visible;
|
||||
parseProgress.ScaleY = 6;
|
||||
Player.instance.Buffering();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient();
|
||||
var mediaStreamInfo = await client.GetVideoMediaStreamInfosAsync(videoID);
|
||||
AudioStreamInfo streamInfo = mediaStreamInfo.Audio.OrderBy(s => s.Bitrate).Last();
|
||||
bool isLive = false;
|
||||
string streamURL = streamInfo.Url;
|
||||
if (mediaStreamInfo.HlsLiveStreamUrl != null)
|
||||
{
|
||||
streamURL = mediaStreamInfo.HlsLiveStreamUrl;
|
||||
isLive = true;
|
||||
}
|
||||
|
||||
|
||||
if (title == null)
|
||||
{
|
||||
Video video = await client.GetVideoAsync(videoID);
|
||||
title = video.Title;
|
||||
artist = video.Author;
|
||||
thumbnailURL = video.Thumbnails.HighResUrl;
|
||||
}
|
||||
|
||||
Console.WriteLine("&Use Cast Player: " + UseCastPlayer);
|
||||
DateTimeOffset? expireDate = null;
|
||||
|
||||
if (UseCastPlayer)
|
||||
{
|
||||
Video info = await client.GetVideoAsync(videoID);
|
||||
thumbnailURL = info.Thumbnails.HighResUrl;
|
||||
if (artist == null || artist == "")
|
||||
artist = info.Author;
|
||||
|
||||
if (!isLive)
|
||||
{
|
||||
expireDate = mediaStreamInfo.ValidUntil;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("&Starting playback");
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "Play":
|
||||
Play(streamURL, title, artist, videoID, thumbnailURL, isLive, expireDate);
|
||||
break;
|
||||
|
||||
case "PlayNext":
|
||||
AddToQueue(streamURL, title, artist, videoID, thumbnailURL, isLive);
|
||||
parsing = false;
|
||||
return;
|
||||
|
||||
case "PlayLast":
|
||||
PlayLastInQueue(streamURL, title, artist, videoID, thumbnailURL, isLive);
|
||||
parsing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("&Action skipped");
|
||||
if (!UseCastPlayer)
|
||||
{
|
||||
Video info = await client.GetVideoAsync(videoID);
|
||||
thumbnailURL = info.Thumbnails.HighResUrl;
|
||||
if (artist == null || artist == "")
|
||||
artist = info.Author;
|
||||
|
||||
queue[CurrentID()].Album = thumbnailURL;
|
||||
queue[CurrentID()].Artist = artist;
|
||||
|
||||
if (!isLive)
|
||||
{
|
||||
expireDate = mediaStreamInfo.ValidUntil;
|
||||
queue[CurrentID()].ExpireDate = expireDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
{
|
||||
MainActivity.instance.Timout();
|
||||
parsing = false;
|
||||
if (MainActivity.instance != null)
|
||||
MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress).Visibility = ViewStates.Gone;
|
||||
return;
|
||||
}
|
||||
//catch
|
||||
//{
|
||||
// MainActivity.instance.Unknow();
|
||||
// parsing = false;
|
||||
// if (MainActivity.instance != null)
|
||||
// MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress).Visibility = ViewStates.Gone;
|
||||
// return;
|
||||
//}
|
||||
|
||||
Console.WriteLine("&Catch block exited");
|
||||
|
||||
Player.instance?.RefreshPlayer();
|
||||
if (MainActivity.instance != null)
|
||||
{
|
||||
MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress).Visibility = ViewStates.Gone;
|
||||
MainActivity.instance.ShowSmallPlayer();
|
||||
MainActivity.instance.ShowPlayer();
|
||||
}
|
||||
UpdateQueueItemDB(await GetItem());
|
||||
parsing = false;
|
||||
ProgressBar parseProgress = MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress);
|
||||
parseProgress.Visibility = ViewStates.Visible;
|
||||
parseProgress.ScaleY = 6;
|
||||
Player.instance.Buffering();
|
||||
}
|
||||
|
||||
Song song = await ParseSong(new Song(title, artist, thumbnailURL, videoID, -1, -1, null, true, false));
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "Play":
|
||||
Play(song);
|
||||
break;
|
||||
|
||||
case "PlayNext":
|
||||
AddToQueue(song);
|
||||
return;
|
||||
|
||||
case "PlayLast":
|
||||
PlayLastInQueue(song);
|
||||
return;
|
||||
}
|
||||
|
||||
Player.instance?.RefreshPlayer();
|
||||
if (MainActivity.instance != null)
|
||||
{
|
||||
MainActivity.instance.FindViewById<ProgressBar>(Resource.Id.ytProgress).Visibility = ViewStates.Gone;
|
||||
MainActivity.instance.ShowSmallPlayer();
|
||||
MainActivity.instance.ShowPlayer();
|
||||
}
|
||||
UpdateQueueItemDB(await GetItem());
|
||||
}
|
||||
|
||||
/*async*/ void GenerateNext(int number)
|
||||
@@ -1555,16 +1523,39 @@ namespace MusicApp.Resources.Portable_Class
|
||||
return new MediaQueueItem.Builder(GetMediaInfo(song)).Build();
|
||||
}
|
||||
|
||||
public async static void GetQueueFromCast()
|
||||
private async void StartCasting()
|
||||
{
|
||||
if (UseCastPlayer)
|
||||
if (UseCastPlayer && (RemotePlayer.MediaQueue == null || RemotePlayer.MediaQueue.ItemCount == 0))
|
||||
{
|
||||
if (RemotePlayer?.MediaStatus?.QueueItems.Count == 0)
|
||||
for (int i = 0; i < queue.Count; i++)
|
||||
{
|
||||
Toast.MakeText(MainActivity.instance, "QueueItems count == 0", ToastLength.Long).Show();
|
||||
return;
|
||||
if (queue[i].IsYt && !queue[i].IsParsed)
|
||||
queue[i] = await ParseSong(queue[i]);
|
||||
}
|
||||
|
||||
RemotePlayer.QueueLoad(queue.ConvertAll(GetQueueItem).ToArray(), currentID, 0, CurrentPosition, null);
|
||||
|
||||
if (noisyRegistered)
|
||||
UnregisterReceiver(noisyReceiver);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
player.Stop();
|
||||
player.Release();
|
||||
player = null;
|
||||
}
|
||||
|
||||
if (isRunning)
|
||||
RemotePlayer.Play();
|
||||
|
||||
Initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async static void GetQueueFromCast()
|
||||
{
|
||||
if (UseCastPlayer && Initialized)
|
||||
{
|
||||
if(RemotePlayer.CurrentItem != null)
|
||||
currentID = RemotePlayer.MediaQueue.IndexOfItemWithId(RemotePlayer.CurrentItem.ItemId);
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Gms.Cast.Framework.Media;
|
||||
using Android.Graphics;
|
||||
using Android.OS;
|
||||
using Android.Support.Design.Widget;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Support.V7.Widget;
|
||||
using Android.Support.V7.Widget.Helper;
|
||||
@@ -20,7 +18,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public static Queue instance;
|
||||
public RecyclerView ListView;
|
||||
public RecyclerAdapter adapter;
|
||||
public QueueAdapter adapter;
|
||||
public ItemTouchHelper itemTouchHelper;
|
||||
public IMenu menu;
|
||||
|
||||
@@ -44,12 +42,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
ListView = FindViewById<RecyclerView>(Resource.Id.recycler);
|
||||
ListView.SetLayoutManager(new LinearLayoutManager(Application.Context));
|
||||
|
||||
if (MusicPlayer.queue != null)
|
||||
adapter = new RecyclerAdapter(MusicPlayer.queue);
|
||||
else
|
||||
adapter = new RecyclerAdapter(new List<Song>());
|
||||
|
||||
adapter = new QueueAdapter(MusicPlayer.queue);
|
||||
ListView.SetAdapter(adapter);
|
||||
adapter.ItemClick += ListView_ItemClick;
|
||||
adapter.ItemLongCLick += ListView_ItemLongCLick;
|
||||
@@ -65,8 +58,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
private void Scroll(object sender, View.ScrollChangeEventArgs e)
|
||||
{
|
||||
if (((LinearLayoutManager)ListView.GetLayoutManager()).FindLastCompletelyVisibleItemPosition() == adapter.songList.Count)
|
||||
LoadMore();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
@@ -81,14 +73,7 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
|
||||
if (!MusicPlayer.UseCastPlayer)
|
||||
adapter.UpdateList(MusicPlayer.queue);
|
||||
else
|
||||
{
|
||||
adapter.NotifyDataSetChanged();
|
||||
MusicPlayer.RemotePlayer.MediaQueue.RegisterCallback(new QueueCallback(adapter));
|
||||
}
|
||||
adapter.UpdateList(MusicPlayer.queue);
|
||||
}
|
||||
|
||||
public void RefreshCurrent()
|
||||
@@ -158,11 +143,6 @@ namespace MusicApp.Resources.Portable_Class
|
||||
item.Icon.ClearColorFilter();
|
||||
}
|
||||
|
||||
public void LoadMore()
|
||||
{
|
||||
List<Song> songList = MusicPlayer.queue.Except(adapter.songList).ToList();
|
||||
}
|
||||
|
||||
private void ListView_ItemClick(object sender, int Position)
|
||||
{
|
||||
Song item = MusicPlayer.queue[Position];
|
||||
|
||||
+63
-54
@@ -1,10 +1,10 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Gms.Cast.Framework.Media;
|
||||
using Android.Graphics;
|
||||
using Android.Support.Design.Widget;
|
||||
using Android.Support.V7.Widget;
|
||||
using Android.Views;
|
||||
using Java.Lang;
|
||||
using MusicApp.Resources.values;
|
||||
using Square.Picasso;
|
||||
using System;
|
||||
@@ -12,19 +12,16 @@ using System.Collections.Generic;
|
||||
|
||||
namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class RecyclerAdapter : RecyclerView.Adapter, IItemTouchAdapter
|
||||
public class QueueAdapter : RecyclerView.Adapter, IItemTouchAdapter
|
||||
{
|
||||
public List<Song> songList;
|
||||
public event EventHandler<int> ItemClick;
|
||||
public event EventHandler<int> ItemLongCLick;
|
||||
public int listPadding;
|
||||
|
||||
public RecyclerAdapter(List<Song> songList)
|
||||
public QueueAdapter(List<Song> songList)
|
||||
{
|
||||
this.songList = songList;
|
||||
|
||||
if(MusicPlayer.UseCastPlayer)
|
||||
MusicPlayer.RemotePlayer.MediaQueue.RegisterCallback(new QueueCallback(this));
|
||||
}
|
||||
|
||||
public void UpdateList(List<Song> songList)
|
||||
@@ -65,10 +62,52 @@ namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
RecyclerHolder holder = (RecyclerHolder)viewHolder;
|
||||
|
||||
Song song = MusicPlayer.UseCastPlayer ? (Song)MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(position) : songList[position];
|
||||
if (MainActivity.Theme == 1)
|
||||
{
|
||||
holder.more.SetColorFilter(Color.White);
|
||||
holder.reorder.SetColorFilter(Color.White);
|
||||
holder.Title.SetTextColor(Color.White);
|
||||
holder.Artist.SetTextColor(Color.White);
|
||||
holder.Artist.Alpha = 0.7f;
|
||||
holder.youtubeIcon.SetColorFilter(Color.White);
|
||||
holder.ItemView.SetBackgroundColor(Color.ParseColor("#424242"));
|
||||
}
|
||||
else
|
||||
holder.ItemView.SetBackgroundColor(Color.White);
|
||||
|
||||
holder.reorder.Visibility = ViewStates.Visible;
|
||||
if (position == MusicPlayer.CurrentID())
|
||||
{
|
||||
holder.status.Visibility = ViewStates.Visible;
|
||||
holder.status.Text = MusicPlayer.isRunning ? "Playing" : "Paused";
|
||||
holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245));
|
||||
}
|
||||
else
|
||||
holder.status.Visibility = ViewStates.Gone;
|
||||
|
||||
|
||||
Song song = songList.Count <= position ? null : songList[position];
|
||||
if (song == null)
|
||||
{
|
||||
if (holder.Title.Text.Length == 0)
|
||||
holder.Title.Text = "aizquruhgqognbq";
|
||||
if (holder.Artist.Text.Length == 0)
|
||||
holder.Artist.Text = "ZJKGNZgzn";
|
||||
|
||||
holder.Title.SetTextColor(Color.Transparent);
|
||||
holder.Title.SetBackgroundResource(Resource.Color.background_material_dark);
|
||||
holder.Artist.SetTextColor(Color.Transparent);
|
||||
holder.Artist.SetBackgroundResource(Resource.Color.background_material_dark);
|
||||
holder.AlbumArt.SetImageResource(Resource.Color.background_material_dark);
|
||||
|
||||
MusicPlayer.RemotePlayer.MediaQueue.GetItemAtIndex(position);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.Title.SetBackgroundResource(0);
|
||||
holder.Artist.SetBackgroundResource(0);
|
||||
}
|
||||
|
||||
holder.Title.Text = song.Title;
|
||||
holder.Artist.Text = song.Artist;
|
||||
@@ -115,61 +154,31 @@ namespace MusicApp.Resources.Portable_Class
|
||||
else
|
||||
holder.Title.SetTextSize(Android.Util.ComplexUnitType.Dip, 14);
|
||||
|
||||
float scale = MainActivity.instance.Resources.DisplayMetrics.Density;
|
||||
if (Queue.instance != null)
|
||||
if (!song.IsParsed && song.IsYt)
|
||||
{
|
||||
holder.reorder.Visibility = ViewStates.Visible;
|
||||
if (!song.IsParsed && song.IsYt)
|
||||
{
|
||||
holder.youtubeIcon.SetImageResource(Resource.Drawable.needProcessing);
|
||||
holder.youtubeIcon.Visibility = ViewStates.Visible;
|
||||
|
||||
if (MainActivity.Theme == 1)
|
||||
holder.youtubeIcon.SetColorFilter(Color.White);
|
||||
}
|
||||
else if (song.IsYt)
|
||||
{
|
||||
holder.youtubeIcon.SetImageResource(Resource.Drawable.PublicIcon);
|
||||
holder.youtubeIcon.Visibility = ViewStates.Visible;
|
||||
|
||||
if (MainActivity.Theme == 1)
|
||||
holder.youtubeIcon.SetColorFilter(Color.White);
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.youtubeIcon.Visibility = ViewStates.Gone;
|
||||
}
|
||||
|
||||
if (position == MusicPlayer.CurrentID())
|
||||
{
|
||||
holder.status.Visibility = ViewStates.Visible;
|
||||
holder.status.Text = MusicPlayer.isRunning ? "Playing" : "Paused";
|
||||
holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245));
|
||||
}
|
||||
else
|
||||
holder.status.Visibility = ViewStates.Gone;
|
||||
holder.youtubeIcon.SetImageResource(Resource.Drawable.needProcessing);
|
||||
holder.youtubeIcon.Visibility = ViewStates.Visible;
|
||||
}
|
||||
else if (song.IsYt)
|
||||
{
|
||||
holder.youtubeIcon.SetImageResource(Resource.Drawable.PublicIcon);
|
||||
holder.youtubeIcon.Visibility = ViewStates.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.reorder.Visibility = ViewStates.Gone;
|
||||
holder.youtubeIcon.Visibility = ViewStates.Gone;
|
||||
}
|
||||
|
||||
if (MainActivity.Theme == 1)
|
||||
{
|
||||
holder.more.SetColorFilter(Color.White);
|
||||
holder.reorder.SetColorFilter(Color.White);
|
||||
holder.Title.SetTextColor(Color.White);
|
||||
holder.Artist.SetTextColor(Color.White);
|
||||
holder.Artist.Alpha = 0.7f;
|
||||
}
|
||||
|
||||
if (MainActivity.Theme == 0)
|
||||
holder.ItemView.SetBackgroundColor(Color.White);
|
||||
else
|
||||
holder.ItemView.SetBackgroundColor(Color.ParseColor("#424242"));
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position, IList<Java.Lang.Object> payloads)
|
||||
{
|
||||
if (payloads.Count > 0 && payloads[0].ToString() == ((RecyclerHolder)holder).Title.Text)
|
||||
return;
|
||||
|
||||
base.OnBindViewHolder(holder, position, payloads);
|
||||
}
|
||||
|
||||
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
if (viewType == 0)
|
||||
@@ -1,53 +0,0 @@
|
||||
using Android.Gms.Cast.Framework.Media;
|
||||
using Android.Support.V7.Widget;
|
||||
|
||||
namespace MusicApp.Resources.Portable_Class
|
||||
{
|
||||
public class QueueCallback : MediaQueue.Callback
|
||||
{
|
||||
public RecyclerView.Adapter adapter;
|
||||
|
||||
public QueueCallback(RecyclerView.Adapter adapter)
|
||||
{
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
|
||||
public override void ItemsInsertedInRange(int insertIndex, int insertCount)
|
||||
{
|
||||
base.ItemsInsertedInRange(insertIndex, insertCount);
|
||||
adapter.NotifyItemRangeInserted(insertIndex, insertCount);
|
||||
}
|
||||
|
||||
public override void ItemsReloaded()
|
||||
{
|
||||
base.ItemsReloaded();
|
||||
adapter.NotifyDataSetChanged();
|
||||
}
|
||||
|
||||
public override void ItemsRemovedAtIndexes(int[] indexes)
|
||||
{
|
||||
base.ItemsRemovedAtIndexes(indexes);
|
||||
foreach(int index in indexes)
|
||||
adapter.NotifyItemRemoved(index);
|
||||
}
|
||||
|
||||
public override void ItemsUpdatedAtIndexes(int[] indexes)
|
||||
{
|
||||
base.ItemsUpdatedAtIndexes(indexes);
|
||||
foreach (int index in indexes)
|
||||
adapter.NotifyItemChanged(index);
|
||||
}
|
||||
|
||||
public override void MediaQueueChanged()
|
||||
{
|
||||
base.MediaQueueChanged();
|
||||
adapter.NotifyDataSetChanged();
|
||||
}
|
||||
|
||||
public override void MediaQueueWillChange()
|
||||
{
|
||||
base.MediaQueueWillChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Android.Gms.Cast;
|
||||
using Java.Lang;
|
||||
using Newtonsoft.Json;
|
||||
using SQLite;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user