public RoutePointV2ViewModel(string routeId, string routePointId) { BackNavigationCommand = new Command(backNavigationCommand); TakePhotoCommand = new Command(takePhotoAsync); ViewPhotoCommand = new Command(viewPhotoAsync); PressPhotoCommand = new Command(pressPhotoCommand); PlayMediaCommand = new Command(playMediaAsync); DeletePhotoCommand = new Command(deletePhotoAsync); DeletePointCommand = new Command(deletePoint); AddPhotoCommand = new Command(addPhotoAsync); AddAudioCommand = new Command(addAudioAsync); ShareCommand = new Command(shareCommand); EditNameCommand = new Command(editNameCommand); CancelNameCommand = new Command(cancelNameCommand); EditNameCompleteCommand = new Command(editNameCompleteCommand); ClearNameCommand = new Command(clearNameCommand); EditDescriptionCommand = new Command(editDescriptionCommand); CopyCoordinatesCommand = new Command(copyCoordinatesCommand); UpdateAddressCommand = new Command(updateAddressCommand); CopyAddressCommand = new Command(copyAddressCommand); RecognizeAudioCommand = new Command(recognizeAudioCommandAsync); RecordAudioStopAndSaveCommand = new Command(recordAudioStopAndSaveCommand); RecordAudioCancel = new Command(recordAudioCancel); ShareToMapCommand = new Command(shareToMapCommand); EditPoiDialogCommand = new Command(editPoiDialogCommand); _vpoint = new ViewRoutePoint(routeId, routePointId); _routePointManager = new RoutePointManager(); _newPoint = string.IsNullOrEmpty(routePointId); Analytics.TrackEvent("Dialog point opened"); }
internal bool Delete(ViewRoutePoint viewRoutePoint) { bool result = false; string rId = viewRoutePoint.RouteId; try { RealmInstance.Write(() => { var point = RealmInstance.Find <RoutePoint>(viewRoutePoint.Id); foreach (var item in point.MediaObjects) { RealmInstance.Remove(item); } RealmInstance.Remove(point); }); result = true; } catch (Exception e) { HandleError.Process("RoutePointManager", "DeleteRoutePoint", e, false); } return(result); }
private async void addNewPointFromShareAsync(string routeName) { if (_sharePointMessage != null) { ViewRoutePoint newPoint = new ViewRoutePoint(_routeItem.RouteId, string.Empty); newPoint.Version++; if (string.IsNullOrEmpty(_sharePointMessage.Subject)) { string name = _sharePointMessage.Description.Substring(0, 15); if (_sharePointMessage.Description.Length > 15) { name += "..."; } newPoint.Name = name; } else { newPoint.Name = _sharePointMessage.Subject; } newPoint.Description = _sharePointMessage.Description; CustomGeocoding geo = new CustomGeocoding(newPoint.Description); if (await geo.GetCoordinatesAsync()) { newPoint.Longitude = geo.Longtitude; newPoint.Latitude = geo.Latitude; } if (newPoint.Save()) { _sharePointMessage = null; } } }
internal (ViewRoutePoint, ViewRoutePoint) GetFirstAndLastViewRoutePoints(string routeId) { var routePoints = RealmInstance.All <RoutePoint>().Where(p => p.RouteId == routeId).OrderBy(p => p.CreateDate); if (routePoints.Count() > 0) { var first = new ViewRoutePoint(routeId, routePoints.FirstOrDefault()?.RoutePointId); var last = new ViewRoutePoint(routeId, routePoints.LastOrDefault()?.RoutePointId); return(first, last); } return(new ViewRoutePoint(), new ViewRoutePoint()); }
public PointCarouselItemViewModel(string routeId, string routePointId, string routePointMediaId) { _routeObject = new ViewRoute(routeId); _pointObject = new ViewRoutePoint(routeId, routePointId); _mediaObject = new ViewRoutePointMediaObject(); _mediaObject.Load(routePointMediaId); ChangeImageAspectCommand = new Command(changeImageAspectCommand); EditRoutePointCommand = new Command(editRoutePointCommand); PhotoImageAspect = Aspect.AspectFill; }
public void Share(ViewRoutePoint vpoint, string packageName) { if ((vpoint != null) && (!string.IsNullOrEmpty(vpoint.Id))) { string pointCoordinates = $"{vpoint.Latitude.ToString(CultureInfo.InvariantCulture)},{vpoint.Longitude.ToString(CultureInfo.InvariantCulture)}"; Intent share = new Intent(); share.SetType("text/plain"); if (vpoint.MediaObjectPaths.Count > 1) { share = new Intent(Intent.ActionSendMultiple); share.SetType("image/*"); List <Uri> uris = new List <Uri>(); foreach (var path in vpoint.MediaObjectPaths) { Java.IO.File file = new Java.IO.File(path); var fileUri = FileProvider.GetUriForFile(Android.App.Application.Context, Android.App.Application.Context.PackageName + ".fileprovider", file); uris.Add(fileUri); } share.PutParcelableArrayListExtra(Intent.ExtraStream, uris.ToArray()); } else if (vpoint.MediaObjectPaths.Count == 1) { share = new Intent(Intent.ActionSend); share.SetType("image/*"); Java.IO.File file = new Java.IO.File(vpoint.MediaObjectPaths[0]); var fileUri = FileProvider.GetUriForFile(Android.App.Application.Context, Android.App.Application.Context.PackageName + ".fileprovider", file); share.PutExtra(Intent.ExtraStream, fileUri); } else if (vpoint.MediaObjectPaths.Count == 0) { } share.SetFlags(ActivityFlags.NewTask); share.PutExtra(Intent.ExtraText, $"{pointCoordinates}\n{vpoint.Description}"); share.PutExtra(Intent.ExtraSubject, $"{pointCoordinates}\n{vpoint.NameText}"); share.PutExtra(Intent.ExtraAllowMultiple, true); if (!string.IsNullOrEmpty(packageName)) { AddComponentNameToIntent(packageName, share); } try { Android.App.Application.Context.StartActivity(share); } catch (Exception e) { HandleError.Process("CommonShareService", "Share point", e, false); } } }
private async Task <bool> updatePoints(RouteRoot routeRoot) { bool updateResult = true; List <string> pointsToUpload = new List <string>(); var pointsByRoute = _routePointManager.GetPointsByRouteId(_routeId, true); //если есть новые точки, на отправку pointsToUpload.AddRange(pointsByRoute .Where(p => !routeRoot.Route.Points.Any(sp => sp.Id == p.RoutePointId)).Select(p => p.Id) .ToList()); foreach (var serverPoint in routeRoot.Route.Points) { var localPoint = _routePointManager.GetPointById(serverPoint.Id); if ((localPoint == null) || (serverPoint.Version > localPoint.Version)) { ViewRoutePoint updatePoint = new ViewRoutePoint(serverPoint.RouteId, serverPoint.Id); updatePoint.FillFromWSModel(serverPoint); updateResult = updatePoint.Save(); } else if (serverPoint.Version < localPoint.Version) { //на сервере более старая версия, в очередь на отправку pointsToUpload.Add(serverPoint.Id); } if (!updateResult) { return(false); } } if (pointsToUpload.Count > 0) { List <ViewRoutePoint> viewPointsToUpload = new List <ViewRoutePoint>(); foreach (string routePointId in pointsToUpload) { viewPointsToUpload.Add(new ViewRoutePoint(routeRoot.Route.Id, routePointId)); } updateResult = await UploadAsync(GetJsonStructuresPoints(viewPointsToUpload), _routePointsApi); } return(updateResult); }
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 EditRoutePointDescriptionViewModel(string routePointId) { BackNavigationCommand = new Command(backNavigationCommand); CancelCommand = new Command(cancelCommand); EditDescriptionCommand = new Command(editDescriptionCommand); if (!string.IsNullOrEmpty(routePointId)) { RoutePointManager manager = new RoutePointManager(); var point = manager.GetPointById(routePointId); _vpoint = new ViewRoutePoint(point.RouteId, routePointId); _previousDescription = _vpoint.Description; } else { HandleError.Process("EditRoutePointDescription", "EditDescripton", new Exception("Ошибка, точка еще не создана."), true); } IsEditMode = false; }
public bool Make(AutoGeneratedRouted autoRoute, string creatorId) { if (autoRoute.Points.Count > 0) { var vroute = new ViewRoute(string.Empty); vroute.CreatorId = creatorId; vroute.CreateDate = DateTime.Now; vroute.Name = autoRoute.Name; if (vroute.Save()) { foreach (var autoPoint in autoRoute.Points.Where(p => !p.IsDeleted)) { var vroutePoint = new ViewRoutePoint(vroute.RouteId, string.Empty); vroutePoint.Name = autoPoint.Name; vroutePoint.Longitude = autoPoint.Longitude; vroutePoint.Latitude = autoPoint.Latitude; vroutePoint.Version++; if (vroutePoint.Save()) { foreach (var autoMedia in autoPoint.Images.Where(i => !i.IsDeleted)) { string localImageId = autoMedia.Id; /*if (mediaObjectIsExists(mediaId)) * { * //в случае если мы используем одно и то же фото в нескольких альбомах, придется его дублировать * //связано с тем, что id media соответствует имени файла и если меняем свойства объекта в каком-то маршруте, меняется для всех * //media object в этом случае один, и это проблема * mediaId = makeNewMediaObject(mediaId); * }*/ string mediaId = makeNewMediaObject(localImageId); vroutePoint.AddMediaItem(mediaId, MediaObjectTypeEnum.Image); } vroutePoint.Save(); } } return(true); } } return(false); }
internal void DeleteObjectFromLocalStorage(ViewRoutePoint vpoint) { if (vpoint != null) { try { RoutePoint point = !string.IsNullOrEmpty(vpoint.Id) ? RealmInstance.Find <RoutePoint>(vpoint.Id) : null; if (point != null) { RealmInstance.Write(() => { RealmInstance.Remove(point); }); } } catch (Exception e) { HandleError.Process("RoutePointManager", "DeleteObjectFromLocalStorage", e, false); } } }
public RoutePointViewModel(string routeId, string routePointId) { TakePhotoCommand = new Command(takePhotoAsync); ViewPhotoCommand = new Command(viewPhotoAsync); PlayMediaCommand = new Command(playMediaAsync); DeletePhotoCommand = new Command(deletePhotoAsync); DeletePointCommand = new Command(deletePoint); AddPhotoCommand = new Command(addPhotoAsync); AddAudioCommand = new Command(addAudioAsync); ShareCommand = new Command(shareCommand); EditDescriptionCommand = new Command(editDescriptionCommand); CopyCoordinatesCommand = new Command(copyCoordinatesCommand); _vpoint = new ViewRoutePoint(routeId, routePointId); if (string.IsNullOrEmpty(routePointId)) { //int index = _rnd.Next(0, _pointNames.Count() - 1); //Name = _pointNames[index]; //if ((_vpoint.Latitude == 0) && (_vpoint.Longitude == 0)) FillCurrentPositionAsync(); } Coordinates = Latitude + "," + Longitude; Analytics.TrackEvent("Dialog point opened"); }
public new void Share(ViewRoutePoint vpoint, string packageName) { base.Share(vpoint, packageName); }
internal string Save(ViewRoutePoint vpoint) { string returnid = string.Empty; RouteManager routeManager = new RouteManager(); vpoint.Version = vpoint.Version == 0 ? 1 : vpoint.Version; if (vpoint.CreateDate.Year == 1) { HandleError.Process("RoutePointManager", "Save", new Exception("CreateDate is empty"), false, $"routePointId:[{vpoint.RoutePointId}]"); //throw new Exception("create date year = 1"); //vpoint.CreateDate = new DateTime(2020,1,1); } try { RealmInstance.Write(() => { RoutePoint point = !string.IsNullOrEmpty(vpoint.Id) ? RealmInstance.Find <RoutePoint>(vpoint.Id) : null; if (point == null) { point = new RoutePoint(); point.RoutePointId = !string.IsNullOrEmpty(vpoint.Id) ? vpoint.Id: point.RoutePointId; point.RouteId = vpoint.RouteId; point.MainRoute = routeManager.GetRouteById(vpoint.RouteId); if (point.MainRoute != null) { point.MainRoute.Points.Add(point);//? } else { HandleError.Process("RoutePointManager", "SavePoint", new Exception($"routeId:{vpoint.RouteId}, pointId:{vpoint.Id}"), false); } RealmInstance.Add(point); } else { //point = _realmInstance.Find<RoutePoint>(vpoint.Id); } if (point.Version != vpoint.Version) { //нужно для того, чтобы синхронизация обнаружила отличия от сервера и проверила версии с последующей отправкой изменений на сервер point.MainRoute.ObjVerHash = string.Empty; } returnid = point.RoutePointId; point.Address = vpoint.Address; point.Description = vpoint.Description; point.Latitude = vpoint.Latitude; point.Longitude = vpoint.Longitude; point.Name = vpoint.Name; point.UpdateDate = DateTime.Now; point.Version = vpoint.Version; point.IsDeleted = vpoint.IsDeleted; point.CreateDate = vpoint.CreateDate; point.MediaObjects.Clear(); foreach (var media in vpoint.MediaObjects) { point.MediaObjects.Add(media); } }); } catch (Exception e) { HandleError.Process("RoutePointManager", "AddRoutePoint", e, false); } return(returnid); }