Allow entering response code manually

This commit is contained in:
M66B 2020-08-25 10:04:25 +02:00
parent b770e11365
commit 0781b132b3
7 changed files with 112 additions and 4 deletions

View File

@ -169,8 +169,12 @@ public class ActivityBilling extends ActivityBase implements /*PurchasesUpdatedL
}
static boolean activatePro(Context context, Uri data) throws NoSuchAlgorithmException {
String challenge = getChallenge(context);
String response = data.getQueryParameter("response");
return activatePro(context, response);
}
static boolean activatePro(Context context, String response) throws NoSuchAlgorithmException {
String challenge = getChallenge(context);
Log.i("IAB challenge=" + challenge);
Log.i("IAB response=" + response);
String expected = getResponse(context);

View File

@ -4051,7 +4051,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
else
ToastEx.makeText(context, R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
} catch (NoSuchAlgorithmException ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
Log.e(ex);
ToastEx.makeText(context, Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
}
} else {
if ("full".equals(uri.getScheme())) {

View File

@ -19,22 +19,29 @@ package eu.faircode.email;
Copyright 2018-2020 by Marcel Bokhorst (M66B)
*/
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
@ -57,6 +64,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_pro);
setHasOptionsMenu(true);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean debug = prefs.getBoolean("debug", false);
@ -220,6 +228,56 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_pro, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
menu.findItem(R.id.menu_response).setVisible(!Helper.isPlayStoreInstall());
super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_response:
onMenuResponse();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuResponse() {
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_response, null);
final EditText etResponse = dview.findViewById(R.id.etResponse);
new AlertDialog.Builder(getContext())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
String response = etResponse.getText().toString().trim();
int q = response.indexOf("?response=");
if (q > 0)
response = response.substring(q + 10);
if (ActivityBilling.activatePro(getContext(), response))
ToastEx.makeText(getContext(), R.string.title_pro_valid, Toast.LENGTH_LONG).show();
else
ToastEx.makeText(getContext(), R.string.title_pro_invalid, Toast.LENGTH_LONG).show();
} catch (Throwable ex) {
Log.e(ex);
ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
}
}
})
.show();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("pro".equals(key)) {

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
android:padding="24dp">
<eu.faircode.email.FixedTextView
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/etPin"
android:text="@string/title_pro_response"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etResponse"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:inputType="text"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvCaption">
<requestFocus />
</eu.faircode.email.EditTextPlain>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_response"
android:title="@string/title_pro_response"
app:showAsAction="never" />
</menu>

View File

@ -1351,6 +1351,7 @@
<string name="title_pro_price">Why are the pro features so expensive?</string>
<string name="title_pro_restore">How can I restore a purchase?</string>
<string name="title_pro_pending">Purchase pending</string>
<string name="title_pro_response" translatable="false">Response</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>

View File

@ -165,12 +165,16 @@ public class ActivityBilling extends ActivityBase implements PurchasesUpdatedLis
}
private static String getResponse(Context context) throws NoSuchAlgorithmException {
return Helper.sha256(BuildConfig.APPLICATION_ID + getChallenge(context));
return Helper.sha256(BuildConfig.APPLICATION_ID.replace(".debug", "") + getChallenge(context));
}
static boolean activatePro(Context context, Uri data) throws NoSuchAlgorithmException {
String challenge = getChallenge(context);
String response = data.getQueryParameter("response");
return activatePro(context, response);
}
static boolean activatePro(Context context, String response) throws NoSuchAlgorithmException {
String challenge = getChallenge(context);
Log.i("IAB challenge=" + challenge);
Log.i("IAB response=" + response);
String expected = getResponse(context);