summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java97
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LoginActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SignupActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java121
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java9
5 files changed, 145 insertions, 86 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 51f787b7..a168059f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -25,27 +25,21 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
-import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
+import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
-import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.temporal.ChronoUnit;
-import java.util.Date;
-import java.util.Locale;
import java.util.Observable;
import java.util.Observer;
@@ -58,23 +52,17 @@ 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.fragments.DonationReminderDialog;
import se.leap.bitmaskclient.views.VpnStateImage;
import static android.view.View.GONE;
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;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
-import static se.leap.bitmaskclient.Constants.DONATION_URL;
-import static se.leap.bitmaskclient.Constants.ENABLE_DONATION;
-import static se.leap.bitmaskclient.Constants.ENABLE_DONATION_REMINDER;
-import static se.leap.bitmaskclient.Constants.LAST_DONATION_REMINDER_DATE;
import static se.leap.bitmaskclient.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.ProviderAPI.USER_MESSAGE;
import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message;
@@ -85,7 +73,6 @@ public class EipFragment extends Fragment implements Observer {
public static final String ASK_TO_CANCEL_VPN = "ask_to_cancel_vpn";
-
private SharedPreferences preferences;
private Provider provider;
@@ -117,9 +104,6 @@ public class EipFragment extends Fragment implements Observer {
private IOpenVPNServiceInternal mService;
private ServiceConnection openVpnConnection;
- private final String DATE_PATTERN = "dd/MM/yyyy";
- private final int ONE_DAY = 86400000; //1000*60*60*24
-
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -172,8 +156,8 @@ public class EipFragment extends Fragment implements Observer {
@Override
public void onStart() {
super.onStart();
- if (isDonationReminderCallable()) {
- showDonationReminder();
+ if (DonationReminderDialog.isCallable(getContext())) {
+ showDonationReminderDialog();
}
}
@@ -509,71 +493,16 @@ public class EipFragment extends Fragment implements Observer {
}
}
- private void showDonationReminder() {
- Activity activity = getActivity();
- if (activity == null) {
- Log.e(TAG, "activity is null when triggering donation reminder");
- return;
- }
- String message = TextUtils.isEmpty(activity.getString(R.string.donate_message)) ?
- activity.getString(R.string.donate_default_message) : activity.getString(R.string.donate_message);
- AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
- alertDialog = alertBuilder.setTitle(activity.getString(R.string.donate_title))
- .setMessage(message)
- .setPositiveButton(R.string.donate_button_donate, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL));
- startActivity(browserIntent);
- }
- })
- .setNegativeButton(R.string.donate_button_remind_later, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- }
- }).setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- preferences.edit().putString(LAST_DONATION_REMINDER_DATE,
- DateHelper.getCurrentDateString()).apply();
- }
- }).show();
- }
-
- private boolean isDonationReminderCallable() {
- if (!ENABLE_DONATION || !ENABLE_DONATION_REMINDER) {
- return false;
- }
-
- if (preferences == null) {
- Log.e(TAG, "preferences is null!");
- return false;
- }
-
- String firstTimeUserDate = preferences.getString(FIRST_TIME_USER_DATE, null);
- if (firstTimeUserDate == null) {
- preferences.edit().putString(FIRST_TIME_USER_DATE, DateHelper.getCurrentDateString()).apply();
- return false;
- }
-
+ public void showDonationReminderDialog() {
try {
- 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) {
+ FragmentTransaction fragmentTransaction = new FragmentManagerEnhanced(
+ getActivity().getSupportFragmentManager()).removePreviousFragment(
+ DonationReminderDialog.TAG);
+ DialogFragment newFragment = new DonationReminderDialog();
+ newFragment.setCancelable(false);
+ newFragment.show(fragmentTransaction, DonationReminderDialog.TAG);
+ } catch (IllegalStateException | NullPointerException e) {
e.printStackTrace();
- Log.e(TAG, e.getMessage());
- return false;
}
}
-
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
index a407b0a9..00ede1a6 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java
@@ -17,7 +17,7 @@ public class LoginActivity extends ProviderCredentialsBaseActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setProgressbarText(R.string.logging_in);
- setProviderHeaderLogo(R.drawable.mask);
+ setProviderHeaderLogo(R.drawable.logo);
setProviderHeaderText(R.string.login_to_profile);
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java
index 0ff792bb..3eac711f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java
@@ -18,7 +18,7 @@ public class SignupActivity extends ProviderCredentialsBaseActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setProviderHeaderLogo(R.drawable.mask);
+ setProviderHeaderLogo(R.drawable.logo);
setProviderHeaderText(R.string.create_profile);
setProgressbarText(R.string.signing_up);
diff --git a/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java b/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java
new file mode 100644
index 00000000..001d7e6c
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/fragments/DonationReminderDialog.java
@@ -0,0 +1,121 @@
+package se.leap.bitmaskclient.fragments;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatDialogFragment;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+
+import java.text.ParseException;
+
+import butterknife.ButterKnife;
+import butterknife.InjectView;
+import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.utils.DateHelper;
+import se.leap.bitmaskclient.utils.PreferenceHelper;
+
+import static se.leap.bitmaskclient.Constants.DONATION_REMINDER_DURATION;
+import static se.leap.bitmaskclient.Constants.DONATION_URL;
+import static se.leap.bitmaskclient.Constants.ENABLE_DONATION;
+import static se.leap.bitmaskclient.Constants.ENABLE_DONATION_REMINDER;
+import static se.leap.bitmaskclient.Constants.FIRST_TIME_USER_DATE;
+import static se.leap.bitmaskclient.Constants.LAST_DONATION_REMINDER_DATE;
+
+public class DonationReminderDialog extends AppCompatDialogFragment {
+
+ public final static String TAG = DonationReminderDialog.class.getName();
+ private static boolean isShown = false;
+
+ @InjectView(R.id.btnDonate)
+ Button btnDonate;
+
+ @InjectView(R.id.btnLater)
+ Button btnLater;
+
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ View view = inflater.inflate(R.layout.donation_reminder_dialog, null);
+ ButterKnife.inject(this, view);
+ isShown = true;
+
+ builder.setView(view);
+ btnDonate.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL));
+ startActivity(browserIntent);
+ PreferenceHelper.putString(getContext(), LAST_DONATION_REMINDER_DATE,
+ DateHelper.getCurrentDateString());
+ dismiss();
+ }
+ });
+ btnLater.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ PreferenceHelper.putString(getContext(), LAST_DONATION_REMINDER_DATE,
+ DateHelper.getCurrentDateString());
+ dismiss();
+ }
+ });
+
+ return builder.create();
+ }
+
+ public static boolean isCallable(Context context) {
+ if (isShown) {
+ return false;
+ }
+
+ if (!ENABLE_DONATION || !ENABLE_DONATION_REMINDER) {
+ return false;
+ }
+
+ if (context == null) {
+ Log.e(TAG, "context is null!");
+ return false;
+ }
+
+ String firstTimeUserDate = PreferenceHelper.getString(context, FIRST_TIME_USER_DATE, null);
+ if (firstTimeUserDate == null) {
+ PreferenceHelper.putString(context, FIRST_TIME_USER_DATE, DateHelper.getCurrentDateString());
+ return false;
+ }
+
+ try {
+ long diffDays;
+
+ diffDays = DateHelper.getDateDiffToCurrentDateInDays(firstTimeUserDate);
+ if (diffDays < 1) {
+ return false;
+ }
+
+ String lastDonationReminderDate = PreferenceHelper.getString(context, 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;
+ }
+ }
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
index 12015dfb..b1da1284 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
@@ -239,4 +239,13 @@ public class PreferenceHelper {
return result;
}
+ public static String getString(Context context, String key, String defValue) {
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
+ return preferences.getString(key, defValue);
+ }
+
+ public static void putString(Context context, String key, String value){
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
+ preferences.edit().putString(key, value).apply();
+ }
}