summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2018-06-26 11:36:38 -0700
committercyberta <cyberta@riseup.net>2018-06-26 11:36:38 -0700
commit8c9879145e588e985e5305ee2f88dfc1b6bf1d10 (patch)
tree304bbc7ea3dd6975369a80988f9e3c45acfa762e
parentee64bde0da3ef44387e8af7ef980c4b1bb63565c (diff)
parent9cbcd3bad1f0aa33b7c08dc18f7065a126af7eb5 (diff)
Merge branch 'imp_donation' into 'master'
Modified donation reminder See merge request leap/bitmask_android!76
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Constants.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java38
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/DateHelper.java29
3 files changed, 52 insertions, 16 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java
index af1d55ec..8ec3fcc7 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java
@@ -99,6 +99,7 @@ public interface Constants {
String DONATION_URL = TextUtils.isEmpty(BuildConfig.donation_url) ?
BuildConfig.default_donation_url : BuildConfig.donation_url;
String LAST_DONATION_REMINDER_DATE = "last_donation_reminder_date";
+ String FIRST_TIME_USER_DATE = "first_time_user_date";
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 535322e5..51f787b7 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -58,6 +58,7 @@ import de.blinkt.openvpn.core.OpenVPNService;
import de.blinkt.openvpn.core.ProfileManager;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
+import se.leap.bitmaskclient.utils.DateHelper;
import se.leap.bitmaskclient.views.VpnStateImage;
import static android.view.View.GONE;
@@ -65,6 +66,7 @@ import static android.view.View.VISIBLE;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
import static se.leap.bitmaskclient.Constants.DONATION_REMINDER_DURATION;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
+import static se.leap.bitmaskclient.Constants.FIRST_TIME_USER_DATE;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_LOG_IN;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER;
@@ -530,7 +532,8 @@ public class EipFragment extends Fragment implements Observer {
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
- saveLastDonationReminderDate();
+ preferences.edit().putString(LAST_DONATION_REMINDER_DATE,
+ DateHelper.getCurrentDateString()).apply();
}
}).show();
}
@@ -545,29 +548,32 @@ public class EipFragment extends Fragment implements Observer {
return false;
}
- String lastDonationReminderDate = preferences.getString(LAST_DONATION_REMINDER_DATE, null);
- if (lastDonationReminderDate == null) {
- return true;
+ String firstTimeUserDate = preferences.getString(FIRST_TIME_USER_DATE, null);
+ if (firstTimeUserDate == null) {
+ preferences.edit().putString(FIRST_TIME_USER_DATE, DateHelper.getCurrentDateString()).apply();
+ return false;
}
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
- Date lastDate;
try {
- lastDate = sdf.parse(lastDonationReminderDate);
+ long diffDays;
+
+ diffDays = DateHelper.getDateDiffToCurrentDateInDays(firstTimeUserDate);
+ if (diffDays < 1) {
+ return false;
+ }
+
+ String lastDonationReminderDate = preferences.getString(LAST_DONATION_REMINDER_DATE, null);
+ if (lastDonationReminderDate == null) {
+ return true;
+ }
+ diffDays = DateHelper.getDateDiffToCurrentDateInDays(lastDonationReminderDate);
+ return diffDays >= DONATION_REMINDER_DURATION;
+
} catch (ParseException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
return false;
}
-
- Date currentDate = new Date();
- long diffDays = (currentDate.getTime() - lastDate.getTime()) / ONE_DAY;
- return diffDays >= DONATION_REMINDER_DURATION;
}
- private void saveLastDonationReminderDate() {
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
- Date lastDate = new Date();
- preferences.edit().putString(LAST_DONATION_REMINDER_DATE, sdf.format(lastDate)).apply();
- }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/DateHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/DateHelper.java
new file mode 100644
index 00000000..523c8c4c
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/DateHelper.java
@@ -0,0 +1,29 @@
+package se.leap.bitmaskclient.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Contains helper methods related to date manipulation.
+ *
+ * @author Janak
+ */
+public class DateHelper {
+ private static final String DATE_PATTERN = "dd/MM/yyyy";
+ private static final int ONE_DAY = 86400000; //1000*60*60*24
+
+ public static long getDateDiffToCurrentDateInDays(String startDate) throws ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
+ Date lastDate = sdf.parse(startDate);
+ Date currentDate = new Date();
+ return (currentDate.getTime() - lastDate.getTime()) / ONE_DAY;
+ }
+
+ public static String getCurrentDateString() {
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
+ Date lastDate = new Date();
+ return sdf.format(lastDate);
+ }
+}