public StopDetailViewModel(Stop stop)
 {
     Routes = new ObservableCollection<Route>();
     Alerts = new ObservableCollection<Alert>();
     SelectedStop = stop;
     refreshTimer = new DispatcherTimer();
     refreshTimer.Tick += TimerDue;
     refreshTimer.Interval = new TimeSpan(0, 0, 15);
     tileId = stop.StopName;
 }
Example #2
0
        public static async Task<XDocument> GetSearchPredictionsAsync(Stop stop, Route route)
        {
            var url = baseUrls["searchPrediction"] + stop.stopId + "&routeTag=" + route.RouteNumber;

             //Make sure to pull from the network and not cache everytime predictions are refreshed 
            client.DefaultRequestHeaders.IfModifiedSince = DateTime.Now;
            try
            {
                var response = await client.GetAsync(new Uri(url));
                response.EnsureSuccessStatusCode();
                var reader = await response.Content.ReadAsStringAsync();
                xmlDoc = XDocument.Parse(reader);
            }
            catch (Exception)
            {
                await ErrorHandler.NetworkError("Error getting predictions. Check network connection and try again.");
                throw;
            }

            return xmlDoc;
        }
Example #3
0
        public static async Task FavoriteSearchAsync(Stop stop)
        {
            string title = stop.StopName;
            if (title.Contains("Inbound"))
            {
                title = title.Replace(" Inbound", "");
            }
            if (title.Contains("Outbound"))
            {
                title = title.Replace(" Outbound", "");
            }

            //var _stopsAsyncConnection = new SQLiteAsyncConnection("muni.sqlite");
            var connection = new SQLiteAsyncConnection(() => DbConnection(muniDbPath));

            //string query = "SELECT * FROM BusStops WHERE StopName = \'" + title + "\'";
            var results = await connection.Table<Stop>().Where(s => s.StopName == title).ToListAsync();
            
            //If stop name not found in db, most likely a stop that was a duplicate and merged so reverse it and search again
            if(!results.Any())
            {
                string [] temp = title.Split('&');
                title = temp[1].Substring(1) + " & " + temp[0].Substring(0, (temp[0].Length - 1));

                //query = "SELECT * FROM BusStops WHERE StopName = \'" + title + "\'";
                results = await connection.Table<Stop>().Where(s => s.StopName == title).ToListAsync();
            }

            foreach (Stop fav in results)
            {
                await AddFavoriteAsync(stop);
            }
        }
Example #4
0
        public static async Task RemoveFavoriteAsync(Stop stop)
        {
            string q = "DELETE FROM FavoriteData WHERE Id IS " + stop.favId;
            //var _favoritesAsyncConnection = new SQLiteAsyncConnection(favoriteDbPath);
            favoritesConnection = new SQLiteAsyncConnection(() => DbConnection(favoriteDbPath));

            await favoritesConnection.QueryAsync<Favorite>(q);
            await LoadFavoritesAsync();
        }
Example #5
0
        public static async Task AddFavoriteAsync(Stop stop)
        {
            //var _favoritesAsyncConnection = new SQLiteAsyncConnection(favoriteDbPath);
            favoritesConnection = new SQLiteAsyncConnection(() => DbConnection(favoriteDbPath));

            await favoritesConnection.InsertAsync(new Favorite
                {
                    Name = stop.StopName,
                    Routes = stop.Routes,
                    Tags = stop.StopTags,
                    Lat = stop.Latitude,
                    Lon = stop.Longitude
                });

            await LoadFavoritesAsync();
        }
Example #6
0
        private void LoadFavorites()
        {
            List<Favorite> favorites = DatabaseHelper.FavoritesList;
            FavoriteStops.Clear();

            if (favorites.Count == 0)
            {
                NoFavoritesText = "Add favorites by pressing \uE00A on a stop";
            }
            else
            {
                NoFavoritesText = "";
                foreach (Favorite fav in favorites)
                {
                    Stop favStop = new Stop(fav.Name, "", fav.Routes, fav.Tags, fav.Lat, fav.Lon);
                    favStop.favId = fav.Id;
                    FavoriteStops.Add(favStop);
                }
            }
            
            //Check if any stops in NearbyStops are also favorites so users have the ability to remove them
            SyncFavoriteIds();
            //FavoritesDistances();
            if (sorted) SortFavorites();
        }
        public async Task StopSelectedAsync(Stop stop)
        {
            SelectedStop = stop;
            string title = SelectedStop.StopName;

            if (title.Contains("Inbound"))
            {
                SelectedStop.StopName = title.Replace(" Inbound", "");
            }
            if (title.Contains("Outbound"))
            {
                SelectedStop.StopName = title.Replace(" Outbound", "");
            }

            //string[] temp = SelectedStop.StopName.Split('&');
            //string reversed;
            //if (temp.Count() > 1)
            //{
            //    reversed = temp[1].Substring(1) + " & " + temp[0].Substring(0, (temp[0].Length - 1));
            //}
            //else reversed = "";

            try
            {
                var xmlDoc = await WebHelper.GetSearchPredictionsAsync(SelectedStop, SelectedRoute);
                //Get bus predictions for stop
                SearchTimes = await Task.Run(() => ParseHelper.ParseSearchTimesAsync(xmlDoc));

                Stop tempStop = await GetStopAsync();
                if (tempStop != null) SelectedStop = tempStop;

                IsFavorite = DatabaseHelper.FavoritesList.Any(f => f.Name == SelectedStop.StopName);

                if (IsFavorite) SyncFavoriteIds();
            }
            catch(Exception)
            {
                throw;
            }        
        }