void listViewItemClick(object sender, AdapterView.ItemClickEventArgs e) { alertDialog.Hide(); if (filesFolders.Count > 0) { CloudMetaData metaData = filesFolders[dataPosition]; if (e.Position == 0) { if (metaData.Folder) { Toast.MakeText(this, "Can only download files", ToastLength.Short).Show(); } else { DownloadFile(metaData); } } else if (e.Position == 1) { ShareLink(metaData); } else if (e.Position == 2) { DeleteFileFolder(metaData); } } }
//Delete file at Path - Delete(path) method used private void DeleteFileFolder(CloudMetaData metaData) { new System.Threading.Thread(new System.Threading.ThreadStart(() => { try { service.Delete(metaData.Path); RunOnUiThread(() => { Toast.MakeText(this, "File Delete", ToastLength.Short).Show(); this.GetChildrenAtPath("/"); }); } catch (Exception e) { Console.WriteLine(e.Message); } })).Start(); }
//Create Share Link for file/folder at Path - CreateShareLink(path) method used private void ShareLink(CloudMetaData metaData) { new System.Threading.Thread(new System.Threading.ThreadStart(() => { try { string shareLink = service.CreateShareLink(metaData.Path); RunOnUiThread(() => { ClipboardManager clipboard = (ClipboardManager)this.GetSystemService(Context.ClipboardService); ClipData clip = ClipData.NewPlainText("Sharable Link", shareLink); clipboard.PrimaryClip = clip; Toast.MakeText(this, "Copied link to clipboard\n" + shareLink, ToastLength.Long).Show(); }); } catch (Exception e) { Console.WriteLine(e.Message); } })).Start(); }
//Download file at Path - GetChildren(path) method used private void DownloadFile(CloudMetaData metaData) { new System.Threading.Thread(new System.Threading.ThreadStart(() => { try { string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string localFilename = metaData.Name; string localPath = System.IO.Path.Combine(documentsPath, localFilename); System.IO.Stream stream = service.Download(metaData.Path); System.IO.File.WriteAllBytes(localPath, ReadFully(stream)); RunOnUiThread(() => { Toast.MakeText(this, "File " + metaData.Name + " downloaded", ToastLength.Long).Show(); }); } catch (Exception e) { Console.WriteLine(e.Message); } })).Start(); }