keepass2android/src/keepass2android/DonateReminder.cs

157 lines
4.0 KiB
C#
Raw Normal View History

2013-09-06 16:56:29 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
2014-04-01 01:26:10 -04:00
using Android.Preferences;
2013-09-06 16:56:29 -04:00
using Android.Runtime;
using Android.Views;
using Android.Widget;
using KeePassLib.Utility;
namespace keepass2android
{
[Activity(Label = AppNames.AppName, Theme = "@style/MyTheme_ActionBar")]
2013-09-06 16:56:29 -04:00
public class DonateReminder : Activity
{
2014-04-01 01:26:10 -04:00
class Reminder
{
public DateTime From, To;
public int ResourceToShow;
public string Key;
}
2013-09-06 16:56:29 -04:00
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
2014-04-01 01:26:10 -04:00
foreach (Reminder r in GetReminders())
{
2016-05-25 00:09:28 -04:00
if ((DateTime.Now >= r.From)
2014-04-01 01:26:10 -04:00
&& (DateTime.Now < r.To))
{
SetContentView(r.ResourceToShow);
}
}
2013-09-06 16:56:29 -04:00
FindViewById(Resource.Id.ok_donate).Click += (sender, args) => { Util.GotoDonateUrl(this);Finish(); };
2016-05-25 00:09:28 -04:00
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();
};
2013-09-06 16:56:29 -04:00
}
2014-04-01 01:26:10 -04:00
static IEnumerable<Reminder> GetReminders()
{
yield return new Reminder
{
From = new DateTime(2015, 09, 19),
To = new DateTime(2015, 10, 05),
Key = "DonationOktoberfest2015"
,ResourceToShow = Resource.Layout.donate
};
yield return new Reminder
{
2015-09-16 22:57:36 -04:00
From = new DateTime(2016, 09, 17),
To = new DateTime(2016, 09, 26),
Key = "DonationOktoberfest2016"
,ResourceToShow = Resource.Layout.donate
};
yield return new Reminder
{
From = new DateTime(2016, 09, 26),
To = new DateTime(2016, 10, 04),
Key = "DonationOktoberfest2016-2"
,
ResourceToShow = Resource.Layout.donate
};
yield return new Reminder
{
2015-09-16 22:57:36 -04:00
From = new DateTime(2017, 09, 16),
2016-05-25 00:09:28 -04:00
To = new DateTime(2017, 09, 25),
2015-09-16 22:57:36 -04:00
Key = "DonationOktoberfest2017b"//b because year was incorrectly set to 2015 in 0.9.8b
2016-05-25 00:09:28 -04:00
,
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
{
2015-09-16 22:57:36 -04:00
From = new DateTime(2018, 09, 22),
2016-05-25 00:09:28 -04:00
To = new DateTime(2018, 03, 30),
2015-09-16 22:57:36 -04:00
Key = "DonationOktoberfest2018b"//b because year was incorrectly set to 2015 in 0.9.8b
2014-04-01 01:26:10 -04:00
,ResourceToShow = Resource.Layout.donate
};
2016-05-25 00:09:28 -04:00
yield return new Reminder
{
From = new DateTime(2018, 09, 30),
To = new DateTime(2018, 10, 08),
Key = "DonationOktoberfest2018b-2"
,
ResourceToShow = Resource.Layout.donate
};
2014-04-01 01:26:10 -04:00
int thisYear = DateTime.Now.Year;
yield return new Reminder
{
From = new DateTime(thisYear, 05, 10),
To = new DateTime(thisYear, 05, 11),
Key = "DonationBirthday" + thisYear,
ResourceToShow = Resource.Layout.donate_bday
};
yield return new Reminder
{
From = new DateTime(thisYear, 05, 11),
To = new DateTime(thisYear, 05, 16),
Key = "DonationBirthday" + thisYear,
ResourceToShow = Resource.Layout.donate_bdaymissed
};
}
public static void ShowDonateReminderIfAppropriate(Activity context)
{
2016-05-25 00:09:28 -04:00
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;
2014-04-01 01:26:10 -04:00
foreach (Reminder r in GetReminders())
{
if ((DateTime.Now >= r.From )
&& (DateTime.Now < r.To))
{
if (prefs.GetBoolean(r.Key, false) == false)
{
ISharedPreferencesEditor edit = prefs.Edit();
edit.PutBoolean(r.Key, true);
EditorCompat.Apply(edit);
context.StartActivity(new Intent(context, typeof(DonateReminder)));
2016-05-25 00:09:28 -04:00
break;
2014-04-01 01:26:10 -04:00
}
}
}
}
2013-09-06 16:56:29 -04:00
}
}