Example #1
0
        public int InsertItem(PoisToDownload item)
        {
            var task = Database.InsertAsync(item);

            task.Wait();
            return(task.Result);
        }
Example #2
0
        public int DeleteItem(PoisToDownload item)
        {
            var task = Database.DeleteAsync(item);

            task.Wait();
            return(task.Result);
        }
        private void DownloadElevationDataFromInternet(PoisToDownload source)
        {
            try
            {
                var ec = new ElevationDataImport(source);

                var lastProgressUpdate = System.Environment.TickCount;

                var pd = new ProgressDialog(this);
                pd.SetMessage(Resources.GetText(Resource.String.Download_LoadingData));
                pd.SetCancelable(false);
                pd.SetProgressStyle(ProgressDialogStyle.Horizontal);
                pd.Show();

                ec.OnFinishedAction = (result) =>
                {
                    pd.Hide();
                    if (result == true)
                    {
                        source.DownloadDate = DateTime.Now;
                        AppContext.Database.InsertItem(source);

                        PopupHelper.InfoDialog(this, Resource.String.Download_InfoLoadedElevation);

                        _downloadItemAdapter.NotifyDataSetChanged();
                    }
                };
                ec.OnStageChange = (resourceStringId, max) =>
                {
                    MainThread.BeginInvokeOnMainThread(() =>
                    {
                        pd.SetMessage(Resources.GetText(resourceStringId));
                        pd.Max = max;
                    });
                };
                ec.OnProgressChange = (progress) =>
                {
                    var tickCount = System.Environment.TickCount;
                    if (tickCount - lastProgressUpdate > 100)
                    {
                        MainThread.BeginInvokeOnMainThread(() => { pd.Progress = progress; });
                        Thread.Sleep(50);
                        lastProgressUpdate = tickCount;
                    }
                };
                ec.OnError = (message) =>
                {
                    PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloadingElevation, message);
                };

                ec.Execute(ElevationDataImport.COMMAND_DOWNLOAD);
            }
            catch (Exception ex)
            {
                PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloadingElevation, ex.Message);
            }
        }
        private void DeleteElevationDataFromInternet(PoisToDownload source)
        {
            try
            {
                var ec = new ElevationDataImport(source);

                var pd = new ProgressDialog(this);
                pd.SetMessage(Resources.GetText(Resource.String.Download_RemovingData));
                pd.SetCancelable(false);
                pd.SetProgressStyle(ProgressDialogStyle.Horizontal);
                pd.Show();

                ec.OnFinishedAction = (result) =>
                {
                    pd.Hide();
                    if (result == true)
                    {
                        source.DownloadDate = null;
                        AppContext.Database.DeleteItem(source);

                        PopupHelper.InfoDialog(this, Resource.String.Download_InfoRemovedElevation);
                    }
                };
                ec.OnStageChange = (resourceStringId, max) =>
                {
                    MainThread.BeginInvokeOnMainThread(() =>
                    {
                        pd.SetMessage(Resources.GetText(resourceStringId));
                        pd.Max = max;
                    });
                };
                ec.OnError = (message) =>
                {
                    PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloadingElevation, message);
                };

                ec.Execute(ElevationDataImport.COMMAND_REMOVE);
            }
            catch (Exception ex)
            {
                PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloadingElevation, ex.Message);
            }
        }
Example #5
0
 public ElevationDataImport(PoisToDownload source)
 {
     _source = source;
 }
        private void OnIndexDownloaded(string json)
        {
            try
            {
                _downloadViewItems = new List <DownloadViewItem>();

                //fetch list of already downladed items from database
                var downloadedTask = AppContext.Database.GetDownloadedPoisAsync();
                downloadedTask.Wait();
                var _downloadItems = downloadedTask.Result.ToList();

                if (!String.IsNullOrEmpty(json))
                {
                    var _horizonIndex = JsonConvert.DeserializeObject <HorizonIndex>(json);

                    //combine those two lists together
                    foreach (var country in _horizonIndex)
                    {
                        foreach (var item in country.PoiData)
                        {
                            var fromDB = _downloadItems.Find(x => x.Id == item.Id);

                            if (fromDB == null)
                            {
                                fromDB = new PoisToDownload()
                                {
                                    Id           = item.Id,
                                    Description  = item.Description,
                                    Category     = item.Category,
                                    Url          = item.Url,
                                    Country      = country.Country,
                                    PointCount   = item.PointCount,
                                    DateCreated  = item.DateCreated,
                                    DownloadDate = null
                                };
                            }

                            var x = new DownloadViewItem(fromDB, item);
                            _downloadViewItems.Add(x);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloading, e.Message);
                return;
            }

            var countries = _downloadViewItems.Select(x => x.fromDatabase.Country)
                            .Distinct()
                            .OrderBy(x => PoiCountryHelper.GetCountryName(x))
                            .ToList();

            Task.Run(async() =>
            {
                var defaultCountry = await PoiCountryHelper.GetDefaultCountryByPhoneLocation();
                MainThread.BeginInvokeOnMainThread(() =>
                {
                    _countryAdapter.SetItems(countries);
                    SelectCountry(defaultCountry);
                });
            });
        }
Example #7
0
 public DownloadViewItem(PoisToDownload fromDatabase, PoiData fromInternet)
 {
     this.fromDatabase = fromDatabase;
     this.fromInternet = fromInternet;
 }
Example #8
0
 public PoiFileImport(PoisToDownload source)
 {
     _source = source;
 }