예제 #1
0
        //private ObservableCollection<TopHeadlines> OriginalGlobalTopHeadLines = new ObservableCollection<TopHeadlines>();
        //private ObservableCollection<Source> OriginalGlobalSources = new ObservableCollection<Source>();
        //private ObservableCollection<Everything> OriginalGlobalEverythings = new ObservableCollection<Everything>();
        //private ObservableCollection<WeatherDataSource> OriginalGlobalWeatherDataSource = new ObservableCollection<WeatherDataSource>();

        public async Task <WeatherDataSource> GetWeatherDataSourceAsync(String TextToSearch)
        {
            //if (OriginalGlobalCountry != null && OriginalGlobalCountry.Count > 0)
            //    return OriginalGlobalCountry;

            var result = new WeatherDataSource();

            //var resultLanguage = new List<Language>();
            try
            {
                using (var client = new HttpClient())
                {
                    var stringResponse = await client.GetStringAsync($"https://api.apixu.com/v1/current.json?key=9c53c92268204fa3bd103431192803&q={TextToSearch}");

                    result = JsonConvert.DeserializeObject <WeatherDataSource>(stringResponse);
                    //OriginalGlobalWeatherDataSource = new ObservableCollection<WeatherDataSource>(result);
                };
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
            }

            return(result);
        }
예제 #2
0
        public MasterContentPageViewModel(INavigationService navigationService, Realm realm, IDataService sourcesService, Prism.Events.IEventAggregator e) :
            base(navigationService)
        {
            Title = "Consulta el clima";
            _navigationService       = navigationService;
            _weatherDataSourceList   = new WeatherDataSource();
            _recentItemsList         = new ObservableCollection <RecentItems>();
            _OriginalrecentItemsList = new ObservableCollection <RecentItems>();
            _sourcesService          = sourcesService;
            _realm = realm;

            SearchButtonCommand   = new DelegateCommand(ExecuteClick, CanExecuteClick);
            ExecuteItemTapCommand = new DelegateCommand(ExecuteItemTap);

            CmdExecuteDeleteItemRecentList = new DelegateCommand <RecentItems>(DeleteItemRecentList);


            SearchCommand     = new  DelegateCommand(ExecuteSearchCommand);
            cmdRefreshCommand = new DelegateCommand(ExecuteRefreshCommand);

            cmdRefreshWhetherCommand = new DelegateCommand(ExecuteRefreshWhetherCommand);

            DeleteRecentItems();
            LoadRecentItemFromLocalDatabase();



            RecentItems itemfirstSelect = new RecentItems();

            itemfirstSelect = RecentItemsList.FirstOrDefault();
            if (itemfirstSelect != null)
            {
                GetWeatherDataSourceFromAPI(itemfirstSelect.Name);
            }
        }