improve message when file is readonly, closes #521

This commit is contained in:
Philipp Crocoll
2018-12-17 11:47:24 +01:00
parent 06e64f7347
commit 780d4c95fe
3 changed files with 64 additions and 22 deletions

View File

@@ -251,28 +251,6 @@ namespace keepass2android
FragmentManager.FindFragmentById<GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);
Log.Warn(Tag, "Finished creating group");
var ioc = App.Kp2a.CurrentDb.Ioc;
OptionalOut<UiStringKey> reason = new OptionalOut<UiStringKey>();
if (App.Kp2a.GetFileStorage(ioc).IsReadOnly(ioc, reason))
{
bool hasShownReadOnlyReason =
PreferenceManager.GetDefaultSharedPreferences(this)
.GetBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", false);
if (!hasShownReadOnlyReason)
{
var b = new AlertDialog.Builder(this);
b.SetTitle(Resource.String.FileReadOnlyTitle);
b.SetMessage(GetString(Resource.String.FileReadOnlyMessagePre) + " " + App.Kp2a.GetResourceString(reason.Result));
b.SetPositiveButton(Android.Resource.String.Ok,
(sender, args) =>
{
PreferenceManager.GetDefaultSharedPreferences(this).
Edit().PutBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", true).Commit();
});
b.Show();
}
}
}

View File

@@ -53,6 +53,7 @@ namespace keepass2android
{ Resource.Id.cancel_insert_element, 20 },
{ Resource.Id.insert_element, 20 },
//only use the same id if elements can be shown simultaneously!
{ Resource.Id.dbreadonly_infotext, 14 },
{ Resource.Id.child_db_infotext, 13 },
{ Resource.Id.fingerprint_infotext, 12 },
{ Resource.Id.autofill_infotext, 11 },
@@ -247,6 +248,7 @@ namespace keepass2android
AppTask.StartInGroupActivity(this);
AppTask.SetupGroupBaseActivityButtons(this);
UpdateDbReadOnlyInfo();
UpdateChildDbInfo();
UpdateFingerprintInfo();
UpdateAutofillInfo();
@@ -504,6 +506,16 @@ namespace keepass2android
};
}
if (FindViewById(Resource.Id.info_dont_show_dbreadonly_again) != null)
{
FindViewById(Resource.Id.info_dont_show_dbreadonly_again).Click += (sender, args) =>
{
_prefs.Edit().PutBoolean(dbreadonly_ignore_prefskey + App.Kp2a.CurrentDb.CurrentFingerprintPrefKey, true).Commit();
UpdateDbReadOnlyInfo();
};
}
if (FindViewById(Resource.Id.fabCancelAddNew) != null)
{
FindViewById(Resource.Id.fabAddNew).Click += (sender, args) =>
@@ -616,6 +628,7 @@ namespace keepass2android
return _prefs.GetBoolean("InfoTextDisabled_" + infoTextKey, false);
}
const string dbreadonly_ignore_prefskey = "dbreadonly_ignore_prefskey";
const string childdb_ignore_prefskey = "childdb_ignore_prefskey";
const string autofillservicewasenabled_prefskey = "AutofillServiceWasEnabled";
const string fingerprintinfohidden_prefskey = "fingerprintinfohidden_prefskey";
@@ -695,6 +708,31 @@ namespace keepass2android
UpdateBottomBarElementVisibility(Resource.Id.child_db_infotext, canShow);
}
private void UpdateDbReadOnlyInfo()
{
bool disabledForDatabase = _prefs.GetBoolean(dbreadonly_ignore_prefskey + App.Kp2a.CurrentDb.CurrentFingerprintPrefKey, false);
bool canShow = false;
if (!disabledForDatabase)
{
var ioc = App.Kp2a.CurrentDb.Ioc;
OptionalOut<UiStringKey> reason = new OptionalOut<UiStringKey>();
if (App.Kp2a.GetFileStorage(ioc).IsReadOnly(ioc, reason))
{
canShow = true;
RegisterInfoTextDisplay(
"DbReadOnly"); //this ensures that we don't show the general info texts too soon
FindViewById<TextView>(Resource.Id.dbreadonly_infotext_text).Text =
(GetString(Resource.String.FileReadOnlyMessagePre) + " " +
App.Kp2a.GetResourceString(reason.Result));
}
}
UpdateBottomBarElementVisibility(Resource.Id.dbreadonly_infotext, canShow);
}
protected void UpdateBottomBarElementVisibility(int resourceId, bool canShow)
{

View File

@@ -136,6 +136,32 @@
style="@style/BottomBarButton" />
</LinearLayout>
<LinearLayout
android:id="@+id/dbreadonly_infotext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical">
<TextView android:id="@+id/dbreadonly_infotext_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="6dp"
android:layout_marginBottom="2dp"
/>
<Button
android:id="@+id/info_dont_show_dbreadonly_again"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:text="@string/dont_show_again"
style="@style/BottomBarButton" />
</LinearLayout>
<LinearLayout
android:id="@+id/child_db_infotext"
android:layout_width="match_parent"