public override async void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);

            this.Activity.Title = "Principal";

            await Task.Run(async() =>
            {
                await ViewModel.LoadHome();
            });

            // await ViewModel.LoadHome();

            if (ViewModel.Tracks != null && ViewModel.Tracks.Count > 0)
            {
                trackAdapter            = new TrackAdapter(ViewModel.Tracks);
                trackAdapter.ItemClick += TrackAdapter_ItemClick;
                trackList.SetAdapter(trackAdapter);
            }
            if (ViewModel.Artists != null && ViewModel.Artists.Count > 0)
            {
                artistAdapter            = new ArtistAdapter(ViewModel.Artists);
                artistAdapter.ItemClick += ArtistAdapter_ItemClick;
                artistList.SetAdapter(artistAdapter);
            }
        }
Exemplo n.º 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.searchActivity, container, false);

            edittext              = view.FindViewById <EditText>(Resource.Id.searchEditText);
            resultsList           = view.FindViewById <RecyclerView>(Resource.Id.searchResults);
            placeholderLayout     = view.FindViewById <RelativeLayout>(Resource.Id.searchPlaceholder);
            progress              = view.FindViewById <ProgressBar>(Resource.Id.searchProgress);
            this.adapter          = new TrackAdapter(new List <Models.AudioFile>());
            resultsList.Clickable = true;
            RegisterForContextMenu(resultsList);
            resultsList.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Vertical, false));
            Handler handler = new Handler(Looper.MainLooper);

            edittext.KeyPress += (sender, e) =>
            {
                e.Handled = false;
                if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter && edittext.Text != "")
                {
                    placeholderLayout.Visibility = ViewStates.Gone;
                    //var results = Core.VKontakte.Music.Search.TracksSync(edittext.Text);
                    progress.Visibility = ViewStates.Visible;
                    Task.Run(() => RefreshResults(new Handler(Looper.MainLooper)));
                    e.Handled = true;
                }

                /*if(e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
                 * {
                 *
                 *  placeholderLayout.Visibility = ViewStates.Gone;
                 *  //var results = Core.VKontakte.Music.Search.TracksSync(edittext.Text);
                 *  progress.Visibility = ViewStates.Visible;
                 *  adapter = new TrackAdapter(new List<Models.AudioFile>(), "false");
                 *  adapter.ItemClick += AdapterOnItemClick;
                 *  var results = Core.VKontakte.Music.Search.TracksSync(edittext.Text);
                 *  this.tracksInResult = Services.MusicService.ConvertToAudioFile(results);
                 *  adapter.AddItems(this.tracksInResult);
                 *  resultsList.RemoveAllViewsInLayout();
                 *  resultsList.RemoveAllViews();
                 *  resultsList.SwapAdapter(adapter, true);
                 *  progress.Visibility = ViewStates.Gone;
                 *  e.Handled = true;
                 *
                 * }*/
            };


            return(view);
        }
Exemplo n.º 3
0
        private async void RefreshResults(Handler handler)
        {
            var results = Core.VKontakte.Music.Search.TracksSync(edittext.Text);

            this.tracksInResult = Services.MusicService.ConvertToAudioFile(results);
            adapter             = new TrackAdapter(tracksInResult, "false");
            adapter.ItemClick  += AdapterOnItemClick;
            handler.Post(new Runnable(() =>
            {
                resultsList.RemoveAllViewsInLayout();
                resultsList.RemoveAllViews();
                resultsList.SwapAdapter(adapter, true);
                progress.Visibility = ViewStates.Gone;
            }));
        }
Exemplo n.º 4
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Inflate the view
            var view = inflater.Inflate(Resource.Layout.SearchFragment, container, false);

            // Get our RecyclerView layout
            _recyclerView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView);

            // Use the built-in linear layout manager:
            _layoutManager = new LinearLayoutManager(view.Context);

            // Plug the layout manager into the RecyclerView:
            _recyclerView.SetLayoutManager(_layoutManager);

            // Setup the adapter
            _adapter            = new TrackAdapter(_searchTracks);
            _adapter.ItemClick += OnItemClick;

            // Plug the adapter into the RecyclerView:
            _recyclerView.SetAdapter(_adapter);

            // Search button logic
            var searchButton = view.FindViewById <Button>(Resource.Id.randPickButton);

            searchButton.Click += async delegate
            {
                _searchTracks.Clear();

                var searchResults = await new SearchSoundCloudTrackSource
                {
                    SearchQuery = "monstercat"
                }.GetItemsAsync(40, null);

                foreach (var result in searchResults.Items)
                {
                    _searchTracks.Add(result);
                }

                // Update the RecyclerView by notifying the adapter:
                // Notify that the top and a randomly-chosen photo has changed (swapped):
                _adapter.NotifyDataSetChanged();
                _adapter.NotifyItemChanged(0);
            };

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

            adapter = new TrackAdapter(tracks, "false");
            var tracksView  = view.FindViewById <RecyclerView>(Resource.Id.list_tracks);
            var progressBar = view.FindViewById <ProgressBar>(Resource.Id.progressBar_tracks);

            progressBar.Visibility = ViewStates.Gone;
            adapter.ItemClick     += AdapterOnItemClick;
            tracksView.SetAdapter(adapter);

            tracksView.SetLayoutManager(new LinearLayoutManager(Application.Context, LinearLayoutManager.Vertical, false));

            RegisterForContextMenu(tracksView);
            tracksView.Clickable = true;
            return(view);
        }
        public async override void OnActivityCreated(Bundle savedInstancesState)
        {
            base.OnActivityCreated(savedInstancesState);

            //activity = this.Activity;
            //ActionBar actionBar = activity.ActionBar;

            //activity.ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_arrow_back_white_24dp);
            //activity.ActionBar.SetHomeButtonEnabled (FragmentManager.BackStackEntryCount>0);
            //activity.ActionBar.Title ="";

            /*
             *          genreFragment = new GenreFragment ();
             *          TracksByGenres tracksbynews = new TracksByGenres ();
             *          //Get data from GenreFragment.cs
             *          tracksbynews.AddData(genreFragment.mData);
             */
            // Find id of listview
            lst = View.FindViewById <ListView>(Resource.Id.lsttrack);


            //Get data by json

            var result = await json.GetStringbyJson("https://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3A" + mData + "&limit=20&client_id=9ac2b17027e4af068adbb4f10330e1b3&app_version=1462873750&offset=" + offset);

            if (result != null)
            {
                items       = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackModel.RootObject>(result);
                tAdapter    = new TrackAdapter(Activity, items.collection);
                lst.Adapter = tAdapter;
            }

            //Check the last of item of listview and show more data.

            lst.ScrollStateChanged += (object sender, AbsListView.ScrollStateChangedEventArgs e) =>
            {
                int lastItem = lst.LastVisiblePosition;

                int adapterCount = lst.Count - 1;

                if (lastItem >= adapterCount)
                {
                    offset += 25;
                    loadMoreData(offset);
                }
            };



            lst.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
                /*
                 *              FragmentTransaction fragTransaction = this.FragmentManager.BeginTransaction ();
                 *              AudioPlayer audio = new AudioPlayer ();
                 *              audio.AddArrayData(items.tracks,e.Position);
                 *              fragTransaction.Replace(Resource.Id.fragmentContainer,audio);
                 *              fragTransaction.AddToBackStack(null);
                 *              fragTransaction.Commit();
                 */
                var data = new Intent(this.Activity, typeof(AudioPlayerActivity));

                if (audioPlayer.mListData.Count == 0)
                {
                    var adapter = lst.Adapter as TrackAdapter;
                    var track   = Newtonsoft.Json.JsonConvert.SerializeObject(adapter._tracks);

                    data.PutExtra("listdata", track);
                    data.PutExtra("position", e.Position.ToString()).ToString();
                }
                else
                {
                    data.PutExtra("position", e.Position.ToString()).ToString();
                }


                StartActivity(data);
            };
        }
Exemplo n.º 7
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.º 8
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);
        }