Beispiel #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var rootView = inflater.Inflate(Resource.Layout.fragment_list, container, false);

            browserAdapter = new BrowseAdapter(Activity);

            var controls = rootView.FindViewById(Resource.Id.controls);

            controls.Visibility = ViewStates.Gone;

            var listView = rootView.FindViewById <ListView> (Resource.Id.list_view);

            listView.Adapter    = browserAdapter;
            listView.ItemClick += (sender, e) => {
                var item = browserAdapter.GetItem(e.Position);
                try {
                    var listener = (IFragmentDataHelper)Activity;
                    listener.OnMediaItemSelected(item);
                } catch (InvalidCastException ex) {
                    Log.Error(Tag, "Exception trying to cast to FragmentDataHelper", ex);
                }
            };
            var args = Arguments;

            mediaId      = args.GetString(ArgMediaId, null);
            mediaBrowser = new MediaBrowser(Activity,
                                            new ComponentName(Activity, Java.Lang.Class.FromType(typeof(MusicService))),
                                            connectionCallback, null);
            subscriptionCallback.OnChildrenLoadedImpl = (parentId, children) => {
                browserAdapter.Clear();
                browserAdapter.NotifyDataSetInvalidated();
                foreach (MediaBrowser.MediaItem item in children)
                {
                    browserAdapter.Add(item);
                }
                browserAdapter.NotifyDataSetChanged();
            };
            subscriptionCallback.OnErrorImpl   = (id) => Toast.MakeText(Activity, "Error Loading Media", ToastLength.Long).Show();
            connectionCallback.OnConnectedImpl = () => {
                LogHelper.Debug(Tag, "onConnected: session token " + mediaBrowser.SessionToken);
                if (mediaId == null)
                {
                    mediaId = mediaBrowser.Root;
                }
                mediaBrowser.Subscribe(mediaId, subscriptionCallback);
                if (mediaBrowser.SessionToken == null)
                {
                    throw new ArgumentNullException("No Session token");
                }
                var mediaController = new Android.Media.Session.MediaController(Activity, mediaBrowser.SessionToken);
                Activity.MediaController = mediaController;
            };
            connectionCallback.OnConnectionFailedImpl    = () => LogHelper.Debug(Tag, "onConnectionFailed");
            connectionCallback.OnConnectionSuspendedImpl = () => {
                LogHelper.Debug(Tag, "onConnectionSuspended");
                Activity.MediaController = null;
            };
            return(rootView);
        }
Beispiel #2
0
 public void Refresh()
 {
     adapter.NotifyDataSetChanged();
 }
Beispiel #3
0
 private void OnRefresh(object sender, System.EventArgs e)
 {
     adapter.NotifyDataSetChanged();
 }