Beispiel #1
0
        public void StartDownload()
        {
            MBDownloadManager.RequestDownload(DownloadUri, this);

            this.DownloadStato = DownloadStato.Downloading;             //in download
            SetUIState();
        }
        private void ShowDownloadDialog()
        {
            var dialog = new AlertDialog.Builder(Activity);

            dialog.SetTitle(GetString(Resource.String.down_title));
            dialog.SetMessage(GetString(Resource.String.down_downAll));
            dialog.SetNegativeButton(GetString(Resource.String.gen_cancel), delegate { return; });
            dialog.SetPositiveButton(GetString(Resource.String.gen_download), delegate(object sender, DialogClickEventArgs e)
            {
                if (_Items == null)
                {
                    return;
                }

                foreach (var item in _Items)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    if (item.GetType() == typeof(Download))
                    {
                        Download down = (item as Download);

                        if (down.Stato == DownloadStato.Download || down.Stato == DownloadStato.Update)
                        {
                            MBDownloadManager.RequestDownload(down.Uri, new VoidNotify());
                        }
                    }
                }

                PopulateTable();
            });

            dialog.Create();
            dialog.Show().SetDivider();
        }
        private void ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var item = _Downloads[e.Position];

            MBDownloadManager.RequestDownload(item.Uri, new VoidNotify());

            item.Stato = DownloadStato.Downloading;

            //_ListView.Adapter = new SearchDownAdapter(this, _Downloads);

            var adapter = new SearchDownAdapter(this, _Downloads);

            adapter.OpenAction += (string p) => {
                Intent i = new Intent();
                i.SetClass(this, typeof(ViewerScreen));

                i.SetAction(Intent.ActionView);

                i.PutExtra("pubPath", p);
                this.StartActivityForResult(i, 0);
            };

            _ListView.Adapter = adapter;
        }
 public void Download(Uri uri)
 {
     MBDownloadManager.RequestDownload(uri, this);
 }
Beispiel #5
0
        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();
        }
        public void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            if (actionMode != null)
            {
                return;
            }

            var item = _Items[e.Position];

            if (item.GetType() == typeof(Download))
            {
                DownloadDetails dialog = new DownloadDetails(this.Activity, item as Download);

                dialog.OpenAction += () =>
                {
                    Intent i = new Intent();
                    i.SetClass(Activity, typeof(ViewerScreen));

                    i.SetAction(Intent.ActionView);

                    i.PutExtra("pubPath", (item as Download).GetLocalPath());
                    Activity.StartActivityForResult(i, 0);

                    dialog.Dismiss();
                };

                dialog.DownloadAction += () =>
                {
                    //var cell = ;
                    //var cell = _GridView.Adapter.get(e.Position);

                    //FileDownloader.DefaultRequestDownload((item as Download).Uri, new DownloadGridItem(Activity, (item as Download)));

                    Download down = (item as Download);
                    //MBDownloadManager.Download(down.Uri.AbsoluteUri, System.IO.Path.GetFileName(down.Uri.LocalPath), down.Titolo);
                    MBDownloadManager.RequestDownload(down.Uri, new VoidNotify());

                    this.PopulateTable();
                    dialog.Dismiss();
                };

                dialog.BuyAction += () =>
                {
                    Task.Run(
                        async() =>
                    {
                        if (!DownloadManager.IsLogged())
                        {
                            Action action = delegate {
                                PopulateTable();
                            };

                            ActivitiesBringe.SetObject("loginSuccess", action);

                            var logActivity = new Intent(Activity, typeof(LoginActivity));
                            StartActivity(logActivity);
                        }
                        else
                        {
                            Download down    = (item as Download);
                            List <string> id = new List <string>()
                            {
                                down.IapID
                            };
                            IReadOnlyList <Product> billProducts = await _billingHandler.QueryInventory(id, ItemType.Product);

                            if (billProducts != null)
                            {
                                var prod = billProducts.FirstOrDefault();
                                if (prod != null && prod.ProductId != null)
                                {
                                    Task billTask = BillProcess(prod);
                                }
                            }
                        }
                    }
                        );

                    dialog.Dismiss();
                };

                dialog.Show();
            }
            else if (item.GetType() == typeof(DownDir))
            {
                Console.WriteLine("click dir" + e.Position);

                DownDir dir = item as DownDir;

                _CurrentDir = dir.Path;
                PopulateTable();
            }
        }
        private async Task BillProcess(Product prod)
        {
            var result = await _billingHandler.BuyProduct(prod);

            var returnData = new Dictionary <string, string>();

            if (result.Result == BillingResult.OK)
            {
                if (result.Purchase != null && result.Data != null)
                {
                    string orderID = "";
                    if (result.Purchase.OrderId == null || result.Purchase.OrderId == "")
                    {
                        orderID = result.Purchase.PurchaseToken;
                    }

                    var data = new Dictionary <string, string>();
                    data.Add("packageName", Activity.PackageName);
                    data.Add("orderId", orderID);
                    data.Add("productId", result.Purchase.ProductId);
                    data.Add("developerPayload", result.Purchase.DeveloperPayload);
                    data.Add("purchaseTime", result.Purchase.PurchaseTime.ToString());
                    data.Add("purchaseToken", result.Purchase.PurchaseToken);
                    data.Add("purchaseState", result.Purchase.PurchaseState.ToString());

                    returnData = Notification.CheckRegisterPurchase(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data))));
                }
            }
            else if (result.Result == BillingResult.ItemAlreadyOwned)
            {
                var purch = await _billingHandler.GetPurchases(ItemType.Product);

                foreach (var p in purch)
                {
                    if (p.ProductId == prod.ProductId)
                    {
                        string orderID = "";
                        if (p.OrderId == null || p.OrderId == "")
                        {
                            orderID = p.PurchaseToken;
                        }

                        var data = new Dictionary <string, string>();
                        data.Add("packageName", Activity.PackageName);
                        data.Add("orderId", orderID);
                        data.Add("productId", p.ProductId);
                        data.Add("developerPayload", p.DeveloperPayload);
                        data.Add("purchaseTime", p.PurchaseTime.ToString());
                        data.Add("purchaseToken", p.PurchaseToken);
                        data.Add("purchaseState", p.PurchaseState.ToString());

                        returnData = Notification.CheckRegisterPurchase(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data))));

                        break;
                    }
                }
            }
            else if (result.Result == BillingResult.UserCancelled)
            {
            }
            else
            {
                returnData["success"]   = "false";
                returnData["errorCode"] = result.Result.ToString();
            }

            if (returnData["success"].ToLower() == "true")
            {
                var sub = _Abbonamenti.Where(d => d.IapID == prod.ProductId).FirstOrDefault();

                if (sub != null && sub.IapID != "") //abbonamento
                {
                    this.PopulateTable();
                }
                else //prodotto
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var uri = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl + "data/accounts/" + returnData["account"] + "/pub/" + returnData["path"]);
                        MBDownloadManager.RequestDownload(uri, new VoidNotify());

                        this.PopulateTable();
                    });
                }
            }
            else
            {
                string msgError = "";
                switch (returnData["errorCode"])
                {
                case "401":
                    msgError = Activity.GetString(Resource.String.iap_authenticationError);
                    break;

                case "403":
                    msgError = Activity.GetString(Resource.String.iap_unauthorizedUser);
                    break;

                case "402":
                    msgError = Activity.GetString(Resource.String.iap_transactionError);
                    break;

                case "503":
                    msgError = Activity.GetString(Resource.String.gen_tryLater);
                    break;

                case "505":
                    msgError = Activity.GetString(Resource.String.gen_tryLater);
                    break;
                }

                Activity.RunOnUiThread(() =>
                {
                    var alert = new AlertDialog.Builder(Activity);
                    alert.SetTitle(GetString(Resource.String.gen_error));

                    if (msgError != "")
                    {
                        alert.SetMessage(msgError + " [" + returnData["errorCode"] + "]");
                    }
                    else
                    {
                        alert.SetMessage("code: " + returnData["errorCode"]);
                    }

                    alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null);
                    alert.Show().SetDivider();
                });
            }
        }