summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorJanak Amarasena <janakamarasena@gmail.com>2018-06-23 16:25:38 +0530
committerJanak Amarasena <janakamarasena@gmail.com>2018-06-23 16:25:38 +0530
commitb8e562d03695f5a73809feb0751a9c296c9c5fa4 (patch)
tree729049747915bb3d70523ae77b5721eeb793ee98 /app/src/main
parent55c3972e9ac0796a801c64788eb364cbd0c9cf02 (diff)
Modified donation reminder
Diffstat (limited to 'app/src/main')
-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.java30
3 files changed, 53 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..a8649132
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/DateHelper.java
@@ -0,0 +1,30 @@
+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;
+ 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);
+ }
+}