public async Task <HttpResult> GetStop(StoppingPlace stop, DateTime date) { await GetToken(); try { /* * Set up basic autentisering */ using (var client = new HttpClient()) { client.BaseAddress = new Uri(" https://api.vasttrafik.se/bin/rest.exe/v2/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", this._accessToken); var appendstring = "?format=json&id=" + stop.Id + "&date=" + date.ToString("yyyy-MM-dd") + "&time=" + date.ToString("HH:mm"); var result = await client.GetAsync("departureBoard" + appendstring); result.EnsureSuccessStatusCode(); string resultContent = await result.Content.ReadAsStringAsync(); if (resultContent == null || resultContent.Length < 3) { throw new ArgumentException("Bad data"); } try { var res = JObject.Parse(resultContent); JArray ArrivalArr = (JArray)res["DepartureBoard"]["Departure"]; var arrivalManager = new StoppingTimeManager(); foreach (var obj in (JToken)ArrivalArr) { var datee = DateTime.Parse((string)obj.SelectToken("date") + " " + (string)obj.SelectToken("time")); arrivalManager.Add(new TravelTime() { Date = DateTime.Parse((string)obj.SelectToken("date") + " " + (string)obj.SelectToken("time")), direction = (string)obj.SelectToken("direction"), name = (string)obj.SelectToken("name") }); } return(new HttpResult(true, arrivalManager)); //return new HttpResult(true, null); } catch (Exception e) { throw new ArgumentException("Bad data", e.Message); } } } catch (Exception e) { throw new ArgumentException("Bad connection", e.Message); } }
public bool OnSuggestionClick(int position) { var place = _stopServerList[position]; _ignoreAutoCompleteTextChange = true; _searchView.SetQuery(place.Name, true); _stoppingPlaceViewModel.SaveLastChoicedStop(place); _choicedStop = place; return(true); }
public void SetChoicedStop(StoppingPlace place) { if (place == null) { _searchView.SetQuery("", false); ClearChoicedStop(); return; } _stoppingPlaceViewModel.SaveLastChoicedStop(place); _choicedStop = place; _ignoreAutoCompleteTextChange = true; _searchView.SetQuery(_choicedStop.Name, true); }
public async Task <StoppingTimeManager> GetArivalsList(StoppingPlace from, StoppingPlace to, DateTime date) { var http = new Http.API(); HttpResult stoppingTimeManager; if (to == null) { stoppingTimeManager = (HttpResult)await http.GetStop(from, date); var sortedList = ((StoppingTimeManager)stoppingTimeManager.Data); return(sortedList); } return(null); }
public async Task <SortedDictionary <string, StoppingTimeManager> > GetArivalsList(StoppingPlace stop, DateTime date) { var http = new Http.API(); var stoppingTimeManager = (HttpResult)await http.GetStop(stop, date); var sortedList = ((StoppingTimeManager)stoppingTimeManager.Data).Sort(); return(sortedList); }
//https://philio.me/styling-the-searchview-with-appcompat-v21/ //https://code.google.com/p/android/issues/detail?id=70754 public void Init(string searchIdName, string textFieldHint, bool topLine, bool serachLine, bool bottomline = false) { _stoppingPlaceViewModel = Stops.Setup.IoC.Container.Get <Core.ViewModels.SearchViewModel> (); /* * Load last selected on startup */ _searchView = _view.FindViewById <Android.Support.V7.Widget.SearchView> (Resource.Id.SearchFragmentSearch); _searchView.QueryHint = textFieldHint; _searchView.SetOnQueryTextListener(this); _searchView.SetOnSuggestionListener(this); ((EditText)_searchView.FindViewById(Resource.Id.search_src_text)).CustomSelectionActionModeCallback = this; if (mSuggestionsAdapter == null) { MatrixCursor cursor = new MatrixCursor(COLUMNS); mSuggestionsAdapter = new SuggestionsAdapter(Android.App.Application.Context, cursor); } _searchView.SuggestionsAdapter = mSuggestionsAdapter; if (!topLine) { var topLineView = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentTopLine); topLineView.Visibility = topLine ? ViewStates.Visible : ViewStates.Gone; } if (!serachLine) { var view = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentDragLine); view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone; } if (!bottomline) { var view = _view.FindViewById <FrameLayout>(Resource.Id.SearchFragmentBottomLine); view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone; } int searchEditTextId = Resource.Id.search_src_text; // for AppCompat // get AutoCompleteTextView from SearchView AutoCompleteTextView searchEditText = (AutoCompleteTextView)_searchView.FindViewById(searchEditTextId); View dropDownAnchor = _searchView.FindViewById(searchEditText.DropDownAnchor); dropDownAnchor.AddOnLayoutChangeListener(this); searchEditText.LongClick += (object sender, View.LongClickEventArgs e) => { SetChoicedStop(null); }; /* * Init the view model and set the last chocied stop */ _stoppingPlaceViewModel.Init(searchIdName); if (_stoppingPlaceViewModel.HasLatestCLickeStop()) { _choicedStop = _stoppingPlaceViewModel.GetLatestCLickeStop(); _ignoreAutoCompleteTextChange = true; _searchView.SetQuery(_choicedStop.Name, true); Events.Trigger("initWithStop", _choicedStop, 100); } var btnPos = _view.FindViewById <ImageButton> (Resource.Id.btnPos); btnPos.Click += (object sender, EventArgs e) => { Events.Trigger("locationClick", null); return; }; }
private void ClearChoicedStop() { _choicedStop = null; _stoppingPlaceViewModel.clearLastChociedStop(); }
public void FireStoppingPlaceSelcted(StoppingPlace stoppingplaceselxted) { Instance.Trigger("stoppingplaceselected", stoppingplaceselxted, 0); }