From 7378e19f998495384ea8d1602d0f00e4a8f82e49 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Wed, 30 Nov 2016 05:50:38 +0100 Subject: [PATCH] add better support for OwnCloud (less typing required when selecting a file) --- src/Kp2aBusinessLogic/Io/JavaFileStorage.cs | 2 +- src/keepass2android/FileSelectHelper.cs | 34 +++++++++++++++++++ .../Resources/values/strings.xml | 7 +++- src/keepass2android/keepass2android.csproj | 3 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Kp2aBusinessLogic/Io/JavaFileStorage.cs b/src/Kp2aBusinessLogic/Io/JavaFileStorage.cs index da4dbfb2..a7173d26 100644 --- a/src/Kp2aBusinessLogic/Io/JavaFileStorage.cs +++ b/src/Kp2aBusinessLogic/Io/JavaFileStorage.cs @@ -252,7 +252,7 @@ namespace keepass2android.Io return _jfs.RequiresSetup(IocToPath(ioConnection)); } - public void StartSelectFile(IFileStorageSetupInitiatorActivity activity, bool isForSave, int requestCode, string protocolId) + public virtual void StartSelectFile(IFileStorageSetupInitiatorActivity activity, bool isForSave, int requestCode, string protocolId) { Kp2aLog.Log("StartSelectFile " + protocolId); _jfs.StartSelectFile((IJavaFileStorageFileStorageSetupInitiatorActivity) activity, isForSave, requestCode); diff --git a/src/keepass2android/FileSelectHelper.cs b/src/keepass2android/FileSelectHelper.cs index 0fb32944..ad86e40e 100644 --- a/src/keepass2android/FileSelectHelper.cs +++ b/src/keepass2android/FileSelectHelper.cs @@ -136,6 +136,8 @@ namespace keepass2android ShowFtpDialog(_activity, ReturnFileOrStartFileChooser, ReturnCancel); else if ((defaultPath.StartsWith("http://")) || (defaultPath.StartsWith("https://"))) ShowHttpDialog(_activity, ReturnFileOrStartFileChooser, ReturnCancel, defaultPath); + else if (defaultPath.StartsWith("owncloud://")) + ShowOwncloudDialog(_activity, ReturnFileOrStartFileChooser, ReturnCancel, defaultPath); else { Func onOpen = OnOpenButton; @@ -151,6 +153,38 @@ namespace keepass2android } } + private void ShowOwncloudDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel, string defaultPath) + { +#if !EXCLUDE_JAVAFILESTORAGE && !NoNet + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.owncloudcredentials, null); + builder.SetView(dlgContents); + builder.SetPositiveButton(Android.Resource.String.Ok, + (sender, args) => + { + string host = dlgContents.FindViewById(Resource.Id.owncloud_url).Text; + + string user = dlgContents.FindViewById(Resource.Id.http_user).Text; + string password = dlgContents.FindViewById(Resource.Id.http_password).Text; + + string scheme = defaultPath.Substring(defaultPath.IndexOf("://", StringComparison.Ordinal)); + if (host.Contains("://") == false) + host = scheme + "://" + host; + string httpPath = new Keepass2android.Javafilestorage.WebDavStorage(null).BuildFullPath(WebDavFileStorage.Owncloud2Webdav(host), user, + password); + onStartBrowse(httpPath); + }); + EventHandler evtH = new EventHandler((sender, e) => onCancel()); + + builder.SetNegativeButton(Android.Resource.String.Cancel, evtH); + builder.SetTitle(activity.GetString(Resource.String.enter_owncloud_login_title)); + Dialog dialog = builder.Create(); + + dialog.Show(); +#endif + + } + private bool ReturnFileOrStartFileChooser(string filename) { int lastSlashPos = filename.LastIndexOf('/'); diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index a87b4e57..fd1524da 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -474,6 +474,10 @@ Enter WebDav login data: URL of folder or file (ex: mycloud.me.com/webdav/) + + Enter OwnCloud login data: + OwnCloud URL (ex: owncloud.me.com) + host (ex: 192.168.0.1) port Initial directory (optional): @@ -491,7 +495,8 @@ FTP HTTP (WebDav) HTTPS (WebDav) - Dropbox + OwnCloud + Dropbox Dropbox (KP2A folder) If you do not want to give KP2A access to your full Dropbox, you may select this option. It will request only access to the folder Apps/Keepass2Android. This is especially suited when creating a new database. If you already have a database, click this option to create the folder, then place your file inside the folder (from your PC) and then select this option again for opening the file. Google Drive diff --git a/src/keepass2android/keepass2android.csproj b/src/keepass2android/keepass2android.csproj index edf04db7..70254f8e 100644 --- a/src/keepass2android/keepass2android.csproj +++ b/src/keepass2android/keepass2android.csproj @@ -1706,6 +1706,9 @@ Designer + + +