mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-15 22:15:14 -05:00
Allow deliberate file pickers when browsing for existing files (OI still required for save as)
This commit is contained in:
parent
fa4cd5bf46
commit
f025b9cb3d
@ -614,7 +614,7 @@ namespace keepass2android
|
|||||||
case (int)Result.Ok:
|
case (int)Result.Ok:
|
||||||
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY)
|
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY)
|
||||||
{
|
{
|
||||||
String filename = data.DataString;
|
string filename = Util.IntentToFilename(data);
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
if (filename.StartsWith("file://")) {
|
if (filename.StartsWith("file://")) {
|
||||||
filename = filename.Substring(7);
|
filename = filename.Substring(7);
|
||||||
@ -666,7 +666,7 @@ namespace keepass2android
|
|||||||
addBinaryButton.SetCompoundDrawablesWithIntrinsicBounds( Resources.GetDrawable(Android.Resource.Drawable.IcMenuAdd) , null, null, null);
|
addBinaryButton.SetCompoundDrawablesWithIntrinsicBounds( Resources.GetDrawable(Android.Resource.Drawable.IcMenuAdd) , null, null, null);
|
||||||
addBinaryButton.Click += (object sender, EventArgs e) =>
|
addBinaryButton.Click += (object sender, EventArgs e) =>
|
||||||
{
|
{
|
||||||
Util.showBrowseDialog("/mnt/sdcard", this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY);
|
Util.showBrowseDialog("/mnt/sdcard", this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_BINARY, false);
|
||||||
|
|
||||||
};
|
};
|
||||||
binariesGroup.AddView(addBinaryButton,layoutParams);
|
binariesGroup.AddView(addBinaryButton,layoutParams);
|
||||||
|
@ -267,7 +267,7 @@ namespace keepass2android
|
|||||||
break;
|
break;
|
||||||
case Android.App.Result.Ok:
|
case Android.App.Result.Ok:
|
||||||
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE) {
|
if (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE) {
|
||||||
String filename = data.DataString;
|
string filename = Util.IntentToFilename(data);
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
if (filename.StartsWith("file://")) {
|
if (filename.StartsWith("file://")) {
|
||||||
filename = filename.Substring(7);
|
filename = filename.Substring(7);
|
||||||
@ -431,33 +431,17 @@ namespace keepass2android
|
|||||||
ImageButton browse = (ImageButton)FindViewById(Resource.Id.browse_button);
|
ImageButton browse = (ImageButton)FindViewById(Resource.Id.browse_button);
|
||||||
browse.Click += (object sender, EventArgs evt) =>
|
browse.Click += (object sender, EventArgs evt) =>
|
||||||
{
|
{
|
||||||
if (Interaction.isIntentAvailable(this, Intents.FILE_BROWSE))
|
string filename = null;
|
||||||
{
|
|
||||||
Intent intent = new Intent(Intents.FILE_BROWSE);
|
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(mIoConnection.Path))
|
if (!String.IsNullOrEmpty(mIoConnection.Path))
|
||||||
{
|
{
|
||||||
File keyfile = new File(mIoConnection.Path);
|
File keyfile = new File(mIoConnection.Path);
|
||||||
File parent = keyfile.ParentFile;
|
File parent = keyfile.ParentFile;
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
intent.SetData(Android.Net.Uri.Parse("file://" + parent.AbsolutePath));
|
filename = parent.AbsolutePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Util.showBrowseDialog(filename, this, Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE, false);
|
||||||
try
|
|
||||||
{
|
|
||||||
StartActivityForResult(intent, Intents.REQUEST_CODE_FILE_BROWSE_FOR_KEYFILE);
|
|
||||||
} catch (ActivityNotFoundException)
|
|
||||||
{
|
|
||||||
BrowserDialog diag = new BrowserDialog(this);
|
|
||||||
diag.Show();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
BrowserDialog diag = new BrowserDialog(this);
|
|
||||||
diag.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,11 +88,19 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void showBrowseDialog(string filename, Activity act, int requestCodeBrowse)
|
public static void showBrowseDialog(string filename, Activity act, int requestCodeBrowse, bool forSaving)
|
||||||
{
|
{
|
||||||
|
if ((!forSaving) && (Interaction.isIntentAvailable(act, Intent.ActionGetContent))) {
|
||||||
|
Intent i = new Intent(Intent.ActionGetContent);
|
||||||
|
i.SetType("file/*");
|
||||||
|
|
||||||
|
act.StartActivityForResult(i, requestCodeBrowse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Interaction.isIntentAvailable(act, Intents.FILE_BROWSE))
|
if (Interaction.isIntentAvailable(act, Intents.FILE_BROWSE))
|
||||||
{
|
{
|
||||||
Intent i = new Intent(Intents.FILE_BROWSE);
|
Intent i = new Intent(Intents.FILE_BROWSE);
|
||||||
|
if (filename != null)
|
||||||
i.SetData(Android.Net.Uri.Parse("file://" + filename));
|
i.SetData(Android.Net.Uri.Parse("file://" + filename));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -111,6 +119,14 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string IntentToFilename(Intent data)
|
||||||
|
{
|
||||||
|
String filename = data.Data.Path;
|
||||||
|
if (String.IsNullOrEmpty(filename))
|
||||||
|
filename = data.DataString;
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ namespace keepass2android
|
|||||||
browseButton.Click += (sender, evt) => {
|
browseButton.Click += (sender, evt) => {
|
||||||
string filename = ((EditText)dialog.FindViewById(Resource.Id.file_filename)).Text;
|
string filename = ((EditText)dialog.FindViewById(Resource.Id.file_filename)).Text;
|
||||||
|
|
||||||
Util.showBrowseDialog(filename, this, requestCodeBrowse);
|
Util.showBrowseDialog(filename, this, requestCodeBrowse, showCreateButton);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -415,6 +415,8 @@ namespace keepass2android
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
||||||
{
|
{
|
||||||
base.OnActivityResult(requestCode, resultCode, data);
|
base.OnActivityResult(requestCode, resultCode, data);
|
||||||
@ -432,7 +434,7 @@ namespace keepass2android
|
|||||||
if ( (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_CREATE
|
if ( (requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_CREATE
|
||||||
|| requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_OPEN)
|
|| requestCode == Intents.REQUEST_CODE_FILE_BROWSE_FOR_OPEN)
|
||||||
&& resultCode == Result.Ok) {
|
&& resultCode == Result.Ok) {
|
||||||
String filename = data.DataString;
|
string filename = Util.IntentToFilename(data);
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
if (filename.StartsWith("file://")) {
|
if (filename.StartsWith("file://")) {
|
||||||
filename = filename.Substring(7);
|
filename = filename.Substring(7);
|
||||||
|
Loading…
Reference in New Issue
Block a user