private async void LoadingByFilter(string filter, string id_string)
        {
            var result = await json.GetStringbyJson("https://api-v2.soundcloud.com/charts?kind=" + filter + "&genre=soundcloud%3Agenres%3Aall-music&limit=25&client_id=9ac2b17027e4af068adbb4f10330e1b3&offset=" + offset);


            if (result != "")
            {
                items = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackModel.RootObject> (result);
                if (items.collection != null || items.collection.Count == 0)
                {
                    if (id_string == "normal")
                    {
                        lst.Adapter = new TrackAdapter(Activity, items.collection);
                    }
                    else if (id_string == "moreItem")
                    {
                        var adapter = lst.Adapter as TrackAdapter;
                        adapter._tracks.AddRange(items.collection);
                        Toast.MakeText(Application.Context, "Loaded more tracks", ToastLength.Long).Show();
                        lst.Adapter = adapter;
                        adapter.NotifyDataSetChanged();
                    }
                }

                //Track.AddRange (items.tracks);
                //AddTrack(items.tracks);
            }
        }
示例#2
0
        public async void loadMoreData(int off)
        {
            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=" + off);

            if (result != null)
            {
                items = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackModel.RootObject> (result);
                //tAdapter = new TrackAdapter (this.Activity,items.tracks);
                if (items.collection != null)
                {
                    var adapter = lst.Adapter as TrackAdapter;
                    adapter._tracks.AddRange(items.collection);
                    Toast.MakeText(Application.Context, "Loaded more tracks", ToastLength.Long).Show();
                    lst.Adapter = adapter;
                    tAdapter.NotifyDataSetChanged();
                }


                //lst.Adapter = new TrackAdapter (Activity, items.tracks);
            }
        }
示例#3
0
        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(AudioPlayer));

                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);
            };
        }