HistoryItem CreateIncomingItem(DataItem item, bool alreadyDownloaded, ProgressBarX progress, View view) { if (!item.Data.StartsWith(CrossCopyApp.Srv.CurrentPath)) { return new HistoryItem { Incoming = item.Data, Downloading = false } } ; var hItem = new HistoryItem { Incoming = Path.GetFileName(item.Data), LocalPath = BaseDir + item.Data.Substring(4, item.Data.Length - 4), Downloading = !alreadyDownloaded }; if (hItem.Downloading) { progress.Visibility = ViewStates.Visible; progress.Indeterminate = true; view.Visibility = ViewStates.Invisible; StartDownload(item.Data, hItem, progress, view); } return(hItem); } HistoryItem CreateOutgoingItem(DataItem item) { try { var input = GetRealPathFromURI(Android.Net.Uri.Parse(item.Data)); if (!string.IsNullOrEmpty(input) && File.Exists(input)) { return new HistoryItem { Outgoing = Path.GetFileName(input), LocalPath = item.Data, Downloading = false } } ; } catch (Exception) { } return(new HistoryItem { Outgoing = item.Data, Downloading = false }); }
private void StartDownload(string url, HistoryItem hItem, ProgressBarX progress, View view) { var localPath = hItem.LocalPath; Directory.CreateDirectory(Path.GetDirectoryName(localPath)); Server.DownloadFileAsync(url, localPath, (s, e) => { if (e.Error != null) { Console.Out.WriteLine("Error fetching file: " + e.Error.ToString()); } hItem.Downloading = false; UpdateProgress(progress, view, 100); }); }
void UpdateProgress(ProgressBarX progressBar, View view, int progress) { Console.WriteLine(progress); RunOnUiThread(() => { progressBar.Progress = progress; if (progress >= 0 && progress < 100) { progressBar.Visibility = ViewStates.Visible; view.Visibility = ViewStates.Invisible; } else if (progress == 100) { progressBar.Indeterminate = false; progressBar.Visibility = ViewStates.Invisible; view.Visibility = ViewStates.Visible; } }); }
void UpdateProgress(ProgressBarX progressBar, View view, int progress) { RunOnUiThread (() => { progressBar.Progress = progress; if (progress >= 0 && progress < 100) { progressBar.Visibility = ViewStates.Visible; view.Visibility = ViewStates.Invisible; } else if (progress == 100) { progressBar.Indeterminate = false; progressBar.Visibility = ViewStates.Invisible; view.Visibility = ViewStates.Visible; } }); }
private void StartDownload(string url, HistoryItem hItem, ProgressBarX progress, View view) { Directory.CreateDirectory (Path.GetDirectoryName (hItem.LocalPath)); Server.DownloadFileAsync (url, hItem.LocalPath, (s, e) => { if (e.Error != null) Console.Out.WriteLine ("Error fetching file: " + e.Error.ToString ()); hItem.Downloading = false; UpdateProgress (progress, view, 100); }); }
HistoryItem CreateIncomingItem(DataItem item, bool alreadyDownloaded, ProgressBarX progress, View view) { if (!item.Data.StartsWith (CrossCopyApp.Srv.CurrentPath)) return new HistoryItem { Incoming = item.Data, Downloading = false }; var hItem = new HistoryItem { Incoming = Path.GetFileName (item.Data), LocalPath = BaseDir + item.Data.Substring (4, item.Data.Length - 4), Downloading = !alreadyDownloaded }; if (hItem.Downloading) { progress.Visibility = ViewStates.Visible; progress.Indeterminate = true; view.Visibility = ViewStates.Invisible; StartDownload (item.Data, hItem, progress, view); } return hItem; }