private async Task <bool> downloadPoiImgAsync(PoiApiRequest api, ViewPoi viewPoi) { bool result = false; if (!string.IsNullOrEmpty(viewPoi.ImgFilename)) { string pathToImg = Path.Combine(ImagePathManager.GetPicturesDirectory(), viewPoi.ImgFilename); string mapMarkerPreviewFilename = "map_" + viewPoi.ImgFilename; string pathToImgMarker = Path.Combine(ImagePathManager.GetPicturesDirectory(), mapMarkerPreviewFilename); if (!File.Exists(pathToImg) && (!string.IsNullOrEmpty(viewPoi.ImgFilename))) { result = await api.DownloadImg(viewPoi.Id, pathToImg); } if (!File.Exists(pathToImgMarker) && File.Exists(pathToImg)) { int sizeMarkerDivider = 3;//примерный делитель для получения более менее видимого маркера int sizeMarker = Convert.ToInt32(DeviceSize.FullScreenHeight / sizeMarkerDivider); ImagePreviewManager preview = new ImagePreviewManager(); preview.PreviewHeight = sizeMarker; preview.PreviewWidth = sizeMarker; preview.PreviewQuality = 30; preview.CreateImagePreview(ImagePathManager.GetPicturesDirectory(), viewPoi.ImgFilename, ImagePathManager.GetPicturesDirectory(), mapMarkerPreviewFilename); } } return(result); }
private async Task refreshPoisAsync() { string token = await _tokenService.GetAuthTokenAsync(); string userId = await _tokenService.GetUserIdAsync(); if (!string.IsNullOrEmpty(token)) { IsPoisLoaded = false; IsLoadingPoi = true; PoiApiRequest poiApi = new PoiApiRequest(token); var pois = await poiApi.GetMyPoisAsync(); PoiManager poiManager = new PoiManager(); pois.ForEach(p => { ViewPoi poi = new ViewPoi(p); poi.Save(); }); _pois = poiManager.GetAllAvailablePois(userId); await Task.WhenAll(_pois.Select(async p => await downloadPoiImgAsync(poiApi, p))); MainThread.BeginInvokeOnMainThread(() => { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("POIs")); IsPoisLoaded = !IsPoisLoaded; IsLoadingPoi = !IsLoadingPoi; }); } }
public async void SelectedPin(string poiId) { IsPoiDialogVisible = true; var poi = _pois.Single(p => p.Id.Equals(poiId)); _currentViewPoi = poi; CurrentPoiName = poi.Name; CurrentPoiImage = Path.Combine(ImagePathManager.GetPicturesDirectory(), poi.ImgFilename); CurrentPoiImage = File.Exists(CurrentPoiImage) ? CurrentPoiImage : "emptyphoto.png"; CurrentPoiDescription = poi.Description; if (!string.IsNullOrEmpty(_currentViewPoi?.ByRouteId)) { var creator = new ViewUserInfo(); creator.Load(_currentViewPoi.CreatorId); CurrentPoiCreatorName = creator?.Name; CurrentPoiCreatorImg = !string.IsNullOrEmpty(creator?.ImgUrl)? creator?.ImgUrl : string.Empty; if (string.IsNullOrEmpty(CurrentPoiCreatorName)) { if (await creator.UpdateFromServerAsync()) { CurrentPoiCreatorName = creator.Name; CurrentPoiCreatorImg = creator.ImgUrl; } } } else { CurrentPoiCreatorName = string.Empty; CurrentPoiCreatorImg = string.Empty; } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsVisibleCreator")); }
public EditPoiViewModel(string poiId, string routePointId) { BackNavigationCommand = new Command(backNavigationCommand); DeleteCommand = new Command(deleteCommand); UpdatePoiCommand = new Command(updatePoiCommand); PickImageCommand = new Command(pickImageCommand); _vpoi = new ViewPoi(poiId); _isNewPoi = string.IsNullOrEmpty(_vpoi.Name); if (!string.IsNullOrEmpty(routePointId)) { _vpoi.ByRoutePointId = routePointId; _vpoint = new ViewRoutePoint(); _vpoint.Refresh(_vpoi.ByRoutePointId); } }
public bool Save(ViewPoi viewPoi) { bool result = false; try { RealmInstance.Write(() => { var poi = !string.IsNullOrEmpty(viewPoi.Id) ? RealmInstance.Find <Poi>(viewPoi.Id) : null; if (null == poi) { poi = string.IsNullOrEmpty(viewPoi.Id) ? new Poi() : new Poi() { PoiId = viewPoi.Id }; RealmInstance.Add(poi); } poi.Name = viewPoi.Name; poi.CreateDate = viewPoi.CreateDate; poi.UpdateDate = viewPoi.UpdateDate; poi.IsDeleted = viewPoi.IsDeleted; poi.CreatorId = viewPoi.CreatorId; poi.ImgFilename = viewPoi.ImgFilename; poi.Description = viewPoi.Description; //poi.PoiType = viewPoi.PoiType; poi.Address = viewPoi.Address; poi.ByRoutePointId = viewPoi.ByRoutePointId; poi.ByRouteId = viewPoi.ByRouteId; poi.IsPublished = viewPoi.IsPublished; poi.Latitude = viewPoi.Location.Latitude; poi.Longitude = viewPoi.Location.Longitude; poi.LikesCount = viewPoi.LikesCount; poi.ViewsCount = viewPoi.ViewsCount; }); var poiSaved = RealmInstance.Find <Poi>(viewPoi.Id); viewPoi.Refresh(poiSaved.PoiId); result = true; } catch (Exception e) { HandleError.Process("PoiManager", "SavePoi", e, false); } return(result); }
private async Task updatePoiStatusAsync() { if (!_newPoint) { TokenStoreService tokenService = new TokenStoreService(); string authToken = await tokenService.GetAuthTokenAsync(); PoiApiRequest poiApi = new PoiApiRequest(authToken); var wsPoi = await poiApi.GetPoiByRoutePointIdAsync(_vpoint.Id); if (poiApi.LastHttpStatusCode == HttpStatusCode.OK) { _vPoi = new ViewPoi(wsPoi); _vPoi.Save(); IsPoiExists = true; } } else { IsPoiExists = false; } }
public async void StartDialog() { _vpoint.Refresh(_vpoint.Id); //Пока не знаю как поймать событие того, редактировалось описание на другой странице и вернулись на текущую уже с модифицированным описанием PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Description")); MessagingCenter.Subscribe <RoutePointDescriptionModifiedMessage>(this, string.Empty, (sender) => { if (sender.RoutePointId.Equals(_vpoint.Id)) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Description")); } }); MessagingCenter.Subscribe <MapSelectNewPointMessage>(this, string.Empty, (sender) => { setNewCoordinates(sender.Latitude, sender.Longitude); }); /*MessagingCenter.Subscribe<PageNavigationMessage>(this, string.Empty, (sender) => * { * if (sender.PageToOpen == MainPages.OverviewRouteMap) * { * MainThread.BeginInvokeOnMainThread(() => * { * var mapRoutePage = new MapRouteOverviewV2Page(_vpoint.RouteId); * Navigation.PushModalAsync(mapRoutePage, false); * }); * } * });*/ if ((_newPoint) && (_vpoint.Latitude == 0) && (_vpoint.Longitude == 0)) { var cacheCoordinates = await _geolocatorManager.GetLastKnownPosition(); if ((cacheCoordinates.Latitude != 0) && (cacheCoordinates.Longtitude != 0)) { Latitude = cacheCoordinates.Latitude; Longitude = cacheCoordinates.Longtitude; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Coordinates")); } var coordinates = await _geolocatorManager.GetCurrentLocationAsync(); if ((coordinates.Latitude != 0) && (coordinates.Longtitude != 0)) { Latitude = coordinates.Latitude; Longitude = coordinates.Longtitude; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Coordinates")); ApplyChanges(); await fillAddressAndPointName(Latitude, Longitude); ApplyChanges(); } } Device.StartTimer(TimeSpan.FromMilliseconds(100), OnTimerForUpdateLocation); MessagingCenter.Subscribe <PoiUpdatedMessage>(this, string.Empty, (sender) => { PoiManager poiManager = new PoiManager(); var vPoi = poiManager.GetPoiByRoutePointId(_vpoint.Id); if (!string.IsNullOrEmpty(vPoi.Id) && vPoi.Id.Equals(sender.PoiId)) { _vPoi = vPoi; IsPoiExists = true; } else { IsPoiExists = false; } }); await updatePoiStatusAsync(); }
private void hidePoiDialogCommand(object obj) { IsPoiDialogVisible = false; _currentViewPoi = null; }