コード例 #1
0
        private async void CloseSettings_Click(object sender, RoutedEventArgs e)
        {
            SettingsPageGrid.Visibility = Visibility.Collapsed;
            SettingsPage.Content        = "";
            if (IsFavoritesChanged == true)
            {
                IsFavoritesChanged = false;
                var favorites = (await UserDataHelper.GetFavorites("Favorites.json"));

                var _CurrentPlace = favorites.Where(x => x.PlaceId == _CityData.PlaceInfo.PlaceId).ToList();
                if (_CurrentPlace.Count == 0)
                {
                    SaveToFavorites.Visibility     = Visibility.Visible;
                    RemoveFromFavorites.Visibility = Visibility.Collapsed;
                }
            }
            if (IsSettingsChanged == true)
            {
                IsSettingsChanged = false;
                PlaceInfo _argument = null;
                var       rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                }

                if (_CityData.PlaceInfo.PlaceId != _Settings.DefaultLocation.PlaceId)
                {
                    _argument = _CityData.PlaceInfo;
                }
                rootFrame.Navigate(typeof(ShellPage), _argument);
            }
        }
コード例 #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            _CityData = e.Parameter as CityData;

            /*set country flag*/

            /*string _CountryCode = _CityData.PlaceInfo.DisplayName;
             * _CountryCode = _CountryCode.Substring(_CountryCode.LastIndexOf(",") + 2);
             * StorageFolder _assets = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
             * StorageFolder _flags = await _assets.GetFolderAsync("CountriesFlag");
             *
             * if (_flags.TryGetItemAsync(_CountryCode + ".png") != null)
             * {
             *  CurrentPlaceName.Text = _CityData.PlaceInfo.DisplayName.Substring(0, _CityData.PlaceInfo.DisplayName.LastIndexOf(","));
             *  BitmapImage image = new BitmapImage(new Uri("ms-appx:///Assets/CountriesFlag/" + _CountryCode + ".png"));
             *  CountryFlag.Source = image;
             * }
             * else {
             *  CurrentPlaceName.Text = _CityData.PlaceInfo.DisplayName;
             * }*/
            /*set country flag*/

            CurrentPlaceName.Text = _CityData.PlaceInfo.DisplayName;

            this.DataContext     = _CityData;
            DailyForecastResult  = _CityData.DailyForecast;
            CurrentWeatherResult = _CityData.Current;
            PlaceInfo            = _CityData.PlaceInfo;
            CoverLink            = _CityData.CoverImage;

            /*set back navigation arguments*/
            if (_LocationHistory == null)
            {
                _LocationHistory = new List <PlaceInfo>();
                _LocationHistory.Add(_CityData.PlaceInfo);
            }

            if (_LocationHistory[_LocationHistory.Count - 1].PlaceId != _CityData.PlaceInfo.PlaceId)
            {
                _LocationHistory.Add(_CityData.PlaceInfo);
            }

            if (_LocationHistory.Count > 1)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                AppNameGrid.Margin = new Thickness(55, 10, 0, 10);
            }
            else
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                AppNameGrid.Margin = new Thickness(20, 10, 0, 10);
            }
            /*set back navigation arguments*/
            _Settings = await UserDataHelper.GetSettings("Settings.json");

            if (_Settings.SaveData == "1" || _CityData.IsLocalData == true)
            {
                BottomItemsPivot.Items.Remove(BottomItemsPivot.Items.Single(p => ((PivotItem)p).Name == "NewsPivot"));
                BottomItemsPivot.Items.Remove(BottomItemsPivot.Items.Single(p => ((PivotItem)p).Name == "GalleryPivot"));
                _CityData.CoverImage = "ms-appx:///Assets/Weather/11.jpg";
                if (_CityData.CoverImage != null)
                {
                    BitmapImage image = new BitmapImage(new Uri(_CityData.CoverImage));
                    Cover.Source = image;
                }
            }
            else
            {
                int _CheckFileAge = await ApplicationData.Current.LocalFolder.TryGetItemAsync("News.json") != null ? await UserDataHelper.CheckFileAge("News.json", "local") : 1441;

                string Language = _Settings.Language ?? "en";

                if (_CheckFileAge >= 1440)
                {
                    _NewsResults = await News.GetNewsData(Language);

                    bool _SaveNews = await UserDataHelper.SaveNewsData(_NewsResults);
                }
                else
                {
                    _NewsResults = await UserDataHelper.GetSavedNews();

                    if (_NewsResults.Language != _Settings.Language)
                    {
                        _NewsResults = await News.GetNewsData(Language);

                        bool _SaveNews = await UserDataHelper.SaveNewsData(_NewsResults);
                    }
                }
                NewsData.ItemsSource = _NewsResults.articles;

                await GetCover(_CityData.PlaceInfo.DisplayName);
            }

            CoverLink = _CityData.CoverImage;

            var favorites     = (await UserDataHelper.GetFavorites("Favorites.json"));
            var _CurrentPlace = favorites.Where(x => x.PlaceId == _CityData.PlaceInfo.PlaceId).ToList();

            if (_CurrentPlace.Count > 0)
            {
                SaveToFavorites.Visibility     = Visibility.Collapsed;
                RemoveFromFavorites.Visibility = Visibility.Visible;
            }

            SetAsHome.IsEnabled = _CityData.PlaceInfo.PlaceId == _Settings.DefaultLocation.PlaceId ? false : true;

            if (SecondaryTile.Exists(_CityData.PlaceInfo.PlaceId))
            {
                PinToStart.Visibility     = Visibility.Collapsed;
                UnPinFromStart.Visibility = Visibility.Visible;
                await LiveTile.UpdateCustomTile(PlaceInfo, CurrentWeatherResult, DailyForecastResult, CoverLink);
            }

            if (_CityData.PlaceInfo.PlaceId == _Settings.DefaultLocation.PlaceId)
            {
                LiveTile.UpdateTile(PlaceInfo, CurrentWeatherResult, DailyForecastResult, CoverLink);
            }

            if (favorites.ToList().Where(x => x.PlaceId == _CityData.PlaceInfo.PlaceId).FirstOrDefault() != null)
            {
                await UserDataHelper.SaveFavoriteWeather(_CityData);
            }
        }
コード例 #3
0
ファイル: Favorites.xaml.cs プロジェクト: Lmond/Wecond
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            var favorites = (await UserDataHelper.GetFavorites("Favorites.json"));

            FavoritePlaces = new List <CityData>();
            foreach (var item in favorites)
            {
                var _data = await UserDataHelper.GetFavoriteWeather(item.PlaceId);

                if (_data != null)
                {
                    FavoritePlaces.Add(_data);
                }
                else
                {
                    FavoritePlaces.Add(new CityData()
                    {
                        CoverImage = "ms-appx:///Assets/Weather/11.jpg", PlaceInfo = item
                    });
                }
            }
            var _Count = FavoritePlaces.Count();

            switch (_Count)
            {
            case 0:
                NoPlaces.Visibility = Visibility.Visible;
                break;

            case 1:
                SavedPlacesGridView.MaxWidth = 250;
                break;

            case 2:
                SavedPlacesGridView.MaxWidth = 500;
                break;

            case 3:
                SavedPlacesGridView.MaxWidth = 750;
                break;

            case 4:
                SavedPlacesGridView.MaxWidth = 1000;
                break;

            case 5:
                SavedPlacesGridView.MaxWidth = 1250;
                break;

            case 6:
                SavedPlacesGridView.MaxWidth = 1500;
                break;

            case 7:
                SavedPlacesGridView.MaxWidth = 1750;
                break;

            case 8:
                SavedPlacesGridView.MaxWidth = 2000;
                break;

            case 9:
                SavedPlacesGridView.MaxWidth = 2250;
                break;

            case 10:
                SavedPlacesGridView.MaxWidth = 2500;
                break;
            }
            SavedPlacesGridView.ItemsSource = FavoritePlaces;
        }