Adding channel mix to searched one and removing topic selector/channel follow (was usless).

This commit is contained in:
Tristan Roux
2019-03-11 21:06:07 +01:00
parent 98f8f0f850
commit 7082f134c4
12 changed files with 700 additions and 1068 deletions

View File

@@ -334,7 +334,6 @@
<Compile Include="Resources\Portable Class\CastCallback.cs" />
<Compile Include="Resources\Portable Class\CastProvider.cs" />
<Compile Include="Resources\Portable Class\CastQueueManager.cs" />
<Compile Include="Resources\Portable Class\ChannelAdapter.cs" />
<Compile Include="Resources\Portable Class\ChannelPreviewHolder.cs" />
<Compile Include="Resources\Portable Class\CircleTransformation.cs" />
<Compile Include="Resources\Portable Class\CollapsingToolbar.cs" />
@@ -381,7 +380,6 @@
<Compile Include="Resources\Portable Class\SnackbarCallback.cs" />
<Compile Include="Resources\Portable Class\SuggestionAdapter.cs" />
<Compile Include="Resources\Portable Class\PlaylistItem.cs" />
<Compile Include="Resources\Portable Class\TopicSelector.cs" />
<Compile Include="Resources\Portable Class\TwoLineAdapter.cs" />
<Compile Include="Resources\Portable Class\UslessHolder.cs" />
<Compile Include="Resources\Portable Class\ViewPagerAdapter.cs" />

View File

@@ -1,65 +0,0 @@
using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using Opus.Resources.values;
using Square.Picasso;
using System.Collections.Generic;
namespace Opus.Resources.Portable_Class
{
public class ChannelAdapter : ArrayAdapter
{
private Context context;
private List<Song> channelList;
private LayoutInflater inflater;
private int resource;
public ChannelAdapter(Context context, int resource, List<Song> channelList) : base(context, resource, channelList)
{
this.context = context;
this.resource = resource;
this.channelList = channelList;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
if (position > channelList.Count || position < 0)
return convertView;
if (inflater == null)
{
inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
}
if (convertView == null)
{
convertView = inflater.Inflate(resource, parent, false);
}
ChannelHolder holder = new ChannelHolder(convertView)
{
Title = { Text = channelList[position].Title },
Artist = { Text = channelList[position].Artist },
};
Picasso.With(Application.Context).Load(channelList[position].Album).Placeholder(Resource.Color.background_material_dark).Transform(new CircleTransformation()).Into(holder.AlbumArt);
if (MainActivity.Theme == 1)
{
holder.Title.SetTextColor(Color.White);
holder.Artist.SetTextColor(Color.White);
holder.Artist.Alpha = 0.7f;
}
else
holder.CheckBox.ButtonTintList = ColorStateList.ValueOf(Color.Argb(255, 117, 117, 117));
if (TopicSelector.instance.selectedTopics.Contains(channelList[position].Title))
holder.CheckBox.Checked = true;
else
holder.CheckBox.Checked = false;
return convertView;
}
}
}

View File

@@ -12,7 +12,6 @@ namespace Opus.Resources.values
public TextView Title;
public TextView Artist;
public ImageView AlbumArt;
public CheckBox CheckBox;
public ChannelHolder(View v)
{
@@ -20,7 +19,6 @@ namespace Opus.Resources.values
Title = v.FindViewById<TextView>(Resource.Id.title);
Artist = v.FindViewById<TextView>(Resource.Id.artist);
AlbumArt = v.FindViewById<ImageView>(Resource.Id.albumArt);
CheckBox = v.FindViewById<CheckBox>(Resource.Id.checkBox);
}
}
@@ -30,7 +28,6 @@ namespace Opus.Resources.values
public TextView Title;
public TextView Artist;
public ImageView AlbumArt;
public CheckBox CheckBox;
public Button action;
public RecyclerChannelHolder(View itemView, Action<int> listener, Action<int> longListener) : base(itemView)
@@ -39,7 +36,6 @@ namespace Opus.Resources.values
Title = itemView.FindViewById<TextView>(Resource.Id.title);
Artist = itemView.FindViewById<TextView>(Resource.Id.artist);
AlbumArt = itemView.FindViewById<ImageView>(Resource.Id.albumArt);
CheckBox = itemView.FindViewById<CheckBox>(Resource.Id.checkBox);
action = itemView.FindViewById<Button>(Resource.Id.action);
if (listener != null)

View File

@@ -61,7 +61,7 @@ namespace Opus.Resources.Portable_Class
}
#pragma warning restore CS4014
private async Task PopulateSongs()
private /*async Task */ void PopulateSongs()
{
if (!populating)
{
@@ -128,247 +128,247 @@ namespace Opus.Resources.Portable_Class
adapter.ItemClick += ListView_ItemClick;
ListView.SetItemAnimator(new DefaultItemAnimator());
ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.instance.GetSystemService(Context.ConnectivityService);
NetworkInfo activeNetworkInfo = connectivityManager.ActiveNetworkInfo;
if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
return;
//ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.instance.GetSystemService(Context.ConnectivityService);
//NetworkInfo activeNetworkInfo = connectivityManager.ActiveNetworkInfo;
//if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
// return;
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Activity);
List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
foreach (string topic in topics)
{
selectedTopics.Add(topic.Substring(0, topic.IndexOf("/#-#/")));
selectedTopicsID.Add(topic.Substring(topic.IndexOf("/#-#/") + 5));
}
//ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Activity);
//List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
//foreach (string topic in topics)
//{
// selectedTopics.Add(topic.Substring(0, topic.IndexOf("/#-#/")));
// selectedTopicsID.Add(topic.Substring(topic.IndexOf("/#-#/") + 5));
//}
if (!await MainActivity.instance.WaitForYoutube())
return;
//if (!await MainActivity.instance.WaitForYoutube())
// return;
if (instance == null)
return;
//if (instance == null)
// return;
if (selectedTopicsID.Count > 0)
{
List<HomeItem> Items = new List<HomeItem>();
foreach (string topic in selectedTopicsID)
{
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
ChannelSectionsResource.ListRequest request = youtube.ChannelSections.List("snippet, contentDetails");
request.ChannelId = topic;
//if (selectedTopicsID.Count > 0)
//{
// List<HomeItem> Items = new List<HomeItem>();
// foreach (string topic in selectedTopicsID)
// {
// try
// {
// YouTubeService youtube = YoutubeEngine.youtubeService;
// ChannelSectionsResource.ListRequest request = youtube.ChannelSections.List("snippet, contentDetails");
// request.ChannelId = topic;
ChannelSectionListResponse response = await request.ExecuteAsync();
// ChannelSectionListResponse response = await request.ExecuteAsync();
foreach (var section in response.Items)
{
if (section.Snippet.Type == "channelsectionTypeUndefined")
continue;
// foreach (var section in response.Items)
// {
// if (section.Snippet.Type == "channelsectionTypeUndefined")
// continue;
string title = section.Snippet.Title;
if (title == null || title == "")
title = selectedTopics[selectedTopicsID.IndexOf(topic)];
// string title = section.Snippet.Title;
// if (title == null || title == "")
// title = selectedTopics[selectedTopicsID.IndexOf(topic)];
if (title == "Popular Artists" || title == "Featured channels")
title = (selectedTopics[selectedTopicsID.IndexOf(topic)].Contains(" Music") ? selectedTopics[selectedTopicsID.IndexOf(topic)].Substring(0, selectedTopics[selectedTopicsID.IndexOf(topic)].IndexOf(" Music")) : selectedTopics[selectedTopicsID.IndexOf(topic)]) + "'s " + title;
// if (title == "Popular Artists" || title == "Featured channels")
// title = (selectedTopics[selectedTopicsID.IndexOf(topic)].Contains(" Music") ? selectedTopics[selectedTopicsID.IndexOf(topic)].Substring(0, selectedTopics[selectedTopicsID.IndexOf(topic)].IndexOf(" Music")) : selectedTopics[selectedTopicsID.IndexOf(topic)]) + "'s " + title;
if (title == "Popular Channels")
continue;
// if (title == "Popular Channels")
// continue;
if (Items.Exists(x => x.SectionTitle == title))
continue;
// if (Items.Exists(x => x.SectionTitle == title))
// continue;
SectionType type = SectionType.None;
List<string> contentValue = null;
switch (section.Snippet.Type)
{
case "multipleChannels":
type = SectionType.ChannelList;
contentValue = section.ContentDetails.Channels.ToList();
break;
case "multiplePlaylists":
contentValue = section.ContentDetails.Playlists.ToList();
type = SectionType.PlaylistList;
break;
case "singlePlaylist":
contentValue = section.ContentDetails.Playlists.ToList();
type = SectionType.SinglePlaylist;
break;
default:
contentValue = new List<string>();
break;
}
// SectionType type = SectionType.None;
// List<string> contentValue = null;
// switch (section.Snippet.Type)
// {
// case "multipleChannels":
// type = SectionType.ChannelList;
// contentValue = section.ContentDetails.Channels.ToList();
// break;
// case "multiplePlaylists":
// contentValue = section.ContentDetails.Playlists.ToList();
// type = SectionType.PlaylistList;
// break;
// case "singlePlaylist":
// contentValue = section.ContentDetails.Playlists.ToList();
// type = SectionType.SinglePlaylist;
// break;
// default:
// contentValue = new List<string>();
// break;
// }
HomeItem item = new HomeItem(title, type, contentValue);
Items.Add(item);
}
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
}
List<HomeItem> playlistList = Items.FindAll(x => x.contentType == SectionType.PlaylistList);
Items.RemoveAll(x => x.contentType == SectionType.PlaylistList);
Random r = new Random();
Items = Items.OrderBy(x => r.Next()).ToList();
Items.AddRange(playlistList);
// HomeItem item = new HomeItem(title, type, contentValue);
// Items.Add(item);
// }
// }
// catch (System.Net.Http.HttpRequestException)
// {
// MainActivity.instance.Timout();
// }
// }
// List<HomeItem> playlistList = Items.FindAll(x => x.contentType == SectionType.PlaylistList);
// Items.RemoveAll(x => x.contentType == SectionType.PlaylistList);
// Random r = new Random();
// Items = Items.OrderBy(x => r.Next()).ToList();
// Items.AddRange(playlistList);
foreach (HomeItem item in Items)
{
List<Song> contentValue = new List<Song>();
switch (item.contentType)
{
case SectionType.SinglePlaylist:
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
// foreach (HomeItem item in Items)
// {
// List<Song> contentValue = new List<Song>();
// switch (item.contentType)
// {
// case SectionType.SinglePlaylist:
// try
// {
// YouTubeService youtube = YoutubeEngine.youtubeService;
PlaylistItemsResource.ListRequest request = youtube.PlaylistItems.List("snippet, contentDetails");
request.PlaylistId = item.contentValue[0];
request.MaxResults = 25;
request.PageToken = "";
// PlaylistItemsResource.ListRequest request = youtube.PlaylistItems.List("snippet, contentDetails");
// request.PlaylistId = item.contentValue[0];
// request.MaxResults = 25;
// request.PageToken = "";
PlaylistItemListResponse response = await request.ExecuteAsync();
// PlaylistItemListResponse response = await request.ExecuteAsync();
if (response.Items.Count < 10)
break;
// if (response.Items.Count < 10)
// break;
foreach (var ytItem in response.Items)
{
if (ytItem.Snippet.Title != "[Deleted video]" && ytItem.Snippet.Title != "Private video" && ytItem.Snippet.Title != "Deleted video")
{
Song song = new Song(ytItem.Snippet.Title, ytItem.Snippet.ChannelTitle, ytItem.Snippet.Thumbnails.High.Url, ytItem.ContentDetails.VideoId, -1, -1, ytItem.ContentDetails.VideoId, true, false);
contentValue.Add(song);
// foreach (var ytItem in response.Items)
// {
// if (ytItem.Snippet.Title != "[Deleted video]" && ytItem.Snippet.Title != "Private video" && ytItem.Snippet.Title != "Deleted video")
// {
// Song song = new Song(ytItem.Snippet.Title, ytItem.Snippet.ChannelTitle, ytItem.Snippet.Thumbnails.High.Url, ytItem.ContentDetails.VideoId, -1, -1, ytItem.ContentDetails.VideoId, true, false);
// contentValue.Add(song);
if (instance == null)
return;
}
}
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
// if (instance == null)
// return;
// }
// }
// }
// catch (System.Net.Http.HttpRequestException)
// {
// MainActivity.instance.Timout();
// }
HomeSection section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
adapter.AddToList(new List<HomeSection>() { section });
break;
case SectionType.ChannelList:
foreach (string channelID in item.contentValue)
{
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
// HomeSection section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
// adapter.AddToList(new List<HomeSection>() { section });
// break;
// case SectionType.ChannelList:
// foreach (string channelID in item.contentValue)
// {
// try
// {
// YouTubeService youtube = YoutubeEngine.youtubeService;
ChannelsResource.ListRequest req = youtube.Channels.List("snippet");
req.Id = channelID;
// ChannelsResource.ListRequest req = youtube.Channels.List("snippet");
// req.Id = channelID;
ChannelListResponse resp = await req.ExecuteAsync();
// ChannelListResponse resp = await req.ExecuteAsync();
foreach (var ytItem in resp.Items)
{
Song channel = new Song(ytItem.Snippet.Title.Contains(" - Topic") ? ytItem.Snippet.Title.Substring(0, ytItem.Snippet.Title.IndexOf(" - Topic")) : ytItem.Snippet.Title, null, ytItem.Snippet.Thumbnails.Default__.Url, channelID, -1, -1, null, true);
contentValue.Add(channel);
// foreach (var ytItem in resp.Items)
// {
// Song channel = new Song(ytItem.Snippet.Title.Contains(" - Topic") ? ytItem.Snippet.Title.Substring(0, ytItem.Snippet.Title.IndexOf(" - Topic")) : ytItem.Snippet.Title, null, ytItem.Snippet.Thumbnails.Default__.Url, channelID, -1, -1, null, true);
// contentValue.Add(channel);
if (instance == null)
return;
}
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
}
// if (instance == null)
// return;
// }
// }
// catch (System.Net.Http.HttpRequestException)
// {
// MainActivity.instance.Timout();
// }
// }
section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
adapter.AddToList(new List<HomeSection>() { section });
break;
case SectionType.PlaylistList:
foreach (string playlistID in item.contentValue)
{
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
// section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
// adapter.AddToList(new List<HomeSection>() { section });
// break;
// case SectionType.PlaylistList:
// foreach (string playlistID in item.contentValue)
// {
// try
// {
// YouTubeService youtube = YoutubeEngine.youtubeService;
PlaylistsResource.ListRequest request = youtube.Playlists.List("snippet, contentDetails");
request.Id = playlistID;
// PlaylistsResource.ListRequest request = youtube.Playlists.List("snippet, contentDetails");
// request.Id = playlistID;
PlaylistListResponse response = await request.ExecuteAsync();
// PlaylistListResponse response = await request.ExecuteAsync();
foreach (var playlist in response.Items)
{
Song song = new Song(playlist.Snippet.Title, playlist.Snippet.ChannelTitle, playlist.Snippet.Thumbnails.Default__.Url, playlist.Id, -1, -1, playlist.Id, true);
contentValue.Add(song);
// foreach (var playlist in response.Items)
// {
// Song song = new Song(playlist.Snippet.Title, playlist.Snippet.ChannelTitle, playlist.Snippet.Thumbnails.Default__.Url, playlist.Id, -1, -1, playlist.Id, true);
// contentValue.Add(song);
if (instance == null)
return;
}
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
}
// if (instance == null)
// return;
// }
// }
// catch (System.Net.Http.HttpRequestException)
// {
// MainActivity.instance.Timout();
// }
// }
section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
List<Song> removedValues = new List<Song>();
for (int i = 0; i < adapter.ItemCount; i++)
{
if (adapter.items[i].contentType == SectionType.ChannelList)
{
for (int j = 0; j < adapter.items[i].contentValue.Count; j++)
{
if (section.contentValue.Exists(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)))
{
adapter.items[i].contentValue[j].Artist = section.contentValue.Find(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)).YoutubeID;
removedValues.Add(section.contentValue.Find(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)));
if (j < 4 && adapter.items[i].recycler != null)
{
RecyclerHolder holder = (RecyclerHolder)adapter.items[i].recycler.GetChildViewHolder(adapter.items[i].recycler.GetLayoutManager().FindViewByPosition(j));
holder.action.Text = "Mix";
}
}
}
}
}
//section.contentValue = section.contentValue.Except(removedValues).ToList();
//if(section.contentValue.Count > 0)
// adapter.AddToList(new List<HomeSection>() { section });
break;
default:
break;
}
}
// section = new HomeSection(item.SectionTitle, item.contentType, contentValue);
// List<Song> removedValues = new List<Song>();
// for (int i = 0; i < adapter.ItemCount; i++)
// {
// if (adapter.items[i].contentType == SectionType.ChannelList)
// {
// for (int j = 0; j < adapter.items[i].contentValue.Count; j++)
// {
// if (section.contentValue.Exists(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)))
// {
// adapter.items[i].contentValue[j].Artist = section.contentValue.Find(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)).YoutubeID;
// removedValues.Add(section.contentValue.Find(x => x.Title.Contains(adapter.items[i].contentValue[j].Title)));
// if (j < 4 && adapter.items[i].recycler != null)
// {
// RecyclerHolder holder = (RecyclerHolder)adapter.items[i].recycler.GetChildViewHolder(adapter.items[i].recycler.GetLayoutManager().FindViewByPosition(j));
// holder.action.Text = "Mix";
// }
// }
// }
// }
// }
// //section.contentValue = section.contentValue.Except(removedValues).ToList();
// //if(section.contentValue.Count > 0)
// // adapter.AddToList(new List<HomeSection>() { section });
// break;
// default:
// break;
// }
// }
r = new Random();
if (r.Next(0, 100) > 90)
await AddHomeTopics();
// r = new Random();
// if (r.Next(0, 100) > 90)
// await AddHomeTopics();
for (int i = 0; i < adapter.items.Count; i++)
{
if (adapter.items[i].contentType == SectionType.ChannelList)
{
for (int j = 0; j < adapter.items[i].contentValue.Count; j++)
{
if (adapter.items[i].contentValue[j].Artist == null)
{
adapter.items[i].contentValue[j].Artist = "Follow";
if (j < 4 && adapter.items[i].recycler != null)
{
RecyclerHolder holder = (RecyclerHolder)adapter.items[i].recycler.GetChildViewHolder(adapter.items[i].recycler.GetLayoutManager().FindViewByPosition(j));
holder.action.Text = "Follow";
}
}
}
}
}
}
else
{
await AddHomeTopics();
}
// for (int i = 0; i < adapter.items.Count; i++)
// {
// if (adapter.items[i].contentType == SectionType.ChannelList)
// {
// for (int j = 0; j < adapter.items[i].contentValue.Count; j++)
// {
// if (adapter.items[i].contentValue[j].Artist == null)
// {
// adapter.items[i].contentValue[j].Artist = "Follow";
// if (j < 4 && adapter.items[i].recycler != null)
// {
// RecyclerHolder holder = (RecyclerHolder)adapter.items[i].recycler.GetChildViewHolder(adapter.items[i].recycler.GetLayoutManager().FindViewByPosition(j));
// holder.action.Text = "Follow";
// }
// }
// }
// }
// }
//}
//else
//{
// await AddHomeTopics();
//}
populating = false;
}
}
@@ -438,7 +438,8 @@ namespace Opus.Resources.Portable_Class
public async Task Refresh()
{
await PopulateSongs();
/*await*/ PopulateSongs();
await Task.Delay(0); //WE DONT NEED TO TALK ABOUT THIS
}
public void LoadMore()

View File

@@ -11,7 +11,6 @@ namespace Opus.Resources.values
public TextView Title;
public TextView Artist;
public ImageView AlbumArt;
public CheckBox CheckBox;
public HomeChannelHolder(View itemView, Action<int> listener, Action<int> longListener) : base(itemView)
{
@@ -19,7 +18,6 @@ namespace Opus.Resources.values
Title = itemView.FindViewById<TextView>(Resource.Id.title);
Artist = itemView.FindViewById<TextView>(Resource.Id.artist);
AlbumArt = itemView.FindViewById<ImageView>(Resource.Id.albumArt);
CheckBox = itemView.FindViewById<CheckBox>(Resource.Id.checkBox);
itemView.Click += (sender, e) => listener(AdapterPosition);
itemView.LongClick += (sender, e) => longListener(AdapterPosition);

View File

@@ -39,49 +39,20 @@ namespace Opus.Resources.Portable_Class
instance = this;
toolbar.NavigationClick += (sender, e) =>
{
if (DownloadFragment.instance == null && TopicSelector.instance == null)
if (DownloadFragment.instance == null)
Finish();
else
else if (DownloadFragment.instance != null)
{
if (DownloadFragment.instance != null)
{
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefManager.Edit();
editor.PutString("downloadPath", DownloadFragment.instance.path);
editor.Apply();
Preference downloadPref = PreferencesFragment.instance.PreferenceScreen.FindPreference("downloadPath");
downloadPref.Summary = DownloadFragment.instance.path ?? Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString();
PreferencesFragment.instance.path = DownloadFragment.instance.path;
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefManager.Edit();
editor.PutString("downloadPath", DownloadFragment.instance.path);
editor.Apply();
Preference downloadPref = PreferencesFragment.instance.PreferenceScreen.FindPreference("downloadPath");
downloadPref.Summary = DownloadFragment.instance.path ?? Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic).ToString();
PreferencesFragment.instance.path = DownloadFragment.instance.path;
DownloadFragment.instance = null;
SupportFragmentManager.PopBackStack();
}
else if (TopicSelector.instance != null)
{
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefManager.Edit();
List<string> topics = new List<string>();
for (int i = 0; i < TopicSelector.instance.selectedTopics.Count; i++)
{
topics.Add(TopicSelector.instance.selectedTopics[i] + "/#-#/" + TopicSelector.instance.selectedTopicsID[i]);
}
editor.PutStringSet("selectedTopics", topics);
editor.Apply();
TopicSelector.instance = null;
SupportFragmentManager.PopBackStack();
Preference topicPreference = PreferencesFragment.instance.PreferenceScreen.FindPreference("topics");
if (topics.Count == 0)
topicPreference.Summary = Resources.GetString(Resource.String.genre_nothing);
else if (topics.Count == 1)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/"));
else if (topics.Count == 2)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and) + topics[1].Substring(0, topics[1].IndexOf("/#-#/"));
else if (topics.Count == 3)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and) + topics[2].Substring(0, topics[2].IndexOf("/#-#/"));
else if (topics.Count > 3)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + ", " + topics[2].Substring(0, topics[2].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and_more);
}
DownloadFragment.instance = null;
SupportFragmentManager.PopBackStack();
}
};
@@ -131,23 +102,6 @@ namespace Opus.Resources.Portable_Class
SetPreferencesFromResource(Resource.Layout.Preferences, rootKey);
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
//Music Genres
Preference topicPreference = PreferenceScreen.FindPreference("topics");
topicPreference.IconSpaceReserved = false;
topicPreference.PreferenceClick += TopicPreference;
string[] topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToArray();
if (topics.Length == 0)
topicPreference.Summary = Resources.GetString(Resource.String.genre_nothing);
else if (topics.Length == 1)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/"));
else if (topics.Length == 2)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and) + topics[1].Substring(0, topics[1].IndexOf("/#-#/"));
else if(topics.Length == 3)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and) + topics[2].Substring(0, topics[2].IndexOf("/#-#/"));
else if(topics.Length > 3)
topicPreference.Summary = topics[0].Substring(0, topics[0].IndexOf("/#-#/")) + ", " + topics[1].Substring(0, topics[1].IndexOf("/#-#/")) + ", " + topics[2].Substring(0, topics[2].IndexOf("/#-#/")) + Resources.GetString(Resource.String.and_more);
//Download Path
Preference downloadPref = PreferenceScreen.FindPreference("downloadPath");
downloadPref.IconSpaceReserved = false;
@@ -234,14 +188,6 @@ namespace Opus.Resources.Portable_Class
MainActivity.instance.InvalidateOptionsMenu();
}
#region Topic Preference
private void TopicPreference(object sender, Preference.PreferenceClickEventArgs e)
{
Preferences.instance.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.PreferenceFragment, TopicSelector.NewInstance()).AddToBackStack(null).Commit();
Preferences.instance.toolbar.Title = "Music Genres";
}
#endregion
#region Download location
private void DownloadClick(object sender, Preference.PreferenceClickEventArgs e)
{

View File

@@ -1,168 +0,0 @@
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Support.V4.App;
using Android.Support.V7.Preferences;
using Android.Views;
using Android.Widget;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Opus.Resources.values;
using System.Collections.Generic;
using System.Linq;
namespace Opus.Resources.Portable_Class
{
public class TopicSelector : ListFragment
{
public static TopicSelector instance;
public string path;
public List<string> selectedTopics = new List<string>();
public List<string> selectedTopicsID = new List<string>();
private List<Song> channels = new List<Song>();
private ChannelAdapter adapter;
private View emptyView;
public async override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
if (!await MainActivity.instance.WaitForYoutube())
{
System.Console.WriteLine("&Youtube awaited");
ListAdapter = null;
emptyView = LayoutInflater.Inflate(Resource.Layout.EmptyView, null);
((TextView)emptyView).Text = "Error while loading.\nCheck your internet connection and check if your logged in.";
((TextView)emptyView).SetTextColor(Color.Red);
Activity.AddContentView(emptyView, ListView.LayoutParameters);
return;
}
if (instance == null)
return;
List<Song> channelList = new List<Song>();
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
foreach(string topic in topics)
{
selectedTopics.Add(topic.Substring(0, topic.IndexOf("/#-#/")));
selectedTopicsID.Add(topic.Substring(topic.IndexOf("/#-#/") + 5));
}
string nextPageToken = "";
while (nextPageToken != null)
{
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
SubscriptionsResource.ListRequest request = youtube.Subscriptions.List("snippet,contentDetails");
request.ChannelId = "UCRPb0XKQwDoHbgvtawH-gGw";
request.MaxResults = 50;
request.PageToken = nextPageToken;
SubscriptionListResponse response = await request.ExecuteAsync();
if (instance == null)
return;
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);
channelList.Add(channel);
}
nextPageToken = response.NextPageToken;
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
}
List<string> topicList = channelList.ConvertAll(x => x.YoutubeID);
foreach (string channelID in selectedTopicsID.Except(topicList))
{
try
{
YouTubeService youtube = YoutubeEngine.youtubeService;
ChannelsResource.ListRequest req = youtube.Channels.List("snippet");
req.Id = channelID;
ChannelListResponse resp = await req.ExecuteAsync();
if (instance == null)
return;
foreach (var ytItem in resp.Items)
{
Song channel = new Song(ytItem.Snippet.Title.Contains(" - Topic") ? ytItem.Snippet.Title.Substring(0, ytItem.Snippet.Title.IndexOf(" - Topic")) : ytItem.Snippet.Title, "", ytItem.Snippet.Thumbnails.Default__.Url, channelID, -1, -1, null, true);
channelList.Add(channel);
if (instance == null)
return;
}
}
catch (System.Net.Http.HttpRequestException)
{
MainActivity.instance.Timout();
}
}
if (instance == null)
return;
channels = channelList.OrderBy(x => x.Title).ToList();
adapter = new ChannelAdapter(Android.App.Application.Context, Resource.Layout.ChannelList, channels);
ListAdapter = adapter;
ListView.TextFilterEnabled = true;
ListView.ItemClick += ListView_ItemClick;
}
public static Fragment NewInstance()
{
instance = new TopicSelector { Arguments = new Bundle() };
return instance;
}
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
Song channel = channels[e.Position];
bool Checked = selectedTopics.Contains(channel.Title);
e.View.FindViewById<CheckBox>(Resource.Id.checkBox).Checked = !Checked;
if (!Checked)
{
selectedTopics.Add(channel.Title);
selectedTopicsID.Add(channel.YoutubeID);
}
else
{
int index = selectedTopics.IndexOf(channel.Title);
selectedTopics.RemoveAt(index);
selectedTopicsID.RemoveAt(index);
}
}
public override void OnStop()
{
if (emptyView != null)
{
ViewGroup rootView = Activity.FindViewById<ViewGroup>(Android.Resource.Id.Content);
rootView.RemoveView(emptyView);
}
base.OnStop();
Preferences.instance.toolbar.Title = Preferences.instance.GetString(Resource.String.settings);
}
public override void OnViewCreated(View view, Bundle savedInstanceState)
{
if (MainActivity.Theme == 1)
view.SetBackgroundColor(Color.Argb(225, 33, 33, 33));
base.OnViewCreated(view, savedInstanceState);
}
}
}

View File

@@ -301,10 +301,6 @@ namespace Opus.Resources.Portable_Class
if (nextPageToken != null)
result.Add(new YtFile(new Song(), YtKind.Loading));
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(MainActivity.instance);
List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
List<string> selectedTopics = topics.ConvertAll(x => x.Substring(x.IndexOf("/#-#/") + 5));
if(result.Count > 0 && result[0].Kind == YtKind.Channel && result.Count(x => x.item.Artist == result[0].item.Title && x.Kind == YtKind.Video) > 0)
{
YtFile channelPreview = new YtFile(result[0].item, YtKind.ChannelPreview);
@@ -335,7 +331,7 @@ namespace Opus.Resources.Portable_Class
}
}
adapter = new YtAdapter(result, selectedTopics);
adapter = new YtAdapter(result);
adapter.ItemClick += ListView_ItemClick;
adapter.ItemLongCLick += ListView_ItemLongClick;
ListView.SetAdapter(adapter);

View File

@@ -18,14 +18,12 @@ namespace Opus.Resources.Portable_Class
{
public int listPadding;
private List<YtFile> items;
public List<string> selectedTopicsID;
public event EventHandler<int> ItemClick;
public event EventHandler<int> ItemLongCLick;
public YtAdapter(List<YtFile> items, List<string> selectedTopicsID)
public YtAdapter(List<YtFile> items)
{
this.items = items;
this.selectedTopicsID = selectedTopicsID;
}
public override int ItemCount => items.Count;
@@ -120,48 +118,11 @@ namespace Opus.Resources.Portable_Class
holder.Title.Text = song.Title;
Picasso.With(Android.App.Application.Context).Load(song.Album).Placeholder(Resource.Color.background_material_dark).Transform(new CircleTransformation(false)).Into(holder.AlbumArt);
holder.action.Visibility = ViewStates.Visible;
holder.CheckBox.Visibility = ViewStates.Gone;
if (selectedTopicsID.Contains(song.YoutubeID))
holder.action.Text = "Unfollow";
else
holder.action.Text = "Follow";
if (!holder.action.HasOnClickListeners)
{
holder.action.Click += async (sender, e) =>
holder.action.Click += (sender, e) =>
{
if (holder.action.Text == "Following" || holder.action.Text == "Unfollow")
{
holder.action.Text = "Unfollowed";
selectedTopicsID.Remove(song.YoutubeID);
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(MainActivity.instance);
List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
ISharedPreferencesEditor editor = prefManager.Edit();
topics.Remove(song.Title + "/#-#/" + song.YoutubeID);
editor.PutStringSet("selectedTopics", topics);
editor.Apply();
await Task.Delay(1000);
holder.action.Text = "Follow";
}
else if (holder.action.Text == "Follow")
{
selectedTopicsID.Add(song.YoutubeID);
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(MainActivity.instance);
List<string> topics = prefManager.GetStringSet("selectedTopics", new string[] { }).ToList();
ISharedPreferencesEditor editor = prefManager.Edit();
topics.Add(song.Title + "/#-#/" + song.YoutubeID);
editor.PutStringSet("selectedTopics", topics);
editor.Apply();
holder.action.Text = "Following";
await Task.Delay(1000);
holder.action.Text = "Unfollow";
}
YoutubeEngine.instances[0].MixFromChannel(song.YoutubeID);
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -13,15 +13,6 @@
android:padding="5dp"
android:gravity="center"
android:src="@drawable/MusicIcon" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="25dp"
android:layout_height="25dp"
android:paddingRight="5dp"
android:focusable="false"
android:clickable="false"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
<Button
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
@@ -29,31 +20,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="?colorAccent"
android:layout_toLeftOf="@id/checkBox"
android:visibility="gone"
android:text="Loading"
android:text="@string/create_mix"
android:id="@+id/action"/>
<LinearLayout
android:orientation="vertical"
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_toLeftOf="@id/action"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:id="@+id/textLayout"
android:paddingLeft="70dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#000"
android:textStyle="bold" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dip"
android:textColor="#000"
android:maxLines="2" />
</LinearLayout>
android:layout_toLeftOf="@id/action"
android:paddingLeft="70dp"
android:textSize="14dip"
android:textColor="#000"
android:textStyle="bold" />
</RelativeLayout >

View File

@@ -4,10 +4,6 @@
xmlns:app="http://schemas.android/com/apk/res-auto"
android:id="@+id/PreferenceScreen">
<android.support.v7.preference.PreferenceCategory android:title="@string/behavior" android:id="@+id/behavior" >
<android.support.v7.preference.Preference
android:key="topics"
android:title="@string/music_genres"
android:summary="Actualy nothing"/>
<Opus.SeekbarPreference
android:title="@string/volume"
android:key="volumeMultipler" />