public void downloadfile() { indicator.IsRunning = true; download.IsEnabled = false; message = DependencyService.Get <Imessaging>(); try { if (string.IsNullOrEmpty(media.filePath)) { return; } indicator.IsRunning = true; download.IsEnabled = false; var current = Connectivity.NetworkAccess; if (current != NetworkAccess.Internet) { message.LongAlert("No Internet Connection"); return; } progress.IsVisible = true; //PlayButton.IsEnabled = false; dependency = DependencyService.Get <IFileHelper>(); message = DependencyService.Get <Imessaging>(); var filename = media.id; var all = App.Database.GetDownloadedAudio().Result.FirstOrDefault(x => x.name == filename); if (all != null) { message.LongAlert("This Audio has already been downloaded, please check your Downloads"); indicator.IsRunning = false; download.IsEnabled = true; // PlayButton.IsEnabled = true; return; } WebClient client = new WebClient(); var dir = dependency.GetLocalFilePath(); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (string.IsNullOrEmpty(media.filePath)) { return; } Uri uri = new Uri(media.filePath); client.OpenRead(uri); var bytes_total = client.ResponseHeaders["Content_Lenght"]; client.DownloadFileAsync(uri, $"{dir}/{filename}.mp3"); client.DownloadFileCompleted += Client_DownloadFileCompleted; client.DownloadProgressChanged += Client_DownloadProgressChanged; } catch (Exception ex) { message.LongAlert("Something went wrong please try again"); } }
public CreatePostViewModel() { IsNotBusy = true; AllCategory(); Gets = new ObservableCollection <GetPostCategory>(); Categories = Gets; message = DependencyService.Get <Imessaging>(); }
// ObservableCollection<GetPostCategory> Categories; //CreatePostViewModel vm; public CreatePostPage() { InitializeComponent(); BindingContext = this; message = DependencyService.Get <Imessaging>(); //vm.GetCategoryCommand.Execute(null); Categories = new ObservableCollection <GetPostCategory>(); username.Text = Preferences.Get("userName", string.Empty); AllCategory(); }