Beispiel #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            _view = inflater.Inflate(Resource.Layout.StoppingPlacesCard, container, false);
            _stoppingPlacesViewModel = Stops.Setup.IoC.Container.Get <Core.ViewModels.StoppingPlacesViewModel> ();
            _favoritesViewModel      = Stops.Setup.IoC.Container.Get <Core.ViewModels.FavoritesViewModel>();
            _favoritesViewModel.Load();

            _root = (ViewGroup)_view.FindViewById(stops.Resource.Id.stoppingPlacesCardRoot);


            FavoriteBridge.Instance.OnEvent += (source, e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "FavoriteSelected")
                {
                    var data = (Favorite)evt.Data;

                    if (data.fromName != null && data.toName != null)
                    {
                        _searchFromFragment.SetChoicedStop(new StoppingPlace()
                        {
                            Name = data.fromName,
                            Id   = data.fromId,
                            Lat  = data.fromLat,
                            Lon  = data.fromLon
                        });

                        _searchToFragment.SetChoicedStop(new StoppingPlace()
                        {
                            Name = data.toName,
                            Id   = data.toId,
                            Lat  = data.toLat,
                            Lon  = data.toLon
                        });
                    }
                }
            };

            /*
             *  Handle Date for search
             */
            _dateFragment = (DateFragment)ChildFragmentManager.FindFragmentById(stops.Resource.Id.stoppingPlacesCardDate);
            _dateFragment.Events.OnEvent += (object source, EventArgs e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "favoritebuttonclicked")
                {
                    HandleAddFavorite();
                }
            };
            _dateFragment.Init(true);


            /*
             *  Handle stop search from
             */
            _searchFromFragment = (SearchFragment)ChildFragmentManager.FindFragmentById(stops.Resource.Id.stoppingPlacesCardSearchFromStops);
            _searchFromFragment.Events.OnEvent += (object source, EventArgs e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "itemclicked")
                {
                    //PerformSearch();
                }
                else if (evt.Name == "locationClick")
                {
                    ShowMapFragment();
                }
                if (evt.Name == "OnQueryTextSubmit")
                {
                    HandleSearchClicked();
                }
            };
            _searchFromFragment.Init("StoppingPlacesFromLastStop", "Från", false, true);

            /*
             *  Handle stop search to
             */
            _searchToFragment = (SearchFragment)ChildFragmentManager.FindFragmentById(stops.Resource.Id.stoppingPlacesCardSearchToStops);
            _searchToFragment.Events.OnEvent += (object source, EventArgs e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "itemclicked")
                {
                    //PerformSearch();
                }
                else if (evt.Name == "locationClick")
                {
                    //ShowMapFragment();
                }
                if (evt.Name == "OnQueryTextSubmit")
                {
                    HandleSearchClicked();
                }
            };
            _searchToFragment.Init("StoppingPlacesToLastStop", "Till", true, true);

            /*
             * Handle arrival spinner
             */
//			var spinner = (Spinner)_view.FindViewById (stops.Resource.Id.stoppingPlacesCardDepartureSpinner);
//			spinner.ItemSelected += (sender, e) => {
//
//			};
//			var adapter = ArrayAdapter.CreateFromResource (
//				Android.App.Application.Context, Resource.Array.when_array,Resource.Layout.SpinnerText);
//
//			adapter.SetDropDownViewResource (Resource.Layout.Spinner);
//			spinner.Adapter = adapter;
//

            SetUpDragAndDrop();

            //PerformSearch ();


            MapBridge.Instance.OnEvent += (source, e) =>
            {
                var evt = ((EventClassArgs)e);
                if (evt.Name == "stoppingplaceselected")
                {
                    var data = (StoppingPlace)evt.Data;

                    if (listenToStoppingPlaceSelectedEvent)
                    {
                        if (stoppingPlaceInt == 0)
                        {
                            _searchFromFragment.SetChoicedStop(data);
                        }
                        else
                        {
                            _searchToFragment.SetChoicedStop(data);
                        }

                        stoppingPlaceInt++;
                        if (stoppingPlaceInt > 1)
                        {
                            stoppingPlaceInt = 0;
                        }
                    }
                }
                if (evt.Name == "ViewPagerPosition")
                {
                    var data = (int)evt.Data;
                    if (data == 1)
                    {
                        listenToStoppingPlaceSelectedEvent = true;
                    }
                    else
                    {
                        listenToStoppingPlaceSelectedEvent = false;
                    }
                }
                if (evt.Name == "SearchButtonClicked")
                {
                    HandleSearchClicked();
                }
            };

            return(_view);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            /*
             * Load view model
             */
            _view = inflater.Inflate(Resource.Layout.StoppingPlaceCard, container, false);
            _stoppingPlaceViewModel = Stops.Setup.IoC.Container.Get <Core.ViewModels.StoppingPlaceViewModel> ();
            _favoritesViewModel     = Stops.Setup.IoC.Container.Get <Core.ViewModels.FavoritesViewModel>();
            _favoritesViewModel.Load();

            /*
             * Setup listview
             */
            _root = (ViewGroup)_view.FindViewById(stops.Resource.Id.layout_container);
//
//			((FrameLayout)headerview.Parent).RemoveView(headerview);
//
            var recyclerView = _view.FindViewById <RecyclerView>(Resource.Id.recyclerview);

            recyclerView.SetLayoutManager(new LinearLayoutManager(Activity, LinearLayoutManager.Vertical, false));
            recyclerView.HasFixedSize = true;


            // items
            var elements = new List <string>(0);

            for (int i = 0; i < 0; i++)
            {
                elements.Add("row " + i);
            }
            recyclerView.SetAdapter(new SimpleRecyclerAdapter(Activity, elements));



            FavoriteBridge.Instance.OnEvent += (source, e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "FavoriteSelected")
                {
                    var data = (Favorite)evt.Data;

                    if (data.fromName != null && data.toName == null)
                    {
                        _searchFragment.SetChoicedStop(new StoppingPlace()
                        {
                            Name = data.fromName,
                            Id   = data.fromId,
                            Lat  = data.fromLat,
                            Lon  = data.fromLon
                        });
                    }
                }
            };

            /*
             *  Handle stop search
             */
            _searchFragment = (SearchFragment)ChildFragmentManager.FindFragmentById(stops.Resource.Id.stoppingPlaceCardSearchStop);
            _searchFragment.Events.OnEvent += (object source, EventArgs e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "itemclicked" || evt.Name == "initWithStop")
                {
                    //PerformSearch();
                }
                else if (evt.Name == "locationClick")
                {
                    //ShowMapFragment();
                }
                if (evt.Name == "OnQueryTextSubmit")
                {
                    HandleSearchClicked();
                }
            };


            /*
             *  Handle Date for search
             */
            _dateFragment = (DateFragment)ChildFragmentManager.FindFragmentById(stops.Resource.Id.stoppingPlaceCardDateStop);
            _dateFragment.Events.OnEvent += (object source, EventArgs e) => {
                var evt = (EventClassArgs)e;
                if (evt.Name == "Dateupdated")
                {
                    //PerformSearch();
                }
            };
            _dateFragment.Init();
            _searchFragment.Init("StoppingPlaceLastStop", "Hållplats", false, false, true);


            MapBridge.Instance.OnEvent += (source, e) =>
            {
                var evt = ((EventClassArgs)e);
                if (evt.Name == "stoppingplaceselected")
                {
                    var data = (StoppingPlace)evt.Data;

                    if (listenToStoppingPlaceSelectedEvent)
                    {
                        _searchFragment.SetChoicedStop(data);
                    }
                }
                if (evt.Name == "ViewPagerPosition")
                {
                    var data = (int)evt.Data;
                    if (data == 0)
                    {
                        listenToStoppingPlaceSelectedEvent = true;
                    }
                    else
                    {
                        listenToStoppingPlaceSelectedEvent = false;
                    }
                }
                if (evt.Name == "SearchButtonClicked")
                {
                    HandleSearchClicked();
                }
            };

            return(_view);
        }