Commit 8c987914 authored by cyberta's avatar cyberta

Merge branch 'imp_donation' into 'master'

Modified donation reminder

See merge request !76
parents ee64bde0 9cbcd3ba
Pipeline #16267 passed with stages
in 21 minutes and 17 seconds
......@@ -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";
}
......@@ -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();
}
}
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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment