コード例 #1
0
        public void OnDownloadItemEdit(int position)
        {
            DownloadViewItem item = _downloadItemAdapter[position];

            if (!item.fromDatabase.DownloadDate.HasValue)
            {
                DownloadPoiDataFromInternet(item);
                _downloadItemAdapter.NotifyDataSetChanged();
            }
        }
コード例 #2
0
        private void DeletePoiDataFromInternet(DownloadViewItem item)
        {
            try
            {
                AppContext.Database.DeleteAllFromSource(item.fromDatabase.Id);

                item.fromDatabase.DownloadDate = null;
                AppContext.Database.DeleteItem(item.fromDatabase);

                //PopupHelper.Toast(this, Resource.String.Download_InfoRemovedItems);
            }
            catch (Exception ex)
            {
                PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorRemoving, ex.Message);
            }
        }
コード例 #3
0
        private void DownloadPoiDataFromInternet(DownloadViewItem item)
        {
            try
            {
                var ec = new PoiFileImport(item.fromDatabase);

                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.Count > 0)
                    {
                        AppContext.Database.InsertAll(result);

                        item.fromDatabase.DateCreated  = item.fromInternet.DateCreated;
                        item.fromDatabase.Description  = item.fromInternet.Description;
                        item.fromDatabase.PointCount   = item.fromInternet.PointCount;
                        item.fromDatabase.Url          = item.fromInternet.Url;
                        item.fromDatabase.DownloadDate = DateTime.Now;

                        AppContext.Database.InsertItem(item.fromDatabase);
                        //PopupHelper.Toast(this, String.Format(Resources.GetText(Resource.String.Download_InfoLoadedItems), result.Count));

                        _downloadItemAdapter.NotifyDataSetChanged();
                    }
                };
                ec.OnStageChange = (resourceStringId, max) =>
                {
                    MainThread.BeginInvokeOnMainThread(() =>
                    {
                        pd.SetMessage(Resources.GetText(resourceStringId));
                        pd.Max = max;
                    });
                };
                ec.OnProgressChange = (progress) =>
                {
                    if (progress % 100 == 0)
                    {
                        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_ErrorDownloading, message);
                };

                ec.Execute(item.fromInternet.Url);
            }
            catch (Exception ex)
            {
                PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloading, ex.Message);
            }
        }
コード例 #4
0
        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);
                });
            });
        }