コード例 #1
0
        public void Download(IOListing io, Action <ResultState> complete)
        {
            this.AssurePath(io.FullPath);

            var dm = (DownloadManager)this.context.Activity.GetSystemService(Context.DownloadService);

            var uri = Android.Net.Uri.Parse(io.Url);

            var encodedUri = io.Url.Replace(uri.Path, Android.Net.Uri.Encode(uri.Path).Replace("%2F", "/"));

            var req = new DownloadManager.Request(Android.Net.Uri.Parse(encodedUri));

            var path = this.Map(io.FullPath);

            req.AllowScanningByMediaScanner();
            req.SetDestinationUri(Android.Net.Uri.FromFile(new File(path)));
            req.SetTitle(io.Name);

            var downlaodId = dm.Enqueue(req);

            Action <ResultState> action = state =>
            {
                complete.Invoke(state);
            };

            this.context.Activity.RegisterReceiver(
                new DownloadCompleteReceiver(action, downlaodId, this.userInteraction),
                new IntentFilter(DownloadManager.ActionDownloadComplete));
        }
コード例 #2
0
        public async void Download(IOListing io, Action <ResultState> complete)
        {
            var webClient = new NativeHttpClient(this.httpClientConfiguration);

            webClient
            .AssignAgent(this.device);

            var stream = await webClient.GetStreamAsync(io.Url);

            await this.WriteFileAsync(this.Map(io.FullPath), stream);

            complete.Invoke(ResultState.Success);
        }
コード例 #3
0
        public void LoadListing(IOListing io)
        {
            if (io == null)
            {
                return;
            }

            if (io.IsDirectory)
            {
                this.Navigate <FilerViewModel, FilerArgs>(new FilerArgs {
                    CurrentDirectory = io.FullPath
                });
            }
            else if (io.IsLocal)
            {
                this.storageService.StartOpenFile(io.FullPath);
            }
            else
            {
                if (this.IsDownloading)
                {
                    return;
                }

                this.IsDownloading = true;
                this.storageService.Download(io, state =>
                {
                    if (state == ResultState.Success)
                    {
                        this.Dispatcher.RequestMainThreadAction(() =>
                                                                this.Listings.Single(t => t.FullPath == io.FullPath).IsLocal = true);
                        this.RaisePropertyChanged(nameof(this.Listings));
                        this.storageService.StartOpenFile(io.FullPath);
                    }

                    this.IsDownloading = false;
                });
            }
        }