LoadDb and SaveDb respect the SyncInBackground preference
This commit is contained in:
@@ -1753,17 +1753,10 @@ namespace keepass2android
|
||||
cbOfflineMode.Checked =
|
||||
App.Kp2a
|
||||
.OfflineModePreference; //this won't overwrite new user settings because every change is directly saved in settings
|
||||
LinearLayout offlineModeContainer = FindViewById<LinearLayout>(Resource.Id.work_offline_container);
|
||||
var cachingFileStorage = App.Kp2a.GetFileStorage(_ioConnection) as CachingFileStorage;
|
||||
if ((cachingFileStorage != null) && cachingFileStorage.IsCached(_ioConnection))
|
||||
{
|
||||
offlineModeContainer.Visibility = ViewStates.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
offlineModeContainer.Visibility = ViewStates.Gone;
|
||||
App.Kp2a.OfflineMode = false;
|
||||
}
|
||||
|
||||
CheckBox cbSyncInBackground = (CheckBox)FindViewById(Resource.Id.sync_in_background)!;
|
||||
cbSyncInBackground.Checked = App.Kp2a.SyncInBackgroundPreference;
|
||||
UpdateInternalCacheCheckboxesVisibility();
|
||||
|
||||
|
||||
|
||||
@@ -2039,10 +2032,38 @@ namespace keepass2android
|
||||
{
|
||||
App.Kp2a.OfflineModePreference = App.Kp2a.OfflineMode = args.IsChecked;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private String LoadKeyProviderStringForIoc(String filename) {
|
||||
|
||||
CheckBox cbSyncInBackground = (CheckBox)FindViewById(Resource.Id.sync_in_background);
|
||||
cbSyncInBackground.CheckedChange += (sender, args) =>
|
||||
{
|
||||
App.Kp2a.SyncInBackgroundPreference = args.IsChecked;
|
||||
UpdateInternalCacheCheckboxesVisibility();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private void UpdateInternalCacheCheckboxesVisibility()
|
||||
{
|
||||
|
||||
LinearLayout syncInBackgroundContainer = FindViewById<LinearLayout>(Resource.Id.sync_in_background_container)!;
|
||||
|
||||
LinearLayout offlineModeContainer = FindViewById<LinearLayout>(Resource.Id.work_offline_container)!;
|
||||
var cachingFileStorage = App.Kp2a.GetFileStorage(_ioConnection) as CachingFileStorage;
|
||||
if ((cachingFileStorage != null) && cachingFileStorage.IsCached(_ioConnection))
|
||||
{
|
||||
syncInBackgroundContainer.Visibility = ViewStates.Visible;
|
||||
offlineModeContainer.Visibility =
|
||||
App.Kp2a.SyncInBackgroundPreference ? ViewStates.Gone : ViewStates.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
syncInBackgroundContainer.Visibility = offlineModeContainer.Visibility = ViewStates.Gone;
|
||||
App.Kp2a.OfflineMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
private String LoadKeyProviderStringForIoc(String filename) {
|
||||
if ( _rememberKeyfile ) {
|
||||
string keyfile = App.Kp2a.FileDbHelper.GetKeyFileForFile(filename);
|
||||
if (String.IsNullOrEmpty(keyfile))
|
||||
|
||||
@@ -318,6 +318,30 @@
|
||||
android:text="@string/help_quickunlock"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sync_in_background_container"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/sync_in_background"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/SyncOfflineCacheInBackground_title" />
|
||||
<keepass2android.views.Kp2aShortHelpView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextAppearance_Help_Dense"
|
||||
|
||||
app:help_text="@string/SyncOfflineCacheInBackground_summary"
|
||||
app:title_text="@string/SyncOfflineCacheInBackground_title"
|
||||
android:text="@string/SyncOfflineCacheInBackground_summary"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/work_offline_container"
|
||||
android:orientation="horizontal"
|
||||
@@ -328,7 +352,7 @@
|
||||
android:id="@+id/work_offline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
|
||||
android:text="@string/UseOfflineMode" />
|
||||
<keepass2android.views.Kp2aShortHelpView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -341,6 +365,7 @@
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/kill_app"
|
||||
android:text="@string/kill_app_label"
|
||||
|
||||
@@ -56,12 +56,16 @@ namespace keepass2android
|
||||
OperationWithFinishHandler task;
|
||||
OnOperationFinishedHandler onOperationFinishedHandler = new ActionOnOperationFinished(_activity, (success, message, activity) =>
|
||||
{
|
||||
if (!String.IsNullOrEmpty(message))
|
||||
App.Kp2a.ShowMessage(activity, message, success ? MessageSeverity.Info : MessageSeverity.Error);
|
||||
new Handler(Looper.MainLooper).Post(() =>
|
||||
{
|
||||
if (!String.IsNullOrEmpty(message))
|
||||
App.Kp2a.ShowMessage(activity, message, success ? MessageSeverity.Info : MessageSeverity.Error);
|
||||
|
||||
// Tell the adapter to refresh it's list
|
||||
BaseAdapter adapter = (activity as GroupBaseActivity)?.ListAdapter;
|
||||
new Handler(Looper.MainLooper).Post(() => adapter?.NotifyDataSetChanged());
|
||||
// Tell the adapter to refresh it's list
|
||||
BaseAdapter adapter = (activity as GroupBaseActivity)?.ListAdapter;
|
||||
|
||||
adapter?.NotifyDataSetChanged();
|
||||
});
|
||||
|
||||
if (App.Kp2a.CurrentDb?.OtpAuxFileIoc != null)
|
||||
{
|
||||
|
||||
@@ -46,7 +46,10 @@ namespace keepass2android.Utils
|
||||
{
|
||||
public void ShowMessage(Message message)
|
||||
{
|
||||
Toast.MakeText(App.Context, message.Text, ToastLength.Long).Show();
|
||||
new Handler(Looper.MainLooper).Post(() =>
|
||||
{
|
||||
Toast.MakeText(App.Context, message.Text, ToastLength.Long).Show();
|
||||
});
|
||||
}
|
||||
|
||||
public List<Message> PendingMessages => new();
|
||||
|
||||
@@ -798,9 +798,14 @@ namespace keepass2android
|
||||
fileStorage = innerFileStorage;
|
||||
}
|
||||
}
|
||||
if (fileStorage is IOfflineSwitchable)
|
||||
if (fileStorage is IOfflineSwitchable switchable)
|
||||
{
|
||||
((IOfflineSwitchable)fileStorage).IsOffline = App.Kp2a.OfflineMode;
|
||||
switchable.IsOffline = App.Kp2a.OfflineMode;
|
||||
if (switchable.IsOffline)
|
||||
{
|
||||
//users of the file storage can set this to false, but the default is to show a warning:
|
||||
switchable.TriggerWarningWhenFallingBackToCache = true;
|
||||
}
|
||||
}
|
||||
return fileStorage;
|
||||
}
|
||||
@@ -1151,10 +1156,28 @@ namespace keepass2android
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// true if the app is used in offline mode
|
||||
/// </summary>
|
||||
public bool OfflineMode
|
||||
|
||||
public bool SyncInBackgroundPreference
|
||||
{
|
||||
get
|
||||
{
|
||||
var prefs = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext);
|
||||
return prefs.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.SyncOfflineCacheInBackground_key), false);
|
||||
}
|
||||
set
|
||||
{
|
||||
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext);
|
||||
ISharedPreferencesEditor edit = prefs.Edit();
|
||||
edit.PutBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.SyncOfflineCacheInBackground_key), value);
|
||||
edit.Commit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// true if the app is used in offline mode
|
||||
/// </summary>
|
||||
public bool OfflineMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user