Пример #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Gets the layout, and all the relevant views it contains.
            Layout = inflater.Inflate(Resource.Layout.EventList, null)
                             .FindViewById<FrameLayout>(Resource.Id.layout);
            List = Layout.FindViewById<ListView>(Resource.Id.list);

            // Show spinner
            Layout.RemoveAllViews();
            Layout.AddView(new ProgressBar(Activity));

            ThreadPool.QueueUserWorkItem(o =>
            {
                // Get joined events and create adapter.
                Adapter = new EventAdapter<Event>(Activity, MainActivity.CIF.GetJoinedEvents(100));

                // On leave click
                Adapter.OnAction1 = (i) =>
                {
                    // Build an alertdialog
                    var alertBuilder = new Android.Support.V7.App.AlertDialog.Builder(Activity);
                    alertBuilder.SetTitle(Resources.GetString(Resource.String.leave_event));
                    alertBuilder.SetMessage(Resources.GetString(Resource.String.message_leave_event_confirm));

                    alertBuilder.SetNegativeButton(Resources.GetString(Resource.String.no), (s, e) => { });
                    alertBuilder.SetPositiveButton(Resources.GetString(Resource.String.yes), (s, e) =>
                    {
                        var @event = Adapter.Items[i];

                        //Leave and remove event.
                        MainActivity.CIF.CancelReg(@event);
                        Adapter.RemoveAt(i);

                        // Show update snackbar
                        AccentSnackBar.Make(Layout, Activity, Resources.GetString(Resource.String.event_left) + @event.Title, 2000).Show();
                    });

                    // Show alertdialog
                    alertBuilder.Show();
                };
                Adapter.OnUpdatePosition = (view, evnt, exp) =>
                {
                    view.FindViewById<TextView>(Resource.Id.title).Text = evnt.Title;
                    view.FindViewById<TextView>(Resource.Id.subtitle).Text = evnt.Date.ToString("G");

                    // Content of card contains description, location, slotstaken and slotstotal.
                    view.FindViewById<TextView>(Resource.Id.expanded_content).Text =
                        string.Format("{0}\n\n{1}: {2}\n{3}: {4}/{5}",
                                      evnt.Description, Resources.GetString(Resource.String.event_place),
                                      evnt.Location, Resources.GetString(Resource.String.event_participants),
                                      evnt.SlotsTaken, evnt.SlotsTotal);

                    view.FindViewById<Button>(Resource.Id.action1).Text = GetString(Resource.String.leave_button);

                    // Remove second button.
                    view.FindViewById<Button>(Resource.Id.action2).Visibility = ViewStates.Gone;
                };

                Activity.RunOnUiThread(() =>
                {
                    // Set listview adapter
                    List.Adapter = Adapter;

                    // Remove spinner, and add listview
                    Layout.RemoveAllViews();
                    Layout.AddView(List);
                });
            });

            return Layout;
        }
Пример #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Gets the layout, and all the relevant views it contains.
            Layout = inflater.Inflate(Resource.Layout.EventList, null)
                             .FindViewById<FrameLayout>(Resource.Id.layout);
            List = Layout.FindViewById<ListView>(Resource.Id.list);

            // Show spinner
            Layout.RemoveAllViews();
            Layout.AddView(new ProgressBar(Activity));

            ThreadPool.QueueUserWorkItem(o =>
            {
                // Get recommended events and create adapter.
                Adapter = new EventAdapter<Offer>(Activity, MainActivity.CIF.RequestOffers());

                // On decline click
                Adapter.OnAction1 = (i) =>
                {
                    // get event
                    var @event = Adapter.Items[i];

                    // reply and remove event
                    MainActivity.CIF.ReplyOffer(false, @event);
                    Adapter.RemoveAt(i);

                    // Show update snackbar
                    AccentSnackBar.Make(Layout, Activity, Resources.GetString(Resource.String.event_decline) + @event.Title, 2000).Show();
                };
                // On accept click
                Adapter.OnAction2 = (i) =>
                {
                    // get event
                    var @event = Adapter.Items[i];

                    // reply and remove event
                    MainActivity.CIF.ReplyOffer(true, @event);
                    Adapter.RemoveAt(i);

                    // Show update snackbar
                    AccentSnackBar.Make(Layout, Activity, Resources.GetString(Resource.String.event_accepted) + @event.Title, 2000).Show();
                };
                Adapter.OnUpdatePosition = (view, evnt, exp) =>
                {
                    var offer = evnt as Offer;
                    string matchs = GetString(Resource.String.event_matchedby) + ":\n";

                    view.FindViewById<TextView>(Resource.Id.title).Text = offer.Title;
                    view.FindViewById<TextView>(Resource.Id.subtitle).Text = offer.Date.ToString("G");

                    AddInfo(offer.Match.Interests, InfoType.Interest, ref matchs);
                    AddInfo(offer.Match.FoodHabits, InfoType.FoodHabit, ref matchs);
                    AddInfo(offer.Match.Languages, InfoType.Language, ref matchs);

                    // Content of card contains description, location, slotstaken, slotstotal and matches.
                    view.FindViewById<TextView>(Resource.Id.expanded_content).Text =
                        string.Format("{0}\n\n{1}: {2}\n{3}: {4}/{5}\n\n{6}",
                                      offer.Description, Resources.GetString(Resource.String.event_place),
                                      offer.Location, Resources.GetString(Resource.String.event_participants),
                                      offer.SlotsTaken, offer.SlotsTotal, matchs);

                    view.FindViewById<Button>(Resource.Id.action1).Text = GetString(Resource.String.decline_button);
                    view.FindViewById<Button>(Resource.Id.action2).Text = GetString(Resource.String.accept_button);
                };

                Activity.RunOnUiThread(() =>
                {
                    // Set listview adapter
                    List.Adapter = Adapter;

                    // Remove spinner, and add listview
                    Layout.RemoveAllViews();
                    Layout.AddView(List);
                });
            });

            return Layout;
        }
Пример #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Gets the layout, and all the relevant views it contains.
            Layout = inflater.Inflate(Resource.Layout.HostList, null)
                             .FindViewById<CoordinatorLayout>(Resource.Id.layout);
            List = Layout.FindViewById<ListView>(Resource.Id.list);
            Fab = Layout.FindViewById<FloatingActionButton>(Resource.Id.fab);
            Layout.RemoveAllViews();

            // Show spinner
            var pd = new ProgressBar(Activity);
            pd.LayoutParameters = new CoordinatorLayout.LayoutParams(-1, -1);
            Layout.AddView(pd);

            ThreadPool.QueueUserWorkItem(o =>
            {
                // Get hosting events and create adapter.
                Adapter = new EventAdapter<Event>(Activity, MainActivity.CIF.GetHostedEvents(100));

                Adapter.OnUpdatePosition = (view, evnt, exp) =>
                {
                    view.FindViewById<TextView>(Resource.Id.title).Text = evnt.Title;
                    view.FindViewById<TextView>(Resource.Id.subtitle).Text = evnt.Date.ToString("G");

                    // Content of card contains description, location, slotstaken and slotstotal.
                    view.FindViewById<TextView>(Resource.Id.expanded_content).Text =
                        string.Format("{0}\n\n{1}: {2}\n{3}: {4}/{5}",
                                      evnt.Description, Resources.GetString(Resource.String.event_place),
                                      evnt.Location, Resources.GetString(Resource.String.event_participants),
                                      evnt.SlotsTaken, evnt.SlotsTotal);

                    view.FindViewById<Button>(Resource.Id.action1).Text = GetString(Resource.String.cancel_button);
                    view.FindViewById<Button>(Resource.Id.action2).Text = GetString(Resource.String.edit_button); ;
                };

                // On cancel click
                Adapter.OnAction1 = (i) =>
                {
                    // Build an alertdialog
                    var alertBuilder = new Android.Support.V7.App.AlertDialog.Builder(Activity);
                    alertBuilder.SetTitle(Resources.GetString(Resource.String.cancel_event));
                    alertBuilder.SetMessage(Resources.GetString(Resource.String.message_cancel_event_confirm));

                    alertBuilder.SetNegativeButton(Resources.GetString(Resource.String.no_abort), (s, e) => { });
                    alertBuilder.SetPositiveButton(Resources.GetString(Resource.String.yes_cancel), (s, e) =>
                    {
                        var @event = Adapter.Items[i];

                        //Delete and remove event.
                        MainActivity.CIF.DeleteEvent(@event);
                        Adapter.RemoveAt(i);

                        // Show update snackbar
                        AccentSnackBar.Make(Layout, Activity, Resources.GetString(Resource.String.event_canceled) + @event.Title, 2000).Show();
                    });

                    // Show alertdialog
                    alertBuilder.Show();
                };
                Adapter.OnAction2 = EditEvent;
                Fab.Click += (s, e) => NewEvent();

                Activity.RunOnUiThread(() =>
                {
                    // Set listview adapter
                    List.Adapter = Adapter;

                    // Remove spinner, and add listview and Fab
                    Layout.RemoveAllViews();
                    Layout.AddView(List);
                    Layout.AddView(Fab);
                });
            });

            return Layout;
        }