Added pro fragment

This commit is contained in:
M66B 2018-08-26 06:11:06 +00:00
parent 6ea780d524
commit b9ceb5bfa5
4 changed files with 167 additions and 18 deletions

View File

@ -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");

View File

@ -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 <http://www.gnu.org/licenses/>.
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("<a href=\"https://email.faircode.eu/\">" + Html.escapeHtml(getString(R.string.title_pro_list)) + "</a>"));
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);
}
}
}

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp">
<TextView
android:id="@+id/tvActivated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_pro_activated"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_pro_list"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvActivated" />
<Button
android:id="@+id/btnPurchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_pro_purchase"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvList" />
<TextView
android:id="@+id/tvHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_pro_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnPurchase" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -181,6 +181,9 @@
<string name="title_legend_closing">Closing</string>
<string name="title_pro_feature">This is a pro feature</string>
<string name="title_pro_list">List of pro features</string>
<string name="title_pro_purchase">Buy</string>
<string name="title_pro_hint">Buying pro features will allow you to use all current and future pro features and will keep this app maintained and supported</string>
<string name="title_pro_activated">All pro features are activated</string>
<string name="title_pro_valid">All pro features activated</string>
<string name="title_pro_invalid">Invalid response</string>