예제 #1
0
 /// <summary>
 /// This method returns single instance of the class
 /// </summary>
 /// <returns></returns>
 public static GetWeatherReport GetInstance()
 {
     if(getWeatherReport==null)
     {
         getWeatherReport = new GetWeatherReport();
     }
     return getWeatherReport;
 }
예제 #2
0
        /// <summary>
        /// Method to initialize all the resources
        /// </summary>
        /// <param name="bundle"></param>
        protected override async void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);

                // create tabs for current hourly and daily weather
                setTabs();

                InitializeLocationManager();

                //create web service url
                string url =string.Concat(GlobalConstants.WeatherForecastAPIUrl, GlobalConstants.Separator , GlobalConstants.APIKey , GlobalConstants.Separator, GeoLocations.Latitude ,"," , GeoLocations.Longitude);

                // Fetch the weather information asynchronously, parse the results,
                // then update the screen:
                getWeatherReport = GetWeatherReport.GetInstance();
                
                //Show Spinner for getting the response from the Web Service
                ShowProgressBar();

                string strJsonString = await getWeatherReport.FetchWeatherAsync(url);
                if(!string.IsNullOrEmpty(strJsonString) && !string.IsNullOrWhiteSpace(strJsonString))
                {
                IsResponseRecieved = true;
                JSONParser(strJsonString);
                }

                //Dismiss Progress Bar
                DismissProgressBar();
                
                //Refresh the fragment
                RefreshFragment();
            }
            catch ( InvalidOperationException ex)
            {
                Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short);
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short);
            }
        }