private void RefreshSavedLocationsItems() { if (SavedLocationsListView == null || SavedLocationsListView.Items.Count == 0) { return; } foreach (LocationItem location in SavedLocationsListView.Items) { var isPinned = TileDesigner.IsSecondaryTilePinned(location); var item = (ListViewItem)SavedLocationsListView.ContainerFromItem(location); if (item == null) { continue; } var slidableListItem = (SlidableListItem)item.ContentTemplateRoot; if (isPinned) { slidableListItem.LeftLabel = App.ResourceLoader.GetString("Unpin"); slidableListItem.LeftIcon = Symbol.UnPin; } else { slidableListItem.LeftLabel = App.ResourceLoader.GetString("Pin"); slidableListItem.LeftIcon = Symbol.Pin; } } }
private async void SlidableListItem_LeftCommandRequested(object sender, EventArgs e) { var item = (SlidableListItem)sender; var location = (LocationItem)item.DataContext; var isPinned = TileDesigner.IsSecondaryTilePinned(location); if (isPinned) { var unpinSuccess = await UnpinLocationOnStart(location); if (unpinSuccess) { item.LeftLabel = App.ResourceLoader.GetString("Pin"); item.LeftIcon = Symbol.Pin; DataTransfer.ShowLocalToast(App.ResourceLoader.GetString("UnpinSuccess")); } return; } var pinSuccess = await PinLocationOnStart(location); if (pinSuccess) { item.LeftLabel = App.ResourceLoader.GetString("Unpin"); item.LeftIcon = Symbol.UnPin; DataTransfer.ShowLocalToast(App.ResourceLoader.GetString("PinSuccess")); } }
private void SavedLocation_RightTapped(object sender, RightTappedRoutedEventArgs ev) { var listItem = (SlidableListItem)sender; var location = (LocationItem)listItem.DataContext; _lastLocationSelected = location; if (string.IsNullOrEmpty(location.Id)) { return; } var isPinned = TileDesigner.IsSecondaryTilePinned(location); if (isPinned) { CmdUnpinLocation.Visibility = Visibility.Visible; CmdPinLocation.Visibility = Visibility.Collapsed; } else { CmdUnpinLocation.Visibility = Visibility.Collapsed; CmdPinLocation.Visibility = Visibility.Visible; } SavedLocationRightTappedFlyout.ShowAt(listItem); }
private async void FetchNewData() { var location = await Settings.GetFavoriteLocation(); if (location == null || string.IsNullOrEmpty(location.Id)) { var granted = await GetLocationPermission(); if (!granted) { ShowNoAccessView(); return; } ShowLoadingView(); var position = await GetPosition(); SetCurrentCity(); location = new LocationItem() { Latitude = position.Latitude, Longitude = position.Longitude }; } else { ShowLoadingView(); SetCurrentCity(); } await FetchCurrentForecast(location); ShowLocalizationSuccess(); TileDesigner.UpdatePrimary(_lastPosition); Settings.CacheForecastData(_pageDataSource.Forecast); Settings.CacheLocationAndTime( _currentTown, DateTime.Now.ToLocalTime().ToString("dddd HH:mm")); Timer deffered = null; deffered = new Timer(async(object state) => { await _UIDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (LoadingView.Visibility == Visibility.Collapsed) { deffered?.Dispose(); return; } HideLoadingView(); PopulateView(); PopulateCurrentLocationAndTime(); }); }, new AutoResetEvent(true), 3000, 2000); }
/// <summary> /// Find the LocationItem from storage and get new data for the specific location. /// If the item isn't found, abort and get new data for the current lcoation. /// (Handle no connectivity) /// </summary> /// <param name="locationId"></param> private async void FetchNewDataFromLocation(string locationId) { if (!NetworkInterface.GetIsNetworkAvailable()) { LoadCachedData(); return; } var locationsList = await Settings.GetSavedLocationAsync(); var locationName = locationId.Replace(".", ", "); LocationItem locationToFind = null; foreach (var location in locationsList) { if (location.Name == locationName) { locationToFind = location; break; } } if (locationToFind == null) { InitializePageData(); return; } ShowLoadingView(); await FetchCurrentForecast(locationToFind); HideLoadingView(); PopulateView(); PopulateCurrentLocationAndTime(); TownTextBlock.Text = locationToFind.Town; TileDesigner.UpdatePrimary(_lastPosition); Settings.CacheForecastData(_pageDataSource.Forecast); Settings.CacheLocationAndTime( _currentTown, DateTime.Now.ToLocalTime().ToString("dddd HH:mm")); }
private async Task <bool> UnpinLocationOnStart(LocationItem location) { // 1.Unpin var locationId = TileDesigner.ConvertLocationNameToTileId(location.Name); var isUnpinned = await TileDesigner.UnpinSecondaryTile(locationId); if (!isUnpinned) { return(false); } // 2.Delete task config await Settings.DeleteSecondaryTaskLocation(locationId); // 3.Unregister task BackgroundTasks.UnregisterSecondaryTileTask(locationId); return(true); }
public async void Run(IBackgroundTaskInstance taskInstance) { StartTask(taskInstance); // 1.Get LocatonItem from storage (json) var location = Settings.GetLocationAsync(taskInstance.Task.Name); if (location == null || !SecondaryTile.Exists(taskInstance.Task.Name)) { EndTask(); return; } // 2.Fetch current weather var forecast = await FetchCurrentForecast(location.Latitude, location.Longitude); // 3.Update secondary tile TileDesigner.UpdateSecondary(taskInstance.Task.Name, forecast, location.Town); EndTask(); }
public async void Run(IBackgroundTaskInstance taskInstance) { StartTask(taskInstance); string city = ""; LocationItem location = null; if (GetTaskType() == _GPSTaskTypeKey) { var position = await GetPosition(); if (position == null) { EndTask(); return; } var coord = position.Coordinate.Point.Position; location = new LocationItem() { Latitude = coord.Latitude, Longitude = coord.Longitude }; city = await GetCityName(coord); } else { location = Settings.GetFavoriteLocation(); city = location?.Town; } var forecast = await FetchCurrentWeather(location.Latitude, location.Longitude); TileDesigner.UpdatePrimary(forecast, city); LogTaskActivity(); EndTask(); }
private void SavedLocation_Loaded(object sender, RoutedEventArgs e) { _delaySavedLocationList += 100; var item = (SlidableListItem)sender; item.Offset(0, 50, 0) .Fade(0, 0) .Then() .Offset(0) .Fade(1) .SetDelay(_delaySavedLocationList) .Start(); var location = (LocationItem)item.DataContext; var isPinned = TileDesigner.IsSecondaryTilePinned(location); if (isPinned) { item.LeftLabel = App.ResourceLoader.GetString("Unpin"); item.LeftIcon = Symbol.UnPin; } }
private async Task <bool> PinLocationOnStart(LocationItem location) { // 1.Ask for pin var locationId = TileDesigner.ConvertLocationNameToTileId(location.Name); var isPined = await TileDesigner.PinSecondaryTile(location); if (!isPined) { return(false); } // 2.Register task config await Settings.SaveSecondaryTaskLocation(locationId, location); // 3.Register task BackgroundTasks.RegisterSecondaryTileTask(locationId); // 4.Update the tile var forecast = await App.DataSource.GetCurrentForecast(location.Latitude, location.Longitude); TileDesigner.UpdateSecondary(locationId, forecast, location); return(true); }