diff --git a/MusicApp/MusicApp.csproj b/MusicApp/MusicApp.csproj
index d13c0e9..f39c686 100644
--- a/MusicApp/MusicApp.csproj
+++ b/MusicApp/MusicApp.csproj
@@ -638,6 +638,9 @@
+
+
+
diff --git a/MusicApp/Resources/Portable Class/Home.cs b/MusicApp/Resources/Portable Class/Home.cs
index 4306dc0..eec5f19 100644
--- a/MusicApp/Resources/Portable Class/Home.cs
+++ b/MusicApp/Resources/Portable Class/Home.cs
@@ -24,6 +24,8 @@ namespace MusicApp.Resources.Portable_Class
public HomeAdapter adapter;
public ItemTouchHelper itemTouchHelper;
public static List adapterItems = new List();
+ public List selectedTopics = new List();
+ public List selectedTopicsID = new List();
public View view;
public override void OnActivityCreated(Bundle savedInstanceState)
@@ -113,8 +115,6 @@ namespace MusicApp.Resources.Portable_Class
ListView.SetItemAnimator(new DefaultItemAnimator());
ListView.ScrollChange += MainActivity.instance.Scroll;
- List selectedTopics = new List();
- List selectedTopicsID = new List();
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Activity);
List topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
foreach (string topic in topics)
@@ -288,7 +288,49 @@ namespace MusicApp.Resources.Portable_Class
break;
}
}
+
+ r = new Random();
+ if (r.Next(0, 100) > 90)
+ AddHomeTopics();
}
+ else
+ {
+ AddHomeTopics();
+ }
+ }
+
+ public async void AddHomeTopics()
+ {
+ await MainActivity.instance.WaitForYoutube();
+
+ List channelLits = new List();
+
+ string nextPageToken = "";
+ while (nextPageToken != null)
+ {
+ YouTubeService youtube = YoutubeEngine.youtubeService;
+ SubscriptionsResource.ListRequest request = youtube.Subscriptions.List("snippet,contentDetails");
+ request.ChannelId = "UCh3mHcmSMffgVxFniKQrpug";
+ request.MaxResults = 50;
+ request.PageToken = nextPageToken;
+
+ SubscriptionListResponse response = await request.ExecuteAsync();
+
+ foreach (var item in response.Items)
+ {
+ Song channel = new Song(item.Snippet.Title.Substring(0, item.Snippet.Title.IndexOf(" - Topic")), item.Snippet.Description, item.Snippet.Thumbnails.Default__.Url, item.Snippet.ResourceId.ChannelId, -1, -1, null, true);
+ channelLits.Add(channel);
+ }
+
+ nextPageToken = response.NextPageToken;
+ }
+
+ Random r = new Random();
+ List channels = channelLits.OrderBy(x => r.Next()).ToList();
+ channels.RemoveAll(x => selectedTopics.Contains(x.GetName()));
+
+ HomeSection TopicSelector = new HomeSection("Music Genres", SectionType.TopicSelector, channels);
+ adapter.AddToList(new List { TopicSelector });
}
public static Fragment NewInstance()
diff --git a/MusicApp/Resources/Portable Class/HomeAdapter.cs b/MusicApp/Resources/Portable Class/HomeAdapter.cs
index df243e9..a02873e 100644
--- a/MusicApp/Resources/Portable Class/HomeAdapter.cs
+++ b/MusicApp/Resources/Portable Class/HomeAdapter.cs
@@ -1,4 +1,5 @@
-using Android.Graphics;
+using Android.Content;
+using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Support.V7.Widget;
using Android.Views;
@@ -44,16 +45,21 @@ namespace MusicApp.Resources.Portable_Class
View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.LineSongs, parent, false);
return new LineSongHolder(itemView, OnClick, OnLongClick);
}
- else /*if(viewType == 1)*/
+ else if (viewType == 1)
{
View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.HomeChannels, parent, false);
return new LineSongHolder(itemView, OnClick, OnLongClick);
}
- //else
+ //else if(viewType == 2)
//{
// View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.HomePlaylists, parent, false);
// return new LineSongHolder(itemView, OnClick, OnLongClick);
//}
+ else
+ {
+ View itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.HomeTopic, parent, false);
+ return new LineSongHolder(itemView, OnClick, OnLongClick);
+ }
}
public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
@@ -111,8 +117,6 @@ namespace MusicApp.Resources.Portable_Class
if (MainActivity.Theme == 1)
holder.ItemView.SetBackgroundColor(Color.Argb(255, 62, 62, 62));
}
- //Youtube topics channels don't have playlist list others than artist mixes
-
//else if (items[position].contentType == SectionType.PlaylistList)
//{
// LineSongHolder holder = (LineSongHolder)viewHolder;
@@ -123,6 +127,21 @@ namespace MusicApp.Resources.Portable_Class
// if (MainActivity.Theme == 1)
// holder.ItemView.SetBackgroundColor(Color.Argb(255, 62, 62, 62));
//}
+ else if(items[position].contentType == SectionType.TopicSelector)
+ {
+ LineSongHolder holder = (LineSongHolder)viewHolder;
+ holder.title.Text = items[position].SectionTitle;
+ holder.recycler.SetLayoutManager(new LinearLayoutManager(MainActivity.instance, LinearLayoutManager.Vertical, false));
+ holder.recycler.SetAdapter(new HomeChannelAdapter(items[position].contentValue));
+ holder.more.Click += (sender, e) =>
+ {
+ Intent intent = new Intent(MainActivity.instance, typeof(Preferences));
+ MainActivity.instance.StartActivity(intent);
+ };
+
+ if (MainActivity.Theme == 1)
+ holder.ItemView.SetBackgroundColor(Color.Argb(255, 62, 62, 62));
+ }
}
void OnClick(int position)
@@ -151,8 +170,10 @@ namespace MusicApp.Resources.Portable_Class
return 0;
else if (items[position].contentType == SectionType.ChannelList)
return 1;
- else
+ else if (items[position].contentType == SectionType.PlaylistList)
return 2;
+ else
+ return 3;
}
}
}
\ No newline at end of file
diff --git a/MusicApp/Resources/Portable Class/HomeChannelAdapter.cs b/MusicApp/Resources/Portable Class/HomeChannelAdapter.cs
index f87db5a..bc15160 100644
--- a/MusicApp/Resources/Portable Class/HomeChannelAdapter.cs
+++ b/MusicApp/Resources/Portable Class/HomeChannelAdapter.cs
@@ -1,9 +1,14 @@
using Android.App;
+using Android.Content;
+using Android.Support.V7.Preferences;
using Android.Support.V7.Widget;
using Android.Views;
+using Android.Widget;
using MusicApp.Resources.values;
using Square.Picasso;
using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
namespace MusicApp.Resources.Portable_Class
{
@@ -12,8 +17,9 @@ namespace MusicApp.Resources.Portable_Class
public RecyclerView recycler;
public int listPadding = 0;
public List songList;
+ private bool useTopic = false;
- public override int ItemCount => songList.Count;
+ public override int ItemCount => useTopic ? 3 : songList.Count;
public HomeChannelAdapter(List songList, RecyclerView recycler)
{
@@ -21,6 +27,12 @@ namespace MusicApp.Resources.Portable_Class
this.songList = songList;
}
+ public HomeChannelAdapter(List songList)
+ {
+ this.songList = songList;
+ useTopic = true;
+ }
+
public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
{
RecyclerHolder holder = (RecyclerHolder)viewHolder;
@@ -29,16 +41,54 @@ namespace MusicApp.Resources.Portable_Class
var songAlbumArtUri = Android.Net.Uri.Parse(songList[position].GetAlbum());
Picasso.With(Application.Context).Load(songAlbumArtUri).Placeholder(Resource.Drawable.MusicIcon).Resize(400, 400).CenterCrop().Transform(new CircleTransformation()).Into(holder.AlbumArt);
- if (songList[position].GetArtist() != null)
- holder.action.Text = "Mix";
-
- if(!holder.action.HasOnClickListeners)
+ if (!useTopic)
{
- holder.action.Click += (sender, e) =>
+ if (songList[position].GetArtist() != null)
+ holder.action.Text = "Mix";
+
+ if (!holder.action.HasOnClickListeners)
{
- if (songList[position].GetArtist() != null)
- Playlist.PlayInOrder(songList[position].GetArtist());
- };
+ holder.action.Click += (sender, e) =>
+ {
+ if (songList[position].GetArtist() != null)
+ Playlist.PlayInOrder(songList[position].GetArtist());
+ };
+ }
+ }
+ else
+ {
+ holder.action.Text = "Follow";
+
+ if (!holder.action.HasOnClickListeners)
+ {
+ holder.action.Click += async (sender, e) =>
+ {
+ ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(MainActivity.instance);
+ List topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
+
+ ISharedPreferencesEditor editor = prefManager.Edit();
+ topics.Add(songList[position].GetName() + "/#-#/" + songList[position].youtubeID);
+ editor.PutStringSet("selectedTopics", topics);
+ editor.Apply();
+
+ holder.action.Text = "Following";
+ await Task.Delay(1000);
+
+ if(position == 0 || position == 1)
+ {
+ if (songList.Count < 4)
+ return;
+
+ songList[position] = songList[songList.Count - 1];
+ songList.RemoveAt(songList.Count - 1);
+ }
+ else
+ songList.RemoveAt(position);
+
+ NotifyItemChanged(position);
+ };
+ }
+ holder.ItemView.SetPadding(4, 1, 4, 1);
}
}
diff --git a/MusicApp/Resources/Portable Class/Preferences.cs b/MusicApp/Resources/Portable Class/Preferences.cs
index 9ea4f31..db9dc43 100644
--- a/MusicApp/Resources/Portable Class/Preferences.cs
+++ b/MusicApp/Resources/Portable Class/Preferences.cs
@@ -121,13 +121,13 @@ namespace MusicApp.Resources.Portable_Class
if (topics.Length == 0)
topicPreference.Summary = "Actually nothing";
else if (topics.Length == 1)
- topicPreference.Summary = topics[0];
+ topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/"));
else if (topics.Length == 2)
- topicPreference.Summary = topics[0] + " and " + topics[1];
+ topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + " and " + topics[1].Substring(0, topics[1].IndexOf("/#-#/"));
else if(topics.Length == 3)
- topicPreference.Summary = topics[0] + ", " + topics[1] + " and " + topics[2];
+ topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + " and " + topics[2].Substring(0, topics[2].IndexOf("/#-#/"));
else if(topics.Length > 3)
- topicPreference.Summary = topics[0] + ", " + topics[1] + ", " + topics[2] + " and more.";
+ topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + ", " + topics[2].Substring(0, topics[2].IndexOf("/#-#/")) + " and more.";
//Download Path
Preference downloadPref = PreferenceScreen.FindPreference("downloadPath");
diff --git a/MusicApp/Resources/Portable Class/RecyclerHolder.cs b/MusicApp/Resources/Portable Class/RecyclerHolder.cs
index 884d77f..bc52b9c 100644
--- a/MusicApp/Resources/Portable Class/RecyclerHolder.cs
+++ b/MusicApp/Resources/Portable Class/RecyclerHolder.cs
@@ -17,6 +17,7 @@ namespace MusicApp.Resources.Portable_Class
public ImageView youtubeIcon;
public ImageView more;
public TextView status;
+ public CheckBox checkBox;
public Button action;
public RecyclerHolder(View itemView, Action listener, Action longListener) : base(itemView)
@@ -30,6 +31,7 @@ namespace MusicApp.Resources.Portable_Class
youtubeIcon = itemView.FindViewById(Resource.Id.youtubeIcon);
more = itemView.FindViewById(Resource.Id.moreButton);
status = itemView.FindViewById(Resource.Id.status);
+ checkBox = itemView.FindViewById(Resource.Id.checkBox);
action = itemView.FindViewById