async void UploadFile(string filePath)
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            dialog.SetCancelable(false);
            dialog.SetMessage("Uploading");
            dialog.Show();

            await Task.Run(() =>
            {
                var client = DropboxClientFactory.GetClient();

                filePath     = UriHelpers.GetFileForUri(this, filePath);
                var fileInfo = new System.IO.FileInfo(filePath);

                using (var stream = System.IO.File.OpenRead(filePath))
                {
                    var folderPath     = string.IsNullOrWhiteSpace(mPath) ? "/" : mPath;
                    var remoteFilePath = System.IO.Path.Combine(folderPath, fileInfo.Name);

                    client
                    .Files()
                    .UploadBuilder(remoteFilePath)
                    .WithMode(WriteMode.Overwrite)
                    .UploadAndFinish(stream);
                }
            });

            dialog.Dismiss();
            LoadData();
        }
Ejemplo n.º 2
0
        protected async override void LoadData()
        {
            var result = await Task.Run(() =>
            {
                var client = DropboxClientFactory.GetClient();

                return(client.Users().CurrentAccount);
            });

            ((TextView)FindViewById(Resource.Id.email_text)).Text = (result.Email);
            ((TextView)FindViewById(Resource.Id.name_text)).Text  = (result.Name.DisplayName);
            ((TextView)FindViewById(Resource.Id.type_text)).Text  = (result.AccountType.Name());
        }
        async void DownloadFile(FileMetadata metadata)
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            dialog.SetCancelable(false);
            dialog.SetMessage("Downloading");
            dialog.Show();

            var result = await Task.Run(() =>
            {
                var directory = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);

                //// Make sure the Downloads directory exists.
                if (!directory.Exists())
                {
                    if (!directory.Mkdirs())
                    {
                        return(null);
                    }

                    directory.Mkdir();
                }
                else if (!directory.IsDirectory)
                {
                    return(null);
                }

                var filePath = System.IO.Path.Combine(directory.Path, metadata.Name);

                using (var stream = System.IO.File.OpenWrite(filePath))
                {
                    DropboxClientFactory
                    .GetClient()
                    .Files()
                    .Download(metadata.PathLower, metadata.Rev)
                    .Download(stream);
                }

                //// Tell android about the file
                var fileUri   = Android.Net.Uri.Parse(filePath);
                Intent intent = new Intent(Intent.ActionMediaScannerScanFile);
                intent.SetData(fileUri);
                SendBroadcast(intent);

                return(fileUri);
            });

            dialog.Dismiss();
            ViewFileInExternalApp(metadata, result);
        }
        protected async override void LoadData()
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            dialog.SetCancelable(false);
            dialog.SetMessage("Loading");
            dialog.Show();

            var result = await Task.Run(() =>
            {
                var client = DropboxClientFactory.GetClient();

                return(client.Files().ListFolder(mPath));
            });

            dialog.Dismiss();
            mFilesAdapter.SetFiles(result.Entries);
        }
 void InitAndLoadData(String accessToken)
 {
     DropboxClientFactory.Init(accessToken);
     PicassoClient.Init(ApplicationContext, DropboxClientFactory.GetClient());
     LoadData();
 }