public static BaseItemView Create (CGRect frame, NodeViewController nodeViewController, TreeNode node, UIColor kleur) { var view = (BaseItemView)Nib.Instantiate (null, null) [0]; view.Frame = frame; view.Node = node; view.NodePath = node.Path; view.SetShadow(); view.TerugButton.TouchUpInside += delegate { nodeViewController.PopView(); }; view.TitelLabel.Text = node.Name; view.TitelLabel.SetFont(); view.FullScreenButton.TouchUpInside += delegate { nodeViewController.ToggleFullScreen(); }; if (kleur != null) { view.kleurenBalk.BackgroundColor = kleur; } view.HideBackButton(); return view; }
public static BaseItemView Create (CGRect frame, NodeViewController nodeViewController, TreeNode node, string filePath, UIColor kleur) { var view = BaseItemView.Create(frame, nodeViewController, node, kleur); UIWebView webView = new UIWebView(); string extension = Path.GetExtension (filePath); if (extension == ".odt") { string viewerPath = NSBundle.MainBundle.PathForResource ("over/viewer/index", "html"); Uri fromUri = new Uri(viewerPath); Uri toUri = new Uri(filePath); Uri relativeUri = fromUri.MakeRelativeUri(toUri); String relativePath = Uri.UnescapeDataString(relativeUri.ToString()); NSUrl finalUrl = new NSUrl ("#" + relativePath.Replace(" ", "%20"), new NSUrl(viewerPath, false)); webView.LoadRequest(new NSUrlRequest(finalUrl)); webView.ScalesPageToFit = true; view.ContentView = webView; return view; } else { NSUrl finalUrl = new NSUrl (filePath, false); webView.LoadRequest(new NSUrlRequest(finalUrl)); webView.ScalesPageToFit = true; view.ContentView = webView; return view; } }
public MoveFileFragment(List<TreeNode> foundDirectoryTreeNodes, TreeNode treeNodeToMove, HomeActivity parentActivity) { this.foundDirectoryTreeNodes = foundDirectoryTreeNodes; this.treeNodeToMove = treeNodeToMove; this.parentActivity = parentActivity; selectedTreeNodes = new List<TreeNode> (); }
private bool IsShare(TreeNode node){ if (node.Path.Count(e => e == '/') > 1) { var path = node.Path; int index = path.IndexOf('/', path.IndexOf('/') + 1); var rootFolder = path.Substring(0, index); var folder = DataLayer.Instance.GetFolder(rootFolder).Result; return folder.IsShare; } else return node.IsShare; }
//Default constructor for explorer public ExplorerFragment (TreeNode foundTreeNode, HomeActivity homeActivity) { foundTreeNodeChildren = foundTreeNode.Children; this.parentActivity = homeActivity; //Add favorite list item in root listview of local box if (openedDirectories.Count == 0) { foundTreeNodeChildren.Insert (0, new TreeNode (){ Name = "Lokale favorieten", Type = "favorite" }); } this.currentTreeNodePath = foundTreeNode.Path; favoriteFolderOpened = false; }
public void ShowNode(TreeNode treeNode, BaseNode sender) { if (_nodes.Last().Node != null && treeNode.Id == _nodes.Last().Node.Id) return; int idx = _nodes.IndexOf(sender); if (sender != _nodes.Last()) { _nodes.RemoveRange(idx + 1, _nodes.Count - idx - 1); } if (treeNode.IsDirectory) { try{ var node = NodeView.Create(new CGRect(View.Frame.Width, 0, width, View.Frame.Height), this, treeNode.Path, _balkKleur); node.Layer.ZPosition = 10; _nodes.Add(node); Add(node); AnimateViews(); } catch (Exception ex){ Insights.Report(ex); DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij het openen van de map.\n" + "Ververs de huidige map en probeer het a.u.b. nogmaals."); } } else { string filePath = string.Empty; InvokeOnMainThread(() => DialogHelper.ShowProgressDialog("Bestand downloaden", "Bezig met het downloaden van een bestand", () => filePath = DataLayer.Instance.GetFilePathSync(treeNode.Path), ()=> { try{ var item = WebItemView.Create(new CGRect(View.Frame.Width, 0, width, View.Frame.Height), this, treeNode, filePath, _balkKleur); item.Layer.ZPosition = 10; _nodes.Add(item); Add(item); AnimateViews(); } catch (Exception ex){ Insights.Report(ex); DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij het openen van het bestand." + "\nVervers a.u.b. de map en probeer het opnieuw."); } }) ); } }
public async void ShowMoveFileDialog(TreeNode treeNodeToMove) { Console.WriteLine ("Bestand om te verplaatsen: " + treeNodeToMove.Name); homeActivity.ShowProgressDialog (null); try { Android.App.FragmentTransaction fragmentTransaction; fragmentTransaction = homeActivity.FragmentManager.BeginTransaction (); List<TreeNode>foundDirectoryTreeNodes = new List<TreeNode>(); TreeNode rootTreeNode = await DataLayer.Instance.GetFolder ("/"); foreach(TreeNode foundTreeNode in rootTreeNode.Children) { if(foundTreeNode.IsDirectory) { foundDirectoryTreeNodes.Add(foundTreeNode); } } MoveFileFragment moveFileFragment = new MoveFileFragment(foundDirectoryTreeNodes, treeNodeToMove, homeActivity); homeActivity.dialogFragmentMoveFile = moveFileFragment; homeActivity.HideProgressDialog (); if (foundDirectoryTreeNodes.Count > 0) { homeActivity.dialogFragmentMoveFile.Show (fragmentTransaction, "movefiledialog"); } else { homeActivity.ShowToast("Geen mappen gevonden om bestand naar te verplaatsen"); } } catch (Exception ex){ Insights.Report(ex); homeActivity.HideProgressDialog (); homeActivity.ShowToast ("Er is iets fout gegaan bij het ophalen van mappen. \nProbeer het a.u.b. opnieuw"); } }
private async void UnFavoriteFile (TreeNode selectedItem) { try { popupWindow.Dismiss (); parentActivity.ShowProgressDialog ("Bestanden verwijderen uit favorieten"); bool unFavoriteSucceed = await DataLayer.Instance.UnFavoriteFile (selectedItem); if (!unFavoriteSucceed) { Toast.MakeText (Android.App.Application.Context, "Mislukt om bestand uit favorieten te verwijderen", ToastLength.Short).Show (); } else { Toast.MakeText (Android.App.Application.Context, "Bestand succesvol uit favorieten verwijderd", ToastLength.Short).Show (); } parentActivity.HideProgressDialog (); //Refresh listview int numberOfDirectoriesOpened = ExplorerFragment.openedDirectories.Count; if(numberOfDirectoriesOpened >= 1){ if(ExplorerFragment.openedDirectories [numberOfDirectoriesOpened - 1] != null){ //Favorite folder niet geopend RefreshData(); }else{ //Favorite folder opened so refresh favorite list List<TreeNode> favorites = DataLayer.Instance.GetFavorites (); explorerAdapter = new ExplorerAdapter (Activity, favorites, false); ListAdapter = explorerAdapter; //UPDATE UI Activity.RunOnUiThread(new Action(()=> { explorerAdapter.NotifyDataSetChanged(); explorerListView.InvalidateViews(); })); } } else { RefreshData(); } } catch (Exception ex){ Insights.Report(ex); parentActivity.HideProgressDialog (); Toast.MakeText (Android.App.Application.Context, "Mislukt om bestand uit favorieten te verwijderen", ToastLength.Short).Show (); } }
private async void FavoriteFile (TreeNode selectedItem) { try { popupWindow.Dismiss (); parentActivity.ShowProgressDialog ("Bestand toevoegen aan favorieten"); bool favoriteSucceed = await DataLayer.Instance.FavoriteFile (selectedItem); if (!favoriteSucceed) { Toast.MakeText (Android.App.Application.Context, "Favoriet maken mislukt", ToastLength.Short).Show (); } else { Toast.MakeText (Android.App.Application.Context, "Bestand succesvol favoriet gemaakt", ToastLength.Short).Show (); } parentActivity.HideProgressDialog (); //Refresh listview RefreshData (); } catch (Exception ex){ Insights.Report(ex); parentActivity.HideProgressDialog (); Toast.MakeText (Android.App.Application.Context, "Favoriet maken mislukt", ToastLength.Short).Show (); } }
public static bool IsInRootNode(TreeNode node) { return IsInRootNode(node.Path); }
private void UpdateFolderKey(TreeNode node) { // alleen keys ophalen als het nog niet eerder is gedaan en het op een map op het rootniveau is. if (!node.CheckedForKeys && node.Path.Count(e => e == '/') == 1 && node.Path.Length > 1) { var explorer = new RemoteExplorer(); AesKeyResponse response; if (explorer.GetAesKey(node.Path, out response)) { if (response != null && response.IV != null && response.Key != null) { var encryptedIV = Convert.FromBase64String(response.IV); var encryptedKey = Convert.FromBase64String(response.Key); var box = GetSelectedOrDefaultBox(); node.Key = CryptoHelper.DecryptPgp(encryptedKey, box.PrivateKey, box.PassPhrase); node.IV = CryptoHelper.DecryptPgp(encryptedIV, box.PrivateKey, box.PassPhrase); } node.CheckedForKeys = true; database.Update(node); } } }
void DeleteLocalFileOrFolder(TreeNode e) { DeleteLocalFileOrFolder(e.Path); }
public bool NodeExists(TreeNode node) { return database.NodeExist(node); }
public Task<bool> UnFavoriteFile(TreeNode treeNodeToUnFavorite) { return Task.Run(() => { bool updateSucceeded = false; if (treeNodeToUnFavorite.IsFavorite) { treeNodeToUnFavorite.IsFavorite = false; database.UpdateNode (treeNodeToUnFavorite); updateSucceeded = true; } else { updateSucceeded = false; } return updateSucceeded; }); }
public Task<bool> FavoriteFile(TreeNode treeNodeToFavorite) { return Task.Run(async () => { bool updateSucceeded = false; if (!treeNodeToFavorite.IsDirectory) { treeNodeToFavorite.IsFavorite = true; database.UpdateNode (treeNodeToFavorite); await GetFilePath(treeNodeToFavorite.Path); updateSucceeded = true; } else { updateSucceeded = false; } return updateSucceeded; }); }
private List<TreeNode> MapDataGroupToTreeNode(DataGroup dg, int parent, int boxId) { List<TreeNode> result = new List<TreeNode>(); if (dg.Items != null) { foreach (DataItem di in dg.Items) { var newNode = new TreeNode() { Name = di.Title, Type = di.FileType, Path = di.Path, IsDirectory = di.IsFolder, ParentId = parent, IsShare = di.Share, IsShared = di.Shared, IsWritable = di.IsWritable, LocalBoxId = boxId, HasKeys = di.HasKeys }; result.Add(newNode); } } return result; }
public NodeViewSource (TreeNode node, NodeViewController nodeViewController, NodeView nodeView) { _node = node; _nodeViewController = nodeViewController; _nodeView = nodeView; _root = _node.ParentId == 0; }
private void ClickHandlersFilePopupMenu (View popupView, TreeNode selectedItem) { ImageButton buttonFileOpenIn = (ImageButton)popupView.FindViewById (Resource.Id.button_popup_file_openin); buttonFileOpenIn.Click += delegate { OpenFileIn (selectedItem); }; ImageButton buttonFavoriteFile = (ImageButton)popupView.FindViewById (Resource.Id.button_popup_file_favorite); buttonFavoriteFile.Click += delegate { if(selectedItem.IsFavorite){ UnFavoriteFile (selectedItem); } else{ FavoriteFile (selectedItem); } }; ImageButton buttonMoveFile = (ImageButton)popupView.FindViewById (Resource.Id.button_popup_file_move); ImageButton buttonDeleteFile = (ImageButton)popupView.FindViewById (Resource.Id.button_popup_file_delete); if (!selectedItem.IsWritable) { buttonMoveFile.Visibility = ViewStates.Invisible; buttonDeleteFile.Visibility = ViewStates.Invisible; } else { if (!favoriteFolderOpened) { buttonMoveFile.Click += delegate { popupWindow.Dismiss(); parentActivity.ShowMoveFileDialog(selectedItem); }; buttonDeleteFile.Click += delegate { if (selectedItem.Id == lastShownTreeNodeId) {//Document is geopend in document fragment, dus deze resetten parentActivity.ClearContentInDocumentFragment (); } DeleteFolderOrFile (selectedItem.Path); }; } } }
public Task<TreeNode> GetFolder(string path, bool refresh = false) { return Task.Run(() => { if (refresh) { RefreshFolder(path); } var result = database.GetTree(path); if (result != null && result.Children.Count == 0) { RefreshFolder(path); result = database.GetTree(path); UpdateFolderKey(result); } else // root is null { if(result == null && (path.Equals("/") || path.Equals(""))) { int boxId = Waardes.Instance.GeselecteerdeBox; var node = new TreeNode(){ Name = "Root", Path = "/", ParentId = 0, IsDirectory = true, LocalBoxId = boxId }; database.AddNode(node); //Create unencrypted public folder in empty root directory var explorer = new RemoteExplorer(); string nameOfUser = explorer.GetUser().Name; CreateFolder("/Publiek - " + nameOfUser, false); RefreshFolder(node.Path); result = database.GetTree(path); } } return result; }); }
private void ClickHandlersFolderSubFolderPopupMenu (View popupView, TreeNode selectedItem) { ImageButton buttonDeleteFolder = (ImageButton)popupView.FindViewById (Resource.Id.button_popup_folder_subfolder_delete); if (!selectedItem.IsWritable) { buttonDeleteFolder.Visibility = ViewStates.Invisible; } else { buttonDeleteFolder.Click += delegate { DeleteFolderOrFile (selectedItem.Path); }; } }
private async void OpenFileIn (TreeNode clickedItem) { try { if (popupWindow != null) { popupWindow.Dismiss (); } string mimeTypeOfClickedItem = MimeTypeHelper.GetMimeType (clickedItem.Path); clickedItem.Type = mimeTypeOfClickedItem; if (clickedItem.Type.Equals ("application/pdf")) { Intent intent = new Intent (Intent.ActionView); new Thread (new ThreadStart (async delegate { //Show progress dialog while loading parentActivity.HideProgressDialog (); parentActivity.ShowProgressDialog (null); string fullFilePath = await DataLayer.Instance.GetFilePath (clickedItem.Path); //Controleer internet verbinding var connectivityManager = (ConnectivityManager)Android.App.Application.Context.GetSystemService (Context.ConnectivityService); var activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { //Internet verbinding gedetecteerd //Create temp file string temporaryFilePath = System.IO.Path.Combine ("/storage/emulated/0/Download", clickedItem.Name); if (File.Exists (temporaryFilePath)) { File.Delete (temporaryFilePath); } //Save settings of last opened file ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (Activity); ISharedPreferencesEditor editor = prefs.Edit (); editor.PutString ("fileNameLastOpenedPdf", clickedItem.Name); editor.PutString ("pathLastOpenedPdf", clickedItem.Path); editor.PutString ("temporaryFilePath", temporaryFilePath); editor.PutBoolean ("isFavorite", clickedItem.IsFavorite); editor.Commit (); //Save temporary file in filesystem Byte[] fileBytes = File.ReadAllBytes (fullFilePath); File.WriteAllBytes (temporaryFilePath, fileBytes); Android.Net.Uri uri = Android.Net.Uri.Parse ("file://" + temporaryFilePath); intent.SetDataAndType (uri, clickedItem.Type); parentActivity.HideProgressDialog (); if(File.Exists (temporaryFilePath)){ Activity.StartActivity (intent); } else { Toast.MakeText (Android.App.Application.Context, "Openen bestand mislukt", ToastLength.Long).Show (); } } else { //Geen internet verbinding var alertDialogConfirmDelete = new Android.App.AlertDialog.Builder (Activity); alertDialogConfirmDelete.SetTitle ("Geen verbinding"); alertDialogConfirmDelete.SetMessage ("U heeft momenteel geen internet verbinding. Het maken van PDF annotaties is daarom niet mogelijk."); alertDialogConfirmDelete.SetPositiveButton ("OK", async delegate { Android.Net.Uri uri = Android.Net.Uri.Parse ("file://" + fullFilePath); intent.SetDataAndType (uri, clickedItem.Type); parentActivity.HideProgressDialog (); Activity.StartActivity (intent); }); alertDialogConfirmDelete.Create ().Show (); } })).Start (); } else {//Ander bestandstype dan PDF openen //Show progress dialog while loading parentActivity.HideProgressDialog (); parentActivity.ShowProgressDialog (null); string fullFilePath = await DataLayer.Instance.GetFilePath (clickedItem.Path); Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse (CustomContentProvider.CONTENT_URI + fullFilePath)); intent.SetFlags (ActivityFlags.GrantReadUriPermission); intent.SetFlags (ActivityFlags.NewTask); intent.SetFlags (ActivityFlags.ClearWhenTaskReset); Activity.StartActivity (intent); } } catch (Exception ex){ Insights.Report(ex); Console.WriteLine (ex.Message); parentActivity.HideProgressDialog (); if (ex is ActivityNotFoundException) { Toast.MakeText (Android.App.Application.Context, "Geen app op uw apparaat gevonden om dit bestandstype te kunnen openen", ToastLength.Long).Show (); } else { Toast.MakeText (Android.App.Application.Context, "Openen bestand mislukt", ToastLength.Long).Show (); } } }
public bool IsEncrypted(TreeNode node) { if (node.Path.Count(e => e == '/') > 1) { var path = node.Path; int index = path.IndexOf('/', path.IndexOf('/') + 1); var rootFolder = path.Substring(0, index); var folder = DataLayer.Instance.GetFolder(rootFolder).Result; return folder.HasKeys; } else return node.HasKeys; }
public void ShowMoveFileDialog(TreeNode treeNodeToMove) { dialogHelper.ShowMoveFileDialog (treeNodeToMove); }