added option to hide donation screens

This commit is contained in:
Philipp Crocoll 2016-05-25 06:09:28 +02:00
parent ff77a04710
commit d0350e8d9d
7 changed files with 77 additions and 16 deletions

View File

@ -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<Reminder> 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;
}
}
}

View File

@ -1575,14 +1575,8 @@ namespace keepass2android
base.OnStart();
_starting = true;
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
DonateReminder.ShowDonateReminderIfAppropriate(this);
long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);
if (usageCount > 5)
{
DonateReminder.ShowDonateReminderIfAppropriate(this);
}
}

View File

@ -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)

View File

@ -107,6 +107,7 @@
<string name="LockWhenNavigateBack_key">kp2a_switch_rootedLockWhenNavigateBack</string>
<string name="NoDonateOption_key">NoDonateOption</string>
<string name="NoDonationReminder_key">NoDonationReminder</string>
<string name="UseOfflineCache_key">UseOfflineCache</string>
<string name="AcceptAllServerCertificates_key">AcceptAllServerCertificates</string>

View File

@ -331,8 +331,11 @@
<string name="NoDonateOption_summary">This setting is for donators. It is available after using Keepass2Android for a while only.</string>
<string name="NoDonateOption_question">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.</string>
<string name="NoDonationReminder_title">Never ever ask for donation</string>
<string name="NoDonationReminder_summary">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.</string>
<string name="UseOfflineCache_title">Database caching</string>
<string name="UseOfflineCache_title">Database caching</string>
<string name="UseOfflineCache_summary">Keep a copy of remote database files in the application cache directory. This allows to use remote databases even when offline.</string>
<string name="AcceptAllServerCertificates_title">SSL certificates</string>

View File

@ -233,6 +233,14 @@
android:defaultValue="false"
android:title="@string/NoDonateOption_title"
android:key="@string/NoDonateOption_key" />
<CheckBoxPreference
android:enabled="true"
android:persistent="true"
android:summary="@string/NoDonationReminder_summary"
android:defaultValue="false"
android:title="@string/NoDonationReminder_title"
android:key="@string/NoDonationReminder_key" />
</PreferenceScreen>
<PreferenceScreen

View File

@ -337,6 +337,7 @@ namespace keepass2android
FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged;
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key)));
PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key)));
FindPreference(GetString(Resource.String.design_key)).PreferenceChange += (sender, args) => 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[]