// Favorites Methods

        public void AddFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Initialize();

            // If the recent already exists delete the old instance.
            // This way the new one will be added with the new LastAccessed time.
            if (type == FavoriteType.Recent && IsFavorite(favorite, type))
            {
                // The comparison doesn't compare the LastAccessed times so
                // it will remove the other copy
                favorites[type].Remove(favorite);
            }

            // Remove the oldest favorite if 15 entires already exist
            if (type == FavoriteType.Recent && favorites[type].Count >= 15)
            {
                favorites[type].Sort(new RecentLastAccessComparer());
                favorites[type].RemoveAt(favorites[type].Count - 1);
            }

            favorites[type].Add(favorite);
            WriteFavoritesToDisk(favorites[type], fileNames[type]);

            if (Favorites_Changed != null)
            {
                Favorites_Changed(this, new FavoritesChangedEventArgs(favorites[type]));
            }
        }
        // Only want to use the state variable on the initial call
        void UpdateAppBar(bool useStateVariable)
        {
            bool addFilterButton = false;

            if (useStateVariable == true &&
                PhoneApplicationService.Current.State.ContainsKey(isFilteredStateId) == true &&
                viewModel.CurrentViewState.CurrentRouteDirection != null)
            {
                // This page was tombstoned and is now reloading, use the previous filter status.
                isFiltered      = (bool)PhoneApplicationService.Current.State[isFilteredStateId];
                addFilterButton = true;
            }
            else
            {
                // No filter override, this is the first load of this details page. If
                // there is a specific route direction filter based on it and add the
                // filter button, otherwise we are just displaying a stop, don't show
                // the filter button.
                isFiltered      = viewModel.CurrentViewState.CurrentRouteDirection != null;
                addFilterButton = isFiltered;
            }

            if (addFilterButton == true)
            {
                if (appbar_allroutes == null)
                {
                    appbar_allroutes        = new ApplicationBarIconButton();
                    appbar_allroutes.Click += new EventHandler(appbar_allroutes_Click);
                }

                if (isFiltered == true)
                {
                    appbar_allroutes.IconUri = unfilterRoutesIcon;
                    appbar_allroutes.Text    = unfilterRoutesText;
                }
                else
                {
                    appbar_allroutes.IconUri = filterRoutesIcon;
                    appbar_allroutes.Text    = filterRoutesText;
                }

                if (!ApplicationBar.Buttons.Contains(appbar_allroutes))
                {
                    // this has to be done after setting the icon
                    ApplicationBar.Buttons.Add(appbar_allroutes);
                }
            }

            FavoriteRouteAndStop currentInfo = new FavoriteRouteAndStop();

            currentInfo.route      = viewModel.CurrentViewState.CurrentRoute;
            currentInfo.routeStops = viewModel.CurrentViewState.CurrentRouteDirection;
            currentInfo.stop       = viewModel.CurrentViewState.CurrentStop;

            isFavorite = viewModel.IsFavorite(currentInfo);
            SetFavoriteIcon();
        }
        private void FavoritesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                FavoriteRouteAndStop favorite = (FavoriteRouteAndStop)e.AddedItems[0];
                viewModel.CurrentViewState.CurrentRoute          = favorite.route;
                viewModel.CurrentViewState.CurrentStop           = favorite.stop;
                viewModel.CurrentViewState.CurrentRouteDirection = favorite.routeStops;

                Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));
            }
        }
        public void DeleteFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Initialize();

            favorites[type].Remove(favorite);
            WriteFavoritesToDisk(favorites[type], fileNames[type]);

            if (Favorites_Changed != null)
            {
                Favorites_Changed(this, new FavoritesChangedEventArgs(favorites[type]));
            }
        }
 public object Convert(
     object value,
     Type targetType,
     object parameter,
     System.Globalization.CultureInfo culture)
 {
     if (value is FavoriteRouteAndStop)
     {
         FavoriteRouteAndStop fav = value as FavoriteRouteAndStop;
         return(fav.route == null ? Visibility.Visible : Visibility.Collapsed);
     }
     else
     {
         return(null);
     }
 }
        private void appbar_favorite_Click(object sender, EventArgs e)
        {
            FavoriteRouteAndStop favorite = new FavoriteRouteAndStop();

            favorite.route      = viewModel.CurrentViewState.CurrentRoute;
            favorite.stop       = viewModel.CurrentViewState.CurrentStop;
            favorite.routeStops = viewModel.CurrentViewState.CurrentRouteDirection;

            if (isFavorite == false)
            {
                viewModel.AddFavorite(favorite);
                isFavorite = true;
            }
            else
            {
                viewModel.DeleteFavorite(favorite);
                isFavorite = false;
            }

            SetFavoriteIcon();
        }
Exemple #7
0
        public void DeleteFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Exception error = null;

            try
            {
                Initialize();

                favorites[type].Remove(favorite);
                WriteFavoritesToDisk(favorites[type], fileNames[type]);
            }
            catch (Exception e)
            {
                Debug.Assert(false);
                error = e;
            }

            if (Favorites_Changed != null)
            {
                Favorites_Changed(this, new FavoritesChangedEventArgs(favorites[type], error));
            }
        }
        public bool IsFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Initialize();

            return favorites[type].Contains(favorite);
        }
Exemple #9
0
 public void DeleteFavorite(FavoriteRouteAndStop favorite)
 {
     appDataModel.DeleteFavorite(favorite, FavoriteType.Favorite);
 }
Exemple #10
0
 public void AddRecent(FavoriteRouteAndStop recent)
 {
     appDataModel.AddFavorite(recent, FavoriteType.Recent);
 }
Exemple #11
0
 public void AddFavorite(FavoriteRouteAndStop favorite)
 {
     appDataModel.AddFavorite(favorite, FavoriteType.Favorite);
 }
Exemple #12
0
 public bool IsFavorite(FavoriteRouteAndStop favorite)
 {
     return(appDataModel.IsFavorite(favorite, FavoriteType.Favorite));
 }
 public void AddFavorite(FavoriteRouteAndStop favorite)
 {
     appDataModel.AddFavorite(favorite, FavoriteType.Favorite);
 }
        // Favorites Methods

        public void AddFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Exception error = null;

            try
            {
                Initialize();

                // If the recent already exists delete the old instance.
                // This way the new one will be added with the new LastAccessed time.
                if (type == FavoriteType.Recent && IsFavorite(favorite, type))
                {
                    // The comparison doesn't compare the LastAccessed times so
                    // it will remove the other copy
                    favorites[type].Remove(favorite);
                }

                // Remove the oldest favorite if 15 entires already exist
                if (type == FavoriteType.Recent && favorites[type].Count >= 15)
                {
                    favorites[type].Sort(new RecentLastAccessComparer());
                    favorites[type].RemoveAt(favorites[type].Count - 1);
                }

                favorites[type].Add(favorite);
                WriteFavoritesToDisk(favorites[type], fileNames[type]);
            }
            catch (Exception e)
            {
                Debug.Assert(false);
                error = e;
            }

            if (Favorites_Changed != null)
            {
                Favorites_Changed(this, new FavoritesChangedEventArgs(favorites[type], error));
            }
        }
        public void DeleteFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Exception error = null;

            try
            {
                Initialize();

                favorites[type].Remove(favorite);
                WriteFavoritesToDisk(favorites[type], fileNames[type]);
            }
            catch (Exception e)
            {
                Debug.Assert(false);
                error = e;
            }

            if (Favorites_Changed != null)
            {
                Favorites_Changed(this, new FavoritesChangedEventArgs(favorites[type], error));
            }
        }
        // Only want to use the state variable on the initial call
        void UpdateAppBar(bool useStateVariable)
        {
            bool addFilterButton = false;
            if (useStateVariable == true &&
                PhoneApplicationService.Current.State.ContainsKey(isFilteredStateId) == true 
                && viewModel.CurrentViewState.CurrentRouteDirection != null)
            {
                // This page was tombstoned and is now reloading, use the previous filter status.
                isFiltered = (bool)PhoneApplicationService.Current.State[isFilteredStateId];
                addFilterButton = true;
            }
            else
            {
                // No filter override, this is the first load of this details page. If
                // there is a specific route direction filter based on it and add the 
                // filter button, otherwise we are just displaying a stop, don't show
                // the filter button.
                isFiltered = viewModel.CurrentViewState.CurrentRouteDirection != null;
                addFilterButton = isFiltered;
            }

            if (addFilterButton == true)
            {
                if (appbar_allroutes == null)
                {
                    appbar_allroutes = new ApplicationBarIconButton();
                    appbar_allroutes.Click += new EventHandler(appbar_allroutes_Click);
                }

                if (isFiltered == true)
                {
                    appbar_allroutes.IconUri = unfilterRoutesIcon;
                    appbar_allroutes.Text = unfilterRoutesText;
                }
                else
                {
                    appbar_allroutes.IconUri = filterRoutesIcon;
                    appbar_allroutes.Text = filterRoutesText;
                }

                if (!ApplicationBar.Buttons.Contains(appbar_allroutes))
                {
                    // this has to be done after setting the icon
                    ApplicationBar.Buttons.Add(appbar_allroutes);
                }
            }

            FavoriteRouteAndStop currentInfo = new FavoriteRouteAndStop();
            currentInfo.route = viewModel.CurrentViewState.CurrentRoute;
            currentInfo.routeStops = viewModel.CurrentViewState.CurrentRouteDirection;
            currentInfo.stop = viewModel.CurrentViewState.CurrentStop;

            isFavorite = viewModel.IsFavorite(currentInfo);
            SetFavoriteIcon();
        }
 public bool IsFavorite(FavoriteRouteAndStop favorite)
 {
     return appDataModel.IsFavorite(favorite, FavoriteType.Favorite);
 }
 public void AddRecent(FavoriteRouteAndStop recent)
 {
     appDataModel.AddFavorite(recent, FavoriteType.Recent);
 }
 public void DeleteFavorite(FavoriteRouteAndStop favorite)
 {
     appDataModel.DeleteFavorite(favorite, FavoriteType.Favorite);
 }
        private void appbar_favorite_Click(object sender, EventArgs e)
        {
            FavoriteRouteAndStop favorite = new FavoriteRouteAndStop();
            favorite.route = viewModel.CurrentViewState.CurrentRoute;
            favorite.stop = viewModel.CurrentViewState.CurrentStop;
            favorite.routeStops = viewModel.CurrentViewState.CurrentRouteDirection;

            if (isFavorite == false)
            {
                viewModel.AddFavorite(favorite);
                isFavorite = true;
            }
            else
            {
                viewModel.DeleteFavorite(favorite);
                isFavorite = false;
            }

            SetFavoriteIcon();
        }
        public bool IsFavorite(FavoriteRouteAndStop favorite, FavoriteType type)
        {
            Initialize();

            return(favorites[type].Contains(favorite));
        }