Ejemplo n.º 1
0
        public int InsertItem(DownloadedElevationData item)
        {
            var task = Database.InsertAsync(item);

            task.Wait();
            return(task.Result);
        }
Ejemplo n.º 2
0
        public int DeleteItem(DownloadedElevationData item)
        {
            var task = Database.DeleteAsync(item);

            task.Wait();
            return(task.Result);
        }
Ejemplo n.º 3
0
        private void DownloadElevationData(DownloadedElevationData ded)
        {
            var edd = new ElevationDataDownload(new GpsLocation(ded.Longitude, ded.Latitude, 0), ded.Distance);

            var pd = new ProgressDialog(this);

            pd.SetMessage(Resources.GetText(Resource.String.Download_Progress_DownloadingElevationData));
            pd.SetCancelable(false);
            pd.SetProgressStyle(ProgressDialogStyle.Horizontal);
            pd.Max = 100;
            pd.Show();

            edd.OnFinishedAction = (result) =>
            {
                pd.Hide();
                if (!string.IsNullOrEmpty(result))
                {
                    PopupHelper.ErrorDialog(this, result);
                }
                else
                {
                    ded.SizeInBytes = edd.GetSize();
                    AppContext.DownloadedElevationDataModel.UpdateItem(ded);
                    Finish();
                }
            };
            edd.OnProgressChange = (progress) =>
            {
                MainThread.BeginInvokeOnMainThread(() => { pd.Progress = progress; });
                Thread.Sleep(50);
            };

            edd.Execute();
        }
 internal void DeleteItem(DownloadedElevationData item)
 {
     _database.DeleteItem(item);
     MainThread.BeginInvokeOnMainThread(() =>
                                        DownloadedElevationDataDeleted?.Invoke(this, new DownloadedElevationDataEventArgs()
     {
         data = item
     })
                                        );
 }
 public void InsertItem(DownloadedElevationData item)
 {
     _database.InsertItem(item);
     MainThread.BeginInvokeOnMainThread(() =>
                                        DownloadedElevationDataAdded?.Invoke(this, new DownloadedElevationDataEventArgs()
     {
         data = item
     })
                                        );
 }
Ejemplo n.º 6
0
        private void DeleteElevationTiles(DownloadedElevationData ded)
        {
            var dedTiles = new ElevationTileCollection(new GpsLocation(ded.Longitude, ded.Latitude, 0), ded.Distance);

            Task.Run(async() =>
            {
                var downloadedElevationData = await AppContext.Database.GetDownloadedElevationDataAsync();
                var tilesToBeRemoved        = ElevationTileCollection.GetUniqueTilesForRemoval(ded.Id, downloadedElevationData, dedTiles);
                tilesToBeRemoved.Remove();
            });
        }
Ejemplo n.º 7
0
        private void RemoveElevationData(DownloadedElevationData ded, int oldDedDistance)
        {
            var location               = new GpsLocation(ded.Longitude, ded.Latitude, 0);
            var tilesToBeRemovedAll    = ElevationTileCollection.GetTilesForRemoval(location, oldDedDistance, ded.Distance);
            var tilesToBeRemovedUnique = ElevationTileCollection.GetUniqueTilesForRemoval(ded.Id, _allElevationData, tilesToBeRemovedAll);

            tilesToBeRemovedUnique.Remove();

            var edd = new ElevationDataDownload(new GpsLocation(ded.Longitude, ded.Latitude, 0), ded.Distance);

            ded.SizeInBytes = edd.GetSize();
            AppContext.DownloadedElevationDataModel.UpdateItem(ded);
            Finish();
        }
Ejemplo n.º 8
0
        private void SaveElevationData(Poi poi)
        {
            if (poi == null)
            {
                return;
            }

            var ded = new DownloadedElevationData()
            {
                Latitude  = poi.Latitude,
                Longitude = poi.Longitude,
                Altitude  = poi.Altitude,
                PlaceName = poi.Name,
                Country   = poi.Country,
                Distance  = GetDownloadDistance()
            };

            var gpsLocation = new GpsLocation(poi.Longitude, poi.Latitude, poi.Altitude);
            var ed          = new ElevationDataDownload(gpsLocation, ded.Distance);

            /*if (ed.GetCountToDownload() == 0)
             * {
             *  PopupHelper.InfoDialog(this, Resources.GetText(Resource.String.DownloadED_NoDataToDownload));
             *  return;
             * }*/

            if (_oldDedItem != null)
            {
                ded.Id = _oldDedItem.Id;
                if (ded.Distance < _oldDedItem.Distance)
                {
                    RemoveElevationData(ded, _oldDedItem.Distance);
                }
                else
                {
                    DownloadElevationData(ded);
                }
            }
            else
            {
                AppContext.DownloadedElevationDataModel.InsertItem(ded);
                DownloadElevationData(ded);
            }
        }
Ejemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            AppContextLiveData.Instance.SetLocale(this);
            Platform.Init(this, savedInstanceState);

            if (AppContextLiveData.Instance.IsPortrait)
            {
                SetContentView(Resource.Layout.AddElevationDataActivityPortrait);
            }
            else
            {
                SetContentView(Resource.Layout.AddElevationDataActivityLandscape);
            }

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);

            ActionBar.SetDisplayShowHomeEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetDisplayShowTitleEnabled(true);
            ActionBar.SetTitle(Resource.String.DownloadElevationDataActivity);

            FindViewById <Button>(Resource.Id.buttonSave).SetOnClickListener(this);
            FindViewById <Button>(Resource.Id.buttonSelect).SetOnClickListener(this);
            FindViewById <LinearLayout>(Resource.Id.linearLayoutSelectedPoint).SetOnClickListener(this);
            FindViewById <RadioButton>(Resource.Id.radioButton100km).SetOnClickListener(this);
            FindViewById <RadioButton>(Resource.Id.radioButton200km).SetOnClickListener(this);
            FindViewById <RadioButton>(Resource.Id.radioButton300km).SetOnClickListener(this);

            var id = Intent.GetLongExtra("Id", -1);

            if (id != -1)
            {
                _oldDedItem    = AppContext.Database.GetDownloadedElevationDataItem(id);
                _selectedPoint = new Poi()
                {
                    Latitude  = _oldDedItem.Latitude,
                    Longitude = _oldDedItem.Longitude,
                    Altitude  = _oldDedItem.Altitude,
                    Name      = _oldDedItem.PlaceName,
                    Country   = _oldDedItem.Country
                };
                SetDownloadDistance(_oldDedItem.Distance);
                FindViewById <Button>(Resource.Id.buttonSelect).Enabled = false;
            }
            else if (Peaks360Lib.Utilities.GpsUtils.HasLocation(AppContext.MyLocation))
            {
                _selectedPoint = PoiSelectActivity.GetMyLocationPoi(AppContext);
                FindViewById <Button>(Resource.Id.buttonSelect).Enabled = true;
            }
            else
            {
                _selectedPoint = GetUnknownPoi(AppContext);
                FindViewById <Button>(Resource.Id.buttonSelect).Enabled = true;
            }

            OnSelectionUpdated(_selectedPoint);
            CalculateDownloadSize(_selectedPoint);

            Task.Run(async() => { _allElevationData = await AppContext.Database.GetDownloadedElevationDataAsync(); });
        }