mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-04 16:16:33 +02:00
Allow entering response code manually
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user