added donate-reminder for birthday

This commit is contained in:
Philipp Crocoll 2014-04-01 07:26:10 +02:00
parent 5693970665
commit 7b7a4eb8a5
5 changed files with 156 additions and 14 deletions

View File

@ -6,6 +6,7 @@ using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using Android.Widget;
@ -16,14 +17,76 @@ namespace keepass2android
[Activity(Label = AppNames.AppName, Theme = "@style/Base")]
public class DonateReminder : Activity
{
class Reminder
{
public DateTime From, To;
public int ResourceToShow;
public string Key;
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.donate);
foreach (Reminder r in GetReminders())
{
if ((DateTime.Now > r.From)
&& (DateTime.Now < r.To))
{
SetContentView(r.ResourceToShow);
}
}
FindViewById(Resource.Id.ok_donate).Click += (sender, args) => { Util.GotoDonateUrl(this);Finish(); };
FindViewById(Resource.Id.no_donate).Click += (sender, args) => { Finish(); };
}
static IEnumerable<Reminder> GetReminders()
{
yield return new Reminder
{
From = new DateTime(2014, 09, 20),
To = new DateTime(2014, 10, 06),
Key = "DonationOktoberfest2014"
,ResourceToShow = Resource.Layout.donate
};
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)
{
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();
edit.PutBoolean(r.Key, true);
EditorCompat.Apply(edit);
context.StartActivity(new Intent(context, typeof(DonateReminder)));
}
}
}
}
}
}

View File

@ -831,20 +831,9 @@ namespace keepass2android
long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);
if ((DateTime.Now > new DateTime(2013, 09, 21))
&& (DateTime.Now < new DateTime(2013, 10, 07))
&& (usageCount > 5)
)
if (usageCount > 5)
{
const string donationOkt2013Key = "HasAskedForDonationOktoberfest2013";
if (prefs.GetBoolean(donationOkt2013Key, false) == false)
{
ISharedPreferencesEditor edit = prefs.Edit();
edit.PutBoolean(donationOkt2013Key, true);
EditorCompat.Apply(edit);
StartActivity(new Intent(this, typeof(DonateReminder)));
}
DonateReminder.ShowDonateReminderIfAppropriate(this);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -0,0 +1,45 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<TextView
android:id="@+id/donate_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/donate_bday_question" />
<ImageView
android:id="@+id/imgoktfest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/donate_question"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/donate_cake" />
<Button
android:text="@string/ok_donate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imgoktfest"
android:id="@+id/ok_donate"
/>
<Button
android:text="@string/no_thanks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ok_donate"
android:id="@+id/no_donate"
/>
</RelativeLayout>
</ScrollView>

View File

@ -0,0 +1,45 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<TextView
android:id="@+id/donate_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/donate_missedbday_question" />
<ImageView
android:id="@+id/imgoktfest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/donate_question"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/donate_cake" />
<Button
android:text="@string/ok_donate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imgoktfest"
android:id="@+id/ok_donate"
/>
<Button
android:text="@string/no_thanks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ok_donate"
android:id="@+id/no_donate"
/>
</RelativeLayout>
</ScrollView>