public void Initialize() { if (DownloadUri != null && DownloadUri.AbsolutePath != "") { DownloadInfo down = MBDownloadManager.DownloadInfo(DownloadUri.AbsoluteUri); if (down != null && down.Id != 0 && down.Uri != "") { MBDownloadManager.UpdateNotify(DownloadUri, this); this.DownloadStato = DownloadStato.Downloading; } } else { this.DownloadStato = DownloadStato.NoUpdate; } SetUIState(); }
public void ConfigureForDownload() { //pulsante download EventHandler onDownClick = (object sender, EventArgs e) => { this.Stato = DownloadStato.Downloading; //_downloadReference = MBDownloadManager2.Download(_download.Uri, System.IO.Path.GetFileName(_download.Uri.LocalPath), _download.Titolo, this); //_downloadReference = MBDownloadManager2.RequestDownload(DownloadUri, System.IO.Path.GetFileName(DownloadUri.LocalPath), this.Title, this); MBDownloadManager.RequestDownload(DownloadUri, this); SetUIState(); Log.Info(this.Title, "Inizio download"); }; _btnDownload.Click -= onDownClick; _btnDownload.Click += onDownClick; //pulsante ferma EventHandler onStopClick = (object sender, EventArgs e) => { //if(_downloadReference != 0) { MBDownloadManager.StopDownload(DownloadUri); //_downloadReference = 0; this.Stato = InitStato; SetUIState(); } }; _btnStop.Click -= onStopClick; _btnStop.Click += onStopClick; DownloadInfo down = MBDownloadManager.DownloadInfo(DownloadUri.AbsoluteUri); if (down != null && down.Id != 0 && down.Uri != "") { //_downloadReference = down.Id; MBDownloadManager.UpdateNotify(DownloadUri, this); if (down.Status == DownloadStatus.Running || down.Status == DownloadStatus.Pending) { _prgDownload.Progress = 0; } else if (down.Status == DownloadStatus.Successful) { string filePath = new Uri(down.LocalUri).AbsolutePath; if (File.Exists(filePath)) { _prgDownload.Progress = 100; } } this.Stato = DownloadStato.Downloading; } else if (MBDownloadManager.IsWaiting(DownloadUri)) { _prgDownload.Progress = 0; this.Stato = DownloadStato.Downloading; MBDownloadManager.UpdateNotify(DownloadUri, this); } _btnBuy.SetText(this.Prezzo, TextView.BufferType.Normal); SetUIState(); }
private static void DownloadMonitor(long downId) { //bool downloading = true; //Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download"); DownloadInfo down = MBDownloadManager.DownloadInfo(downId); while (down != null) { down = MBDownloadManager.DownloadInfo(downId); if (down == null) { break; } Uri uri = new Uri(down.Uri); if (!MBDownloadManager.pendingRequests.ContainsKey(uri)) { break; } switch (down.Status) { case DownloadStatus.Running: case DownloadStatus.Pending: if (MBDownloadManager.pendingRequests.ContainsKey(uri)) { List <IDownloadUpdated2> list = MBDownloadManager.pendingRequests[uri]; var perc = (int)((down.ByteDownloaded * 100L) / down.ByteTotal); try { foreach (IDownloadUpdated2 current2 in list) { current2.ProgressChanged(perc); } } catch (Exception value) { Console.WriteLine(value); } } break; case DownloadStatus.Successful: try { MBDownloadManager.InstallMbPackage(down.Uri, down.LocalUri); //downloadManager.Remove(down.Id); //downloading = false; //MBDownloadManager.RegisterDownload(uri.ToString(), down.LocalUri); //MBDownloadManager.FinishDownload(uri, true); } catch (Exception value) { Console.WriteLine(value); MBDownloadManager.FinishDownload(uri, false); } break; default: break; } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); this.Window.RequestFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.DownloadDetails); this.SetTitle(_download.Titolo); TextView txtTitolo = FindViewById <TextView>(Resource.Id.txtTitolo); TextView txtAutore = FindViewById <TextView>(Resource.Id.txtAutore); TextView txtPubblicato = FindViewById <TextView>(Resource.Id.txtPubblicato); TextView txtScadenza = FindViewById <TextView>(Resource.Id.txtScadenza); TextView txtDimensione = FindViewById <TextView>(Resource.Id.txtDimensione); ImageView imgCover = FindViewById <ImageView>(Resource.Id.imgCover); Button btnOpen = FindViewById <Button>(Resource.Id.btnOpen); Button btnDownload = FindViewById <Button>(Resource.Id.btnDownload); Button btnBuy = FindViewById <Button>(Resource.Id.btnBuy); TextView txtPrezzo = FindViewById <TextView>(Resource.Id.txtPrezzo); txtTitolo.Text = _download.Titolo; txtAutore.Text = _download.Autore.Trim(); txtPrezzo.Text = ""; if (_download.Tipo == "pdf") { imgCover.SetImageResource(Resource.Drawable.pdf_icon); } else { string key = _download.ImageKey; var uri = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl + "services/edicola_services.php?action=pubCover&zip=" + _download.RelativePath + "&img=copertina.jpg&key=" + key + "&app=" + DataManager.Get <ISettingsManager>().Settings.AppId); imgCover.Tag = uri.ToString(); //Koush.UrlImageViewHelper.SetUrlDrawable (imgCover, uri.AbsoluteUri); MBImageLoader.DisplayNetworkImage(uri, imgCover, new PointF(360, 360)); } if (_download.DataPubblicazione != DateTime.MinValue) { txtPubblicato.Text = string.Format(Context.GetString(Resource.String.pub_publishedOn), _download.DataPubblicazione.ToString("dd-MM-yyyy")); } else { txtPubblicato.Visibility = ViewStates.Gone; } if (_download.DataScadenza != DateTime.MinValue) { txtScadenza.Text = string.Format(Context.GetString(Resource.String.pub_expireOn), _download.DataScadenza.ToString("dd-MM-yyyy")); } else { txtScadenza.Visibility = ViewStates.Gone; } txtDimensione.Text = Utils.FormatBytes(_download.Dimensione); if (DataManager.Get <ISettingsManager>().Settings.InAppPurchase&& _download.IapID != "") { if (_download.IapAcquistato) { txtPrezzo.Text = string.Format(Context.GetString(Resource.String.iap_purchaseDate), _download.IapDataAcquisto.ToString("dd-MM-yyyy")); } } //pulsante apri btnOpen.SetTextColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.ButtonColor)); btnOpen.Text = Context.GetString(Resource.String.pub_open); btnOpen.Click += delegate { if (OpenAction != null) { OpenAction(); } }; //pulsante download btnDownload.SetTextColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.ButtonColor)); btnDownload.Text = Context.GetString(Resource.String.pub_download); btnDownload.Click += delegate { if (DownloadAction != null) { DownloadAction(); } }; //pulsante buy btnBuy.SetTextColor(Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.ButtonColor)); btnBuy.Text = _download.IapPrezzo; btnBuy.Click += delegate { if (BuyAction != null) { BuyAction(); } }; GradientDrawable gd = new GradientDrawable(); gd.SetColor(Color.Transparent.FromHex("ffffff")); gd.SetCornerRadius(5); gd.SetStroke(1, Color.Transparent.FromHex(DataManager.Get <ISettingsManager>().Settings.ButtonColor)); btnBuy.Background = gd; /*if(FileDownloader.IsWaiting(_download.Uri)) * { * _download.Stato = DownloadStato.Downloading; * }*/ DownloadInfo down = MBDownloadManager.DownloadInfo(_download.Uri.AbsoluteUri); if (down != null && (down.Status == DownloadStatus.Running || down.Status == DownloadStatus.Pending)) { _download.Stato = DownloadStato.Downloading; } //in base allo stato del download configuro i pulsanti switch (_download.Stato) { case DownloadStato.Download: btnDownload.Text = Context.GetString(Resource.String.pub_download); btnOpen.Visibility = ViewStates.Invisible; btnBuy.Visibility = ViewStates.Gone; btnBuy.Enabled = false; break; case DownloadStato.NoUpdate: btnDownload.Visibility = ViewStates.Invisible; btnOpen.Visibility = ViewStates.Visible; btnBuy.Visibility = ViewStates.Gone; btnBuy.Enabled = false; break; case DownloadStato.Update: btnDownload.Text = Context.GetString(Resource.String.down_update); btnOpen.Visibility = ViewStates.Visible; btnBuy.Visibility = ViewStates.Gone; btnBuy.Enabled = false; break; case DownloadStato.Downloading: btnDownload.Text = Context.GetString(Resource.String.down_wait); btnDownload.Enabled = false; btnOpen.Visibility = ViewStates.Invisible; btnBuy.Visibility = ViewStates.Gone; btnBuy.Enabled = false; break; case DownloadStato.Expired: btnDownload.Text = Context.GetString(Resource.String.pub_expired); btnDownload.Enabled = false; btnOpen.Visibility = ViewStates.Invisible; btnBuy.Visibility = ViewStates.Gone; btnBuy.Enabled = false; break; case DownloadStato.Buy: btnDownload.Visibility = ViewStates.Gone; btnDownload.Enabled = false; btnOpen.Visibility = ViewStates.Invisible; btnBuy.Visibility = ViewStates.Visible; btnBuy.Enabled = true; break; default: break; } }