예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.search_by_num);

            TextView    txtLine       = FindViewById <TextView>(Resource.Id.txt_line_num);
            Button      btnSearch     = FindViewById <Button>(Resource.Id.btn_search_num);
            TableLayout mTableLayout  = FindViewById <TableLayout>(Resource.Id.table_by_num);
            ImageButton btnFavorite   = FindViewById <ImageButton>(Resource.Id.save_favorite);
            TextView    labelFavorite = FindViewById <TextView>(Resource.Id.labelFavorite);

            string[] OperatorList = dbHelper.GetAllAgencies();

            AutoCompleteTextView operatorAutoComplete = FindViewById <AutoCompleteTextView>(Resource.Id.autoComplete_operator);
            var adapter = new ArrayAdapter <String>(this, Resource.Layout.list_item, OperatorList);

            operatorAutoComplete.Adapter = adapter;

            operatorAutoComplete.ItemClick += new EventHandler <AdapterView.ItemClickEventArgs>(OperatorSelected);
            txtLine.FocusChange            += new EventHandler <Android.Views.View.FocusChangeEventArgs>(LineChange);
            txtLine.TextChanged            += new EventHandler <Android.Text.TextChangedEventArgs>(TextLineChange);
            Spinner spinner = FindViewById <Spinner>(Resource.Id.spinner);

            btnSearch.Click += delegate
            {
                List <RouteData> directions = GetDirections(txtLine.Text, operatorAutoComplete.Text);

                if (directions.Count == 0)
                {
                    Alert.AlertMessage(this, "אין קווים העונים לחיפוש זה");
                    return;
                }

                int routeIdOfDirectionChoosen = directions.First(d => d.destination.Equals(spinner.SelectedItem.ToString())).route_id;
                labelFavorite.Visibility = Android.Views.ViewStates.Invisible;
                labelFavorite.Text       = "";
                GetData(mTableLayout, routeIdOfDirectionChoosen);
            };

            btnFavorite.Click += delegate
            {
                List <RouteData> directions      = GetDirections(txtLine.Text, operatorAutoComplete.Text);
                int    routeIdOfDirectionChoosen = directions.First(d => d.destination.Equals(spinner.SelectedItem.ToString())).route_id;
                string favoriteName = operatorAutoComplete.Text + " קו " + txtLine.Text;
                dbHelper.AddNewFavorite(this, favoriteName, apiService.GetSrcUrl(this, routeIdOfDirectionChoosen),
                                        (int)SEARCH_TYPE.line, spinner.SelectedItem.ToString());
            };

            string favoriteUrl = "";

            favoriteUrl = Intent.GetStringExtra("url");

            if (favoriteUrl != null && favoriteUrl != "")
            {
                labelFavorite.Visibility = Android.Views.ViewStates.Visible;
                string searchName = Intent.GetStringExtra("searchName") + " " + Intent.GetStringExtra("direction");
                labelFavorite.Text = searchName;
                GetData(mTableLayout, 0, favoriteUrl);
            }
        }
예제 #2
0
        private int FindTrainStationNumberByName(string stationName)
        {
            int stationNumber = dbHelper.GetTrainStationNumberByName(stationName);

            if (stationNumber == 0)
            {
                Alert.AlertMessage(this, "תחנת הרכבת לא מופיעה במערכת");
            }

            return(stationNumber);
        }
예제 #3
0
        public void DeleteFavorite(Activity activity, string name)
        {
            try
            {
                SQLiteConnection connection = dbConnection.CreateConnection();
                connection.Query <FavoriteData>($"Delete from favorites where name = '{name}'");
            }

            catch (Exception)
            {
                Alert.AlertMessage(activity, "המועדף לא נוסף במערכת");
                return;
            }
        }
예제 #4
0
        public async void GetData(int stationNumber, TableLayout mTableLayout, string favoriteUrl = "")
        {
            string      urlToSend   = favoriteUrl != "" ? favoriteUrl : apiService.GetSrcUrl(stationNumber);
            ApiResponse apiResponse = await apiService.GetDataFromApi(urlToSend);

            if (apiResponse?.Siri?.ServiceDelivery?.StopMonitoringDelivery?[0]?.MonitoredStopVisit?.Count == 0)
            {
                Alert.AlertMessage(this, "אין רכבות בתחנה ב30 הדקות הקרובות");
            }

            else if (apiResponse.Siri != null)
            {
                List <MonitoredStopVisit> visits        = apiResponse.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit.ToList();
                DataGenerator             dataGenerator = new DataGenerator();
                dataGenerator.SetTableData(visits, mTableLayout, this, Resources, "station");
            }
        }
예제 #5
0
        public void AddNewFavorite(Activity activity, string name, string url, int searchType, string direction)
        {
            const string ADDED = " נוסף למועדפים";

            try
            {
                SQLiteConnection connection = dbConnection.CreateConnection();
                connection.Query <FavoriteData>($"INSERT INTO favorites (name, url, searchType, direction) VALUES('{name}', '{url}', '{searchType}', '{direction}')");
                Alert.AlertMessage(activity, name + ADDED);
            }

            catch (Exception)
            {
                Alert.AlertMessage(activity, "המועדף לא נוסף במערכת");
                return;
            }
        }
예제 #6
0
        public async void GetData(TableLayout mTableLayout, int routeIdOfDirectionChoosen, string favoriteUrl = "")
        {
            string      urlToSend   = favoriteUrl != "" ? favoriteUrl : apiService.GetSrcUrl(this, routeIdOfDirectionChoosen);
            ApiResponse apiResponse = await apiService.GetDataFromApi(urlToSend);

            if (apiResponse.Siri != null)
            {
                List <MonitoredStopVisit> visits = apiResponse.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit.ToList();

                if (visits.Count == 0)
                {
                    Alert.AlertMessage(this, "לא נמצאו נסיעות קרובות לקו זה");
                    return;
                }
                DataGenerator dataGenerator = new DataGenerator();
                dataGenerator.SetTableData(visits, mTableLayout, this, Resources, "line");
            }
        }
예제 #7
0
        public void SetFunctions(List <FavoriteElementId> favoritsElementsId)
        {
            foreach (FavoriteElementId Row in favoritsElementsId)
            {
                Row.Btn.Click += delegate
                {
                    dBHelper.DeleteFavorite(this, Row.Name);
                    Alert.AlertMessage(this, Row.Name + " נמחק");
                    GetDataToScreen();
                };

                Row.Txt.Click += delegate
                {
                    Intent activity;
                    switch (Row.SearchType)
                    {
                    case (int)SEARCH_TYPE.line:
                        activity = new Intent(this, typeof(SearchByNum));
                        activity.PutExtra("direction", (Row as FavoriteLineElementId).Direction);
                        break;

                    case (int)SEARCH_TYPE.train:
                        activity = new Intent(this, typeof(SearchTrain));
                        break;

                    case (int)SEARCH_TYPE.station:
                        activity = new Intent(this, typeof(SearchByStation));
                        break;

                    default:
                        return;
                    }

                    activity.PutExtra("url", dBHelper.GetUrlFavoriteByName(Row.Name));
                    activity.PutExtra("searchName", Row.Name);
                    StartActivity(activity);
                };
            }
        }
예제 #8
0
        public async void GetData(string stationNum, TableLayout mTableLayout, string favoriteUrl = "")
        {
            string      urlToSend   = favoriteUrl != "" ? favoriteUrl : apiService.GetSrcUrl(stationNum);
            ApiResponse apiResponse = await apiService.GetDataFromApi(urlToSend);

            try
            {
                List <MonitoredStopVisit> visits = apiResponse.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit.ToList();

                if (visits.Count == 0)
                {
                    Alert.AlertMessage(this, "לא נמצאו נסיעות קרובות לתחנה זו");
                    return;
                }
                DataGenerator dataGenerator = new DataGenerator();
                dataGenerator.SetTableData(visits, mTableLayout, this, Resources, "station");
            }
            catch
            {
                Alert.AlertMessage(this, "מספר התחנה לא מופיע במערכת");
            }
        }