diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 9c3631df..c7899bdd 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -100,6 +100,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack static final String ACTION_VIEW_MESSAGE = BuildConfig.APPLICATION_ID + ".VIEW_MESSAGE"; static final String ACTION_EDIT_FOLDER = BuildConfig.APPLICATION_ID + ".EDIT_FOLDER"; static final String ACTION_STORE_ATTACHMENT = BuildConfig.APPLICATION_ID + ".STORE_ATTACHMENT"; + static final String ACTION_PURCHASE = BuildConfig.APPLICATION_ID + ".ACTION_PURCHASE"; static final String ACTION_ACTIVATE_PRO = BuildConfig.APPLICATION_ID + ".ACTIVATE_PRO"; @Override @@ -358,6 +359,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack iff.addAction(ACTION_VIEW_MESSAGE); iff.addAction(ACTION_EDIT_FOLDER); iff.addAction(ACTION_STORE_ATTACHMENT); + iff.addAction(ACTION_PURCHASE); iff.addAction(ACTION_ACTIVATE_PRO); lbm.registerReceiver(receiver, iff); @@ -539,24 +541,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack } private void onMenuPro() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (prefs.getBoolean("pro", false)) { - Snackbar.make(view, R.string.title_pro_activated, Snackbar.LENGTH_LONG).show(); - return; - } - - if (Helper.isPlayStoreInstall(this)) { - BillingFlowParams flowParams = BillingFlowParams.newBuilder() - .setSku(BuildConfig.APPLICATION_ID + ".pro") - .setType(BillingClient.SkuType.INAPP) - .build(); - int responseCode = billingClient.launchBillingFlow(ActivityView.this, flowParams); - String text = Helper.getBillingResponseText(responseCode); - Log.i(Helper.TAG, "IAB launch billing flow response=" + text); - if (responseCode != BillingClient.BillingResponse.OK) - Snackbar.make(view, text, Snackbar.LENGTH_LONG).show(); - } else - startActivity(getIntentPro()); + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro"); + fragmentTransaction.commit(); } private void onMenuPrivacy() { @@ -641,6 +628,8 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack onEditFolder(intent); else if (ACTION_STORE_ATTACHMENT.equals(intent.getAction())) onStoreAttachment(intent); + else if (ACTION_PURCHASE.equals(intent.getAction())) + onPurchase(intent); else if (ACTION_ACTIVATE_PRO.equals(intent.getAction())) onActivatePro(intent); } @@ -713,6 +702,21 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack startActivityForResult(create, REQUEST_ATTACHMENT); } + private void onPurchase(Intent intent) { + if (Helper.isPlayStoreInstall(this)) { + BillingFlowParams flowParams = BillingFlowParams.newBuilder() + .setSku(BuildConfig.APPLICATION_ID + ".pro") + .setType(BillingClient.SkuType.INAPP) + .build(); + int responseCode = billingClient.launchBillingFlow(ActivityView.this, flowParams); + String text = Helper.getBillingResponseText(responseCode); + Log.i(Helper.TAG, "IAB launch billing flow response=" + text); + if (responseCode != BillingClient.BillingResponse.OK) + Snackbar.make(view, text, Snackbar.LENGTH_LONG).show(); + } else + startActivity(getIntentPro()); + } + private void onActivatePro(Intent intent) { try { Uri data = intent.getParcelableExtra("uri"); diff --git a/app/src/main/java/eu/faircode/email/FragmentPro.java b/app/src/main/java/eu/faircode/email/FragmentPro.java new file mode 100644 index 00000000..5b9e4f7f --- /dev/null +++ b/app/src/main/java/eu/faircode/email/FragmentPro.java @@ -0,0 +1,91 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NetGuard is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NetGuard. If not, see . + + Copyright 2018 by Marcel Bokhorst (M66B) +*/ + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.text.Html; +import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; + +public class FragmentPro extends FragmentEx implements SharedPreferences.OnSharedPreferenceChangeListener { + private TextView tvActivated; + private TextView tvList; + private Button btnPurchase; + + @Override + @Nullable + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + setSubtitle(R.string.menu_pro); + + View view = inflater.inflate(R.layout.fragment_pro, container, false); + + tvActivated = view.findViewById(R.id.tvActivated); + tvList = view.findViewById(R.id.tvList); + btnPurchase = view.findViewById(R.id.btnPurchase); + + tvList.setText(Html.fromHtml("" + Html.escapeHtml(getString(R.string.title_pro_list)) + "")); + tvList.setMovementMethod(LinkMovementMethod.getInstance()); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + onSharedPreferenceChanged(prefs, "pro"); + + btnPurchase.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast(new Intent(ActivityView.ACTION_PURCHASE)); + } + }); + + return view; + } + + @Override + public void onResume() { + super.onResume(); + PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if ("pro".equals(key)) { + boolean pro = prefs.getBoolean(key, false); + tvActivated.setVisibility(pro ? View.VISIBLE : View.GONE); + btnPurchase.setEnabled(!pro); + } + } +} diff --git a/app/src/main/res/layout/fragment_pro.xml b/app/src/main/res/layout/fragment_pro.xml new file mode 100644 index 00000000..2abbdaf3 --- /dev/null +++ b/app/src/main/res/layout/fragment_pro.xml @@ -0,0 +1,51 @@ + + + + + + + + + +