mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-29 04:22:22 -05:00
FileSelectActivity is only shown when necessary or when explicitly selected by user
This commit is contained in:
parent
3b1b10385f
commit
eaa426db33
@ -24,6 +24,7 @@ using Android.Preferences;
|
||||
using Android.Content.PM;
|
||||
using Android.Text;
|
||||
using Android.Text.Method;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
{
|
||||
@ -103,7 +104,7 @@ namespace keepass2android
|
||||
Dialog dialog = builder.Create();
|
||||
dialog.DismissEvent += (sender, e) =>
|
||||
{
|
||||
StartFileSelect();
|
||||
LaunchNextActivity();
|
||||
};
|
||||
dialog.Show();
|
||||
TextView message = (TextView) dialog.FindViewById(Android.Resource.Id.Message);
|
||||
@ -116,7 +117,7 @@ namespace keepass2android
|
||||
|
||||
} else
|
||||
{
|
||||
StartFileSelect();
|
||||
LaunchNextActivity();
|
||||
}
|
||||
|
||||
|
||||
@ -154,12 +155,42 @@ namespace keepass2android
|
||||
|
||||
}
|
||||
|
||||
private void StartFileSelect() {
|
||||
Intent intent = new Intent(this, typeof(FileSelectActivity));
|
||||
//TEST Intent intent = new Intent(this, typeof(EntryActivity));
|
||||
//Intent intent = new Intent(this, typeof(SearchActivity));
|
||||
//Intent intent = new Intent(this, typeof(QuickUnlock));
|
||||
IOConnectionInfo LoadIoc(string defaultFileName)
|
||||
{
|
||||
return App.Kp2a.FileDbHelper.CursorToIoc(App.Kp2a.FileDbHelper.FetchFileByName(defaultFileName));
|
||||
}
|
||||
|
||||
private void LaunchNextActivity() {
|
||||
|
||||
if (!App.Kp2a.GetDb().Loaded)
|
||||
{
|
||||
// Load default database
|
||||
ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);
|
||||
String defaultFileName = prefs.GetString(PasswordActivity.KeyDefaultFilename, "");
|
||||
|
||||
if (defaultFileName.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
PasswordActivity.Launch(this, LoadIoc(defaultFileName), _appTask);
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Toast.MakeText(this, e.Message, ToastLength.Long);
|
||||
// Ignore exception
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PasswordActivity.Launch(this, App.Kp2a.GetDb().Ioc, _appTask);
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, typeof(FileSelectActivity));
|
||||
_appTask.ToIntent(intent);
|
||||
|
||||
|
||||
|
@ -291,6 +291,8 @@ namespace keepass2android
|
||||
LoadDb task = new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, pass, key, new AfterLoad(handler, this));
|
||||
_loadDbTask = null; // prevent accidental re-use
|
||||
|
||||
SetNewDefaultFile();
|
||||
|
||||
new ProgressTask(App.Kp2a, this, task).Run();
|
||||
};
|
||||
|
||||
@ -319,31 +321,7 @@ namespace keepass2android
|
||||
}
|
||||
};
|
||||
|
||||
CheckBox defaultCheck = (CheckBox)FindViewById(Resource.Id.default_database);
|
||||
//Don't allow the current file to be the default if we don't have stored credentials
|
||||
if ((_ioConnection.IsLocalFile() == false) && (_ioConnection.CredSaveMode != IOCredSaveMode.SaveCred))
|
||||
{
|
||||
defaultCheck.Enabled = false;
|
||||
} else
|
||||
{
|
||||
defaultCheck.Enabled = true;
|
||||
}
|
||||
defaultCheck.CheckedChange += (sender, e) =>
|
||||
{
|
||||
String newDefaultFileName;
|
||||
|
||||
if (e.IsChecked)
|
||||
{
|
||||
newDefaultFileName = _ioConnection.Path;
|
||||
} else
|
||||
{
|
||||
newDefaultFileName = "";
|
||||
}
|
||||
|
||||
ISharedPreferencesEditor editor = _prefs.Edit();
|
||||
editor.PutString(KeyDefaultFilename, newDefaultFileName);
|
||||
EditorCompat.Apply(editor);
|
||||
};
|
||||
|
||||
ImageButton browse = (ImageButton)FindViewById(Resource.Id.browse_button);
|
||||
browse.Click += (sender, evt) =>
|
||||
@ -365,6 +343,34 @@ namespace keepass2android
|
||||
RetrieveSettings();
|
||||
}
|
||||
|
||||
private void SetNewDefaultFile()
|
||||
{
|
||||
//Don't allow the current file to be the default if we don't have stored credentials
|
||||
bool makeFileDefault;
|
||||
if ((_ioConnection.IsLocalFile() == false) && (_ioConnection.CredSaveMode != IOCredSaveMode.SaveCred))
|
||||
{
|
||||
makeFileDefault = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
makeFileDefault = true;
|
||||
}
|
||||
String newDefaultFileName;
|
||||
|
||||
if (makeFileDefault)
|
||||
{
|
||||
newDefaultFileName = _ioConnection.Path;
|
||||
}
|
||||
else
|
||||
{
|
||||
newDefaultFileName = "";
|
||||
}
|
||||
|
||||
ISharedPreferencesEditor editor = _prefs.Edit();
|
||||
editor.PutString(KeyDefaultFilename, newDefaultFileName);
|
||||
EditorCompat.Apply(editor);
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@ -432,11 +438,6 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
private void RetrieveSettings() {
|
||||
String defaultFilename = _prefs.GetString(KeyDefaultFilename, "");
|
||||
if (!String.IsNullOrEmpty(_ioConnection.Path) && _ioConnection.Path.Equals(defaultFilename)) {
|
||||
CheckBox checkbox = (CheckBox) FindViewById(Resource.Id.default_database);
|
||||
checkbox.Checked = true;
|
||||
}
|
||||
CheckBox cbQuickUnlock = (CheckBox)FindViewById(Resource.Id.enable_quickunlock);
|
||||
cbQuickUnlock.Checked = _prefs.GetBoolean(GetString(Resource.String.QuickUnlockDefaultEnabled_key), true);
|
||||
}
|
||||
@ -502,8 +503,19 @@ namespace keepass2android
|
||||
case Resource.Id.menu_app_settings:
|
||||
AppSettingsActivity.Launch(this);
|
||||
return true;
|
||||
|
||||
case Resource.Id.menu_change_db:
|
||||
Intent intent = new Intent(this, typeof(FileSelectActivity));
|
||||
AppTask.ToIntent(intent);
|
||||
StartActivityForResult(intent, 0);
|
||||
Finish();
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return base.OnOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
779
src/keepass2android/Resources/Resource.designer.cs
generated
779
src/keepass2android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -91,16 +91,10 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/keyfileLine" />
|
||||
<CheckBox
|
||||
android:id="@+id/default_database"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/pass_ok"
|
||||
android:text="@string/default_checkbox" />
|
||||
<CheckBox
|
||||
android:id="@+id/enable_quickunlock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/default_database"
|
||||
android:layout_below="@id/pass_ok"
|
||||
android:text="@string/enable_quickunlock" />
|
||||
</RelativeLayout>
|
@ -79,16 +79,10 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/pass_keyfile" />
|
||||
<CheckBox
|
||||
android:id="@+id/default_database"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/pass_ok"
|
||||
android:text="@string/default_checkbox" />
|
||||
<CheckBox
|
||||
android:id="@+id/enable_quickunlock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/default_database"
|
||||
android:layout_below="@id/pass_ok"
|
||||
android:text="@string/enable_quickunlock" />
|
||||
</RelativeLayout>
|
@ -20,6 +20,11 @@
|
||||
android:title="@string/menu_about"
|
||||
android:icon="@android:drawable/ic_menu_help"
|
||||
android:showAsAction="ifRoom"
|
||||
/>
|
||||
<item android:id="@+id/menu_change_db"
|
||||
android:icon="@drawable/collections_collection"
|
||||
android:title="@string/menu_change_db"
|
||||
android:showAsAction="ifRoom"
|
||||
/>
|
||||
<item android:id="@+id/menu_app_settings"
|
||||
android:title="@string/menu_app_settings"
|
||||
|
@ -19,6 +19,10 @@
|
||||
<item android:id="@+id/menu_app_settings"
|
||||
android:icon="@android:drawable/ic_menu_preferences"
|
||||
android:title="@string/menu_app_settings"
|
||||
/>
|
||||
<item android:id="@+id/menu_change_db"
|
||||
android:icon="@drawable/collections_collection"
|
||||
android:title="@string/menu_change_db"
|
||||
/>
|
||||
<item android:id="@+id/menu_about"
|
||||
android:icon="@android:drawable/ic_menu_help"
|
||||
|
@ -131,6 +131,7 @@
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_search_advanced">Advanced Search</string>
|
||||
<string name="menu_url">Go to URL</string>
|
||||
<string name="menu_change_db">Change database…</string>
|
||||
<string name="minus">Minus</string>
|
||||
<string name="never">Never</string>
|
||||
<string name="yes">Yes</string>
|
||||
|
@ -62,11 +62,6 @@ namespace keepass2android
|
||||
|
||||
internal AppTask AppTask;
|
||||
|
||||
IOConnectionInfo LoadIoc(string defaultFileName)
|
||||
{
|
||||
return _DbHelper.CursorToIoc(_DbHelper.FetchFileByName(defaultFileName));
|
||||
}
|
||||
|
||||
void ShowFilenameDialog(bool showOpenButton, bool showCreateButton, bool showBrowseButton, string defaultFilename, string detailsText, int requestCodeBrowse)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
@ -376,6 +371,7 @@ namespace keepass2android
|
||||
ioc.Password = password;
|
||||
ioc.CredSaveMode = (IOCredSaveMode)credentialRememberMode;
|
||||
PasswordActivity.Launch(this, ioc, AppTask);
|
||||
Finish();
|
||||
});
|
||||
builder.SetView(LayoutInflater.Inflate(Resource.Layout.url_credentials, null));
|
||||
builder.SetNeutralButton(GetString(Android.Resource.String.Cancel),
|
||||
@ -391,6 +387,7 @@ namespace keepass2android
|
||||
try
|
||||
{
|
||||
PasswordActivity.Launch(this, ioc, AppTask);
|
||||
Finish();
|
||||
} catch (Java.IO.FileNotFoundException)
|
||||
{
|
||||
Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
|
||||
@ -474,36 +471,6 @@ namespace keepass2android
|
||||
|
||||
_fileSelectButtons.UpdateExternalStorageWarning();
|
||||
|
||||
if (!_createdWithActivityResult)
|
||||
{
|
||||
if ((Intent.Action == Intent.ActionSend) && (App.Kp2a.GetDb().Loaded))
|
||||
{
|
||||
PasswordActivity.Launch(this, App.Kp2a.GetDb().Ioc , AppTask);
|
||||
} else
|
||||
{
|
||||
|
||||
// Load default database
|
||||
ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);
|
||||
String defaultFileName = prefs.GetString(PasswordActivity.KeyDefaultFilename, "");
|
||||
|
||||
if (defaultFileName.Length > 0)
|
||||
{
|
||||
Java.IO.File db = new Java.IO.File(defaultFileName);
|
||||
|
||||
if (db.Exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
PasswordActivity.Launch(this, LoadIoc(defaultFileName), AppTask);
|
||||
} catch (Exception e)
|
||||
{
|
||||
Toast.MakeText(this, e.Message, ToastLength.Long);
|
||||
// Ignore exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -516,8 +483,10 @@ namespace keepass2android
|
||||
if (db.Loaded)
|
||||
{
|
||||
PasswordActivity.Launch(this, db.Ioc, AppTask);
|
||||
Finish();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public override bool OnCreateOptionsMenu(IMenu menu) {
|
||||
base.OnCreateOptionsMenu(menu);
|
||||
|
Loading…
Reference in New Issue
Block a user