From d0350e8d9dc677d88b6d39b6177b3edce417c124 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Wed, 25 May 2016 06:09:28 +0200 Subject: [PATCH] added option to hide donation screens --- src/keepass2android/DonateReminder.cs | 47 ++++++++++++++++--- src/keepass2android/PasswordActivity.cs | 10 +--- src/keepass2android/QuickUnlock.cs | 7 +++ .../Resources/values/config.xml | 1 + .../Resources/values/strings.xml | 7 ++- .../Resources/xml/preferences.xml | 8 ++++ .../settings/DatabaseSettingsActivity.cs | 13 +++++ 7 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/keepass2android/DonateReminder.cs b/src/keepass2android/DonateReminder.cs index 7f56acb2..e0aecba1 100644 --- a/src/keepass2android/DonateReminder.cs +++ b/src/keepass2android/DonateReminder.cs @@ -30,7 +30,7 @@ namespace keepass2android foreach (Reminder r in GetReminders()) { - if ((DateTime.Now > r.From) + if ((DateTime.Now >= r.From) && (DateTime.Now < r.To)) { SetContentView(r.ResourceToShow); @@ -38,7 +38,16 @@ namespace keepass2android } FindViewById(Resource.Id.ok_donate).Click += (sender, args) => { Util.GotoDonateUrl(this);Finish(); }; - FindViewById(Resource.Id.no_donate).Click += (sender, args) => { Finish(); }; + FindViewById(Resource.Id.no_donate).Click += (sender, args) => + { + ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); + + ISharedPreferencesEditor edit = prefs.Edit(); + edit.PutBoolean("DismissedDonateReminder", true); + EditorCompat.Apply(edit); + + Finish(); + }; } static IEnumerable GetReminders() { @@ -60,17 +69,34 @@ namespace keepass2android yield return new Reminder { From = new DateTime(2017, 09, 16), - To = new DateTime(2017, 10, 04), + To = new DateTime(2017, 09, 25), Key = "DonationOktoberfest2017b"//b because year was incorrectly set to 2015 in 0.9.8b - ,ResourceToShow = Resource.Layout.donate + , + ResourceToShow = Resource.Layout.donate + }; + yield return new Reminder + { + From = new DateTime(2017, 09, 25), + To = new DateTime(2017, 10, 04), + Key = "DonationOktoberfest2017b-2" + , + ResourceToShow = Resource.Layout.donate }; yield return new Reminder { From = new DateTime(2018, 09, 22), - To = new DateTime(2018, 10, 08), + To = new DateTime(2018, 03, 30), Key = "DonationOktoberfest2018b"//b because year was incorrectly set to 2015 in 0.9.8b ,ResourceToShow = Resource.Layout.donate }; + yield return new Reminder + { + From = new DateTime(2018, 09, 30), + To = new DateTime(2018, 10, 08), + Key = "DonationOktoberfest2018b-2" + , + ResourceToShow = Resource.Layout.donate + }; int thisYear = DateTime.Now.Year; @@ -92,12 +118,20 @@ namespace keepass2android public static void ShowDonateReminderIfAppropriate(Activity context) { + ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(context); + if (prefs.GetBoolean(context.GetString(Resource.String.NoDonationReminder_key), false)) + return; + + long usageCount = prefs.GetLong(context.GetString(Resource.String.UsageCount_key), 0); + + if (usageCount <= 5) + return; + foreach (Reminder r in GetReminders()) { if ((DateTime.Now >= r.From ) && (DateTime.Now < r.To)) { - ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(context); if (prefs.GetBoolean(r.Key, false) == false) { ISharedPreferencesEditor edit = prefs.Edit(); @@ -105,6 +139,7 @@ namespace keepass2android EditorCompat.Apply(edit); context.StartActivity(new Intent(context, typeof(DonateReminder))); + break; } } } diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 4581c4e1..6bcf5e84 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -1575,14 +1575,8 @@ namespace keepass2android base.OnStart(); _starting = true; - ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); - - long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0); - - if (usageCount > 5) - { - DonateReminder.ShowDonateReminderIfAppropriate(this); - } + DonateReminder.ShowDonateReminderIfAppropriate(this); + } diff --git a/src/keepass2android/QuickUnlock.cs b/src/keepass2android/QuickUnlock.cs index f9c245f3..41a9e293 100644 --- a/src/keepass2android/QuickUnlock.cs +++ b/src/keepass2android/QuickUnlock.cs @@ -148,6 +148,13 @@ namespace keepass2android } + protected override void OnStart() + { + base.OnStart(); + DonateReminder.ShowDonateReminderIfAppropriate(this); + + } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { if (requestCode == FingerprintPermissionRequestCode && grantResults[0] == Permission.Granted) diff --git a/src/keepass2android/Resources/values/config.xml b/src/keepass2android/Resources/values/config.xml index 2a5cae59..4b0d0f5a 100644 --- a/src/keepass2android/Resources/values/config.xml +++ b/src/keepass2android/Resources/values/config.xml @@ -107,6 +107,7 @@ kp2a_switch_rootedLockWhenNavigateBack NoDonateOption + NoDonationReminder UseOfflineCache AcceptAllServerCertificates diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index 9dfb8d5f..2d04579c 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -331,8 +331,11 @@ This setting is for donators. It is available after using Keepass2Android for a while only. Without donations, this app would not exist and would not be improved continually! If you have not yet donated, please consider making a donation now. - - Database caching + Never ever ask for donation + I won\'t give you a dime or I have already donated. Don\'t ask for a donation, not even at the author\'s birthday. + + + Database caching Keep a copy of remote database files in the application cache directory. This allows to use remote databases even when offline. SSL certificates diff --git a/src/keepass2android/Resources/xml/preferences.xml b/src/keepass2android/Resources/xml/preferences.xml index 52cb05c3..fded5265 100644 --- a/src/keepass2android/Resources/xml/preferences.xml +++ b/src/keepass2android/Resources/xml/preferences.xml @@ -233,6 +233,14 @@ android:defaultValue="false" android:title="@string/NoDonateOption_title" android:key="@string/NoDonateOption_key" /> + + Activity.Recreate(); @@ -424,6 +425,18 @@ namespace keepass2android } + private void PrepareNoDonationReminderPreference(Activity ctx, PreferenceScreen screen, Preference preference) + { + ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx); + + if (!prefs.GetBoolean("DismissedDonateReminder", false)) + { + screen.RemovePreference(preference); + } + + + } + private void SetupErrorReportModePref(ListPreference errorReportModePref) { errorReportModePref.SetEntries(new string[]