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); } }