private async void SearchSourceBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { _source = args.SelectedItem.ToString(); flag = 1; progress.IsActive = true; //string dlat, dlng, token; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); GeoResponse location; CabsAPI api = new CabsAPI(); location = await api.GeoCodingResult(token, args.SelectedItem.ToString()); if (location.Code == ResponseCode.SUCCESS) { slat = location.Position.Latitude; slng = location.Position.Longitude; BasicGeoposition curPos = new BasicGeoposition(); curPos.Latitude = double.Parse(slat); curPos.Longitude = double.Parse(slng); await MyMap.TrySetViewAsync(new Geopoint(curPos), 17D); AddMapIcon(double.Parse(slat), double.Parse(slng)); CabsResponse response = await api.GetNearbyCabs(slat, slng, Token); if (response.Code == ResponseCode.SUCCESS) { progress.IsActive = false; CabsListView.ItemsSource = response.Cabs; } else { await new MessageDialog("Error fetching nearby cabs").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition coordinates").ShowAsync(); return; } } }
public async Task RefreshView(int refreshType) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { List <Cab> refreshed = new List <Cab>(); if (refreshType == REFRESH_SURGE) { CabsResponse res = await _cabsApi.GetNearbyCabs(_startLat, _startLng, _token); if (res.Code == ResponseCode.SUCCESS) { refreshed = res.Cabs; } } else if (refreshType == REFRESH_ESTIMATE) { PriceEstimateResponse res = await _cabsApi.GetEstimate(_token, _startLat, _startLng, _endLat, _endLng); if (res.Code == ResponseCode.SUCCESS) { foreach (var estimate in res.Estimates) { Cab cab = new Cab(); cab.Provider = estimate.Provider; cab.Eta = estimate.Eta; cab.ImageURL = estimate.ImageURL; cab.Type = estimate.Type; cab.Time = estimate.CurrentEstimate.Time; cab.Distance = estimate.CurrentEstimate.Distance; cab.FareData = estimate.CurrentEstimate.FareData; cab.FareData.Surge = estimate.CurrentEstimate.LowRange + "-" + estimate.CurrentEstimate.HighRange; refreshed.Add(cab); } } } Cabs = refreshed; } }
public async void init(View rootView) { if (!isOnline()) { mErrorDialog.Show(); return; } api = new CabsAPI(); mLoadingDialog = new LoadingDialog(mActivity, Resource.Drawable.main); mLoadingDialog.SetCancelable(false); Window window = mLoadingDialog.Window; window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent); window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans))); SpannableString s = new SpannableString("Home"); typeface = Typeface.CreateFromAsset(mActivity.Assets, "JosefinSans-SemiBold.ttf"); s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive); s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive); mActivity.TitleFormatted = s; mSharedPreference = mActivity.GetSharedPreferences(Constants.MY_PREF, 0); token = mSharedPreference.GetString("token", " "); if (mActivity.Intent.GetStringExtra("source") != null) { msourceRecieved = mActivity.Intent.GetStringExtra("source"); } else { msourceRecieved = mSharedPreference.GetString("source", "1,ISB Rd,Gachibowli"); } autoSourceBox = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.sourceauto); autoSourceBox.Text = msourceRecieved; sourceSuggestionsAdapter = new SearchSuggestionsAdapter(mActivity); autoSourceBox.Adapter = sourceSuggestionsAdapter; destinationSuggestionsAdapter = new SearchSuggestionsAdapter(mActivity); autoSourceBox.ItemClick += mSourceTextBoxClicked; autoDestinationBox = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.destinationauto); autoDestinationBox.Adapter = destinationSuggestionsAdapter; autoDestinationBox.ItemClick += mDestinationTextBoxClicked; mLoadingDialog.Show(); mRecyclerView = rootView.FindViewById <RecyclerView>(Resource.Id.cabrecycler); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Application.Context); mRecyclerView.SetLayoutManager(linearLayoutManager); mRecyclerView.AddItemDecoration(new VerticalSpaceItemDecoration(VERTICAL_ITEM_SPACE)); LayoutInflater inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService); View Childlayout = inflater.Inflate(Resource.Layout.fragment_google_maps, null); if (msourceRecieved != null) { GeoResponse mResponseGetSourcelatlng = await api.GeoCodingResult(token, msourceRecieved); slat = mResponseGetSourcelatlng.Position.Latitude; slng = mResponseGetSourcelatlng.Position.Longitude; hasSourceSet = false; setSourceMarker(msourceRecieved); } CabsResponse response = await api.GetNearbyCabs(slat, slng, Constants.AUTH_TOKEN); if (response.Code == ResponseCode.SUCCESS) { mCabs = response.Cabs; mAdapter = new CabRecyclerAdapter(Application.Context, mCabs, mActivity); mAdapter.ItemClick += OnItemClick; mRecyclerView.SetAdapter(mAdapter); mLoadingDialog.Dismiss(); } }