From 293ba7ebe699488e930f3d94817f54fc7a8c1154 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Oct 2018 11:31:45 +0000 Subject: [PATCH] Made encryption a pro feature --- .../eu/faircode/email/ActivityCompose.java | 14 ++++++ .../java/eu/faircode/email/ActivityView.java | 15 +++--- .../eu/faircode/email/FragmentCompose.java | 48 +++++++++++-------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 718e55c3..10055165 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -23,11 +23,13 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; +import android.view.MenuItem; import java.util.ArrayList; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; +import androidx.lifecycle.Lifecycle; public class ActivityCompose extends ActivityBilling implements FragmentManager.OnBackStackChangedListener { static final int REQUEST_CONTACT_TO = 1; @@ -125,4 +127,16 @@ public class ActivityCompose extends ActivityBilling implements FragmentManager. if (getSupportFragmentManager().getBackStackEntryCount() == 0) finish(); } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) + getSupportFragmentManager().popBackStack(); + return true; + default: + return false; + } + } } diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 610668d8..0efa2311 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -898,12 +898,15 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void onDecrypt(Intent intent) { - Intent data = new Intent(); - data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); - data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{intent.getStringExtra("to")}); - data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); - - decrypt(data, intent.getLongExtra("id", -1)); + if (Helper.isPro(this)) { + Intent data = new Intent(); + data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); + data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{intent.getStringExtra("to")}); + data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); + + decrypt(data, intent.getLongExtra("id", -1)); + } else + onShowPro(intent); } private void onShowPro(Intent intent) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index eeb079cb..3868e0c6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -488,27 +488,33 @@ public class FragmentCompose extends FragmentEx { } private void onEncrypt() { - try { - String to = etTo.getText().toString(); - InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to)); - if (ato.length == 0) - throw new IllegalArgumentException(getString(R.string.title_to_missing)); - - String[] tos = new String[ato.length]; - for (int i = 0; i < ato.length; i++) - tos[i] = ato[i].getAddress(); - - Intent data = new Intent(); - data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); - data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos); - data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); - - encrypt(data); - } catch (Throwable ex) { - if (ex instanceof IllegalArgumentException) - Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); - else - Helper.unexpectedError(getContext(), ex); + if (Helper.isPro(getContext())) + try { + String to = etTo.getText().toString(); + InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to)); + if (ato.length == 0) + throw new IllegalArgumentException(getString(R.string.title_to_missing)); + + String[] tos = new String[ato.length]; + for (int i = 0; i < ato.length; i++) + tos[i] = ato[i].getAddress(); + + Intent data = new Intent(); + data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); + data.putExtra(OpenPgpApi.EXTRA_USER_IDS, tos); + data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); + + encrypt(data); + } catch (Throwable ex) { + if (ex instanceof IllegalArgumentException) + Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); + else + Helper.unexpectedError(getContext(), ex); + } + else { + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); + fragmentTransaction.commit(); } }