Exemplo n.º 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.MainTaskListFragment, container, false);

            View header = Activity.LayoutInflater.Inflate(Resource.Layout.MainTaskListHeader, null);
            mainList = view.FindViewById<ExpandableListView>(Resource.Id.mainActivitiesList);
            mainList.AddHeaderView(header, null, false);
            mainList.SetAdapter(new ScenarioListAdapter(Activity,
                AppData.Session.Categories.ToArray()));
            mainList.ChildClick += mainList_ChildClick;

            // When the pull to refresh is activated, pull new data from the server and refresh the list with the new data
            refresher = view.FindViewById<SwipeRefreshLayout>(Resource.Id.refresher);
            refresher.Refresh += async delegate
            {
                if (!AndroidUtils.IsConnected())
                {
                    AndroidUtils.OfflineAlert(Activity);
                    refresher.Refreshing = false;
                    return;
                }

                await ServerData.FetchCategories();
                refresher.Refreshing = false;

                ((ScenarioListAdapter) mainList.ExpandableListAdapter).Categories = AppData.Session.Categories.ToArray();
                Activity.RunOnUiThread(
                    () => ((ScenarioListAdapter) mainList.ExpandableListAdapter).NotifyDataSetChanged());
            };

            // If there's only one category, it makes sense to expand it by default
            if (AppData.Session.Categories.Count == 1)
            {
                mainList.ExpandGroup(0, true);
            }

            practiceBtn = header.FindViewById<Button>(Resource.Id.practiceAreaBtn);
            practiceBtn.Click += practiceButton_Click;
            return view;
        }