Exemplo n.º 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.activity_playlist, container, false);

            //var tracks_in_playlist_i_know_im_really_bad_at_naming = Core.VKontakte.Music.Playlist.GetById(playlist.Id);
            Activity.FindViewById <TextView>(Resource.Id.titlebar_title).Text = "Плейлист";
            Handler handler = new Handler(Looper.MainLooper);
            var     tracks  = new List <AudioFile>();

            adapter = new TrackAdapter(tracks, "false");

            var plists_recycler = view.FindViewById <RecyclerView>(Resource.Id.tracksPlaylistView);
            var trackscount     = view.FindViewById <TextView>(Resource.Id.countTracksPlaylistView);
            var title           = view.FindViewById <TextView>(Resource.Id.namePlaylistView);
            var genre           = view.FindViewById <TextView>(Resource.Id.genrePlaylistView);
            var author          = view.FindViewById <TextView>(Resource.Id.artistPlaylistView);
            var year            = view.FindViewById <TextView>(Resource.Id.yearPlaylistView);
            var cover           = view.FindViewById <RoundedImageView>(Resource.Id.coverPlaylistView);

            adapter.ItemClick += AdapterOnItemClick;

            if (playlist.Cover != "playlist_placeholder")
            {
                cover.SetImageString(playlist.Cover, 50, 50);
            }
            if (playlist.Cover == "playlist_placeholder")
            {
                cover.SetImageResource(Resource.Drawable.playlist_placeholder);
            }


            title.Text  = playlist.Name;
            genre.Text  = playlist.Genre;
            author.Text = playlist.Artist;
            year.Text   = playlist.Year;

            plists_recycler.SetAdapter(adapter);
            plists_recycler.Clickable = true;
            plists_recycler.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Vertical, false));

            var actualtracks = Task.Run(async() =>
            {
                return(await Core.VKontakte.Music.Playlist.GetTracks(playlist.Id, playlist.OwnerId, playlist.AccessKey));
            });

            try {
                tracks = MusicService.ConvertToAudioFile(actualtracks.Result);
                this.playlist.TracksFiles = tracks;
                adapter.AddItems(tracks);
                adapter.ItemClick += AdapterOnItemClick;

                if (playlist.Cover != "playlist_placeholder")
                {
                    cover.SetImageString(playlist.Cover, 50, 50);
                }
                if (playlist.Cover == "playlist_placeholder")
                {
                    cover.SetImageResource(Resource.Drawable.playlist_placeholder);
                }

                trackscount.Text = $"{actualtracks.Result.Count} треков";
                title.Text       = playlist.Name;
                genre.Text       = playlist.Genre;
                author.Text      = playlist.Artist;
                year.Text        = playlist.Year;

                plists_recycler.SetAdapter(adapter);
                plists_recycler.Clickable = true;
                plists_recycler.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Vertical, false));
            }
            catch (System.Exception e)
            {
                Toast.MakeText(Application.Context, $"Произошла ошибка. Видимо, ВКонтакте не дает нам доступ к этому плейлисту.", ToastLength.Long).Show();
                view = inflater.Inflate(Resource.Layout.errorActivity, container, false);
            }

            return(view);
        }
Exemplo n.º 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.activity_tracks, container, false);

            List <AudioFile> tracks = new List <AudioFile>();

            Tracks  = tracks;
            adapter = new TrackAdapter(tracks);

            List <PlaylistFile> plists = new List <PlaylistFile>();

            Playlists = plists;
            pAdapter  = new PlaylistAdapter(plists);

            var tracksView  = view.FindViewById <RecyclerView>(Resource.Id.list_tracks);
            var progressBar = view.FindViewById <ProgressBar>(Resource.Id.progressBar_tracks);

            var playlistsView        = view.FindViewById <RecyclerView>(Resource.Id.list_plists);
            var playlistsProgressBar = view.FindViewById <ProgressBar>(Resource.Id.progressBar_library_plists);

            Handler handler = new Handler(Looper.MainLooper);

            adapter.ItemClick  += AdapterOnItemClick;
            pAdapter.ItemClick += PlaylistOnItemClick;

            tracksView.SetAdapter(adapter);
            tracksView.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Vertical, false));
            RegisterForContextMenu(tracksView);
            tracksView.Clickable = true;

            playlistsView.SetAdapter(pAdapter);
            playlistsView.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Horizontal, false));
            playlistsView.Clickable = true;

            var scrollListener = new Listeners.OnScrollToBottomListener(() =>
            {
                //if (!HasLoading) return;
                var task = Task.Run(() =>
                {
                    handler.Post(new Runnable(() =>
                    {
                        progressBar.Visibility = ViewStates.Visible;
                    }));
                    try
                    {
                        tracks = MusicService.GetMusicLibrary(15, adapter.ItemCount);
                        var i  = 1 + 1; //Без этого нихуя не работает.
                        Fooxboy.MusicX.Core.Log.Debug(i.ToString());
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(Application.Context, $"Произошла ошибка: {e.ToString()}", ToastLength.Long).Show();
                    }
                });

                bool end = false;
                task.ContinueWith((t) =>
                {
                    while (tracks.Count == 0)
                    {
                        System.Threading.Thread.Sleep(300);
                    }

                    HasLoading = !(tracks.Count < 15);
                    handler.Post(new Runnable(() =>
                    {
                        var count = adapter.ItemCount;
                        adapter.AddItems(tracks);
                        TracksInLibrary.AddRange(tracks);
                        adapter.NotifyItemRangeChanged(count, tracks.Count);
                        progressBar.Visibility = ViewStates.Invisible;
                        end = true;
                    }));
                });
                var a = task.ConfigureAwait(false);
                while (!end)
                {
                    System.Threading.Thread.Sleep(300);
                }
            });

            tracksView.AddOnScrollListener(scrollListener);


            var plistsScrollListener = new Listeners.OnScrollToBottomListener(() =>
            {
                if (!HasLoading)
                {
                    return;
                }
                var task = Task.Run(() =>
                {
                    handler.Post(new Runnable(() =>
                    {
                        playlistsProgressBar.Visibility = ViewStates.Visible;
                    }));
                    try
                    {
                        //tracks = MusicService.GetMusicLibrary(15, adapter.ItemCount);
                        var vkplists = Core.VKontakte.Music.Library.PlaylistsSync(15, pAdapter.ItemCount);
                        plists       = PlaylistsService.CovertToPlaylistFiles(vkplists);
                        var i        = 1 + 1; //Без этого нихуя не работает.
                        Fooxboy.MusicX.Core.Log.Debug(i.ToString());
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(Application.Context, $"Произошла ошибка: {e.ToString()}", ToastLength.Long).Show();
                    }
                });

                bool end = false;
                task.ContinueWith((t) =>
                {
                    while (plists.Count == 0)
                    {
                        System.Threading.Thread.Sleep(300);
                    }

                    HasLoading = !(plists.Count < 15);
                    handler.Post(new Runnable(() =>
                    {
                        var count = pAdapter.ItemCount;
                        pAdapter.AddItems(plists);
                        PlaylistsInLibrary.AddRange(plists);
                        pAdapter.NotifyItemRangeChanged(count, plists.Count);
                        playlistsProgressBar.Visibility = ViewStates.Invisible;
                        end = true;
                    }));
                });
                var a = task.ConfigureAwait(false);
                while (!end)
                {
                    System.Threading.Thread.Sleep(300);
                }
            });

            playlistsView.AddOnScrollListener(plistsScrollListener);

            if (pAdapter.ItemCount == 0)
            {
                plistsScrollListener.InvokeCallback();
            }
            if (adapter.ItemCount == 0)
            {
                scrollListener.InvokeCallback();
            }

            return(view);
        }