remove purchase activity
This commit is contained in:
parent
4b02fb2b5f
commit
0891555785
38 changed files with 3 additions and 587 deletions
|
|
@ -33,8 +33,6 @@ public class App extends Application {
|
|||
private static App app;
|
||||
private static ApiClient apiClient;
|
||||
|
||||
private BillingProcessor billingProcessor;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
|
@ -42,39 +40,13 @@ public class App extends Application {
|
|||
|
||||
// default theme
|
||||
if (!ThemeStore.isConfigured(this, 1)) {
|
||||
ThemeStore.editTheme(this)
|
||||
.primaryColorRes(R.color.md_indigo_500)
|
||||
.accentColorRes(R.color.md_pink_A400)
|
||||
.commit();
|
||||
ThemeStore.editTheme(this).primaryColorRes(R.color.md_indigo_500).accentColorRes(R.color.md_pink_A400).commit();
|
||||
}
|
||||
|
||||
// dynamic shortcuts
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
new DynamicShortcutManager(this).initDynamicShortcuts();
|
||||
}
|
||||
|
||||
// automatically restore purchases
|
||||
billingProcessor = new BillingProcessor(this, App.GOOGLE_PLAY_LICENSE_KEY, new BillingProcessor.IBillingHandler() {
|
||||
@Override
|
||||
public void onProductPurchased(@NonNull String productId, TransactionDetails details) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseHistoryRestored() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingError(int errorCode, Throwable error) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingInitialized() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isProVersion() {
|
||||
return BuildConfig.DEBUG || app.billingProcessor.isPurchased(PRO_VERSION_PRODUCT_ID);
|
||||
}
|
||||
|
||||
public static ConnectionManager getConnectionManager(Context context, IJsonSerializer jsonSerializer, ILogger logger, IAsyncHttpClient httpClient) {
|
||||
|
|
@ -99,10 +71,4 @@ public class App extends Application {
|
|||
public static App getInstance() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
billingProcessor.release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ import android.widget.Toast;
|
|||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.afollestad.materialdialogs.internal.ThemeSingleton;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.PurchaseActivity;
|
||||
import com.kabouzeid.gramophone.util.MusicUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.triggertrap.seekarc.SeekArc;
|
||||
|
|
@ -63,11 +61,6 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (!App.isProVersion()) {
|
||||
Toast.makeText(getActivity(), getString(R.string.sleep_timer_is_a_pro_feature), Toast.LENGTH_LONG).show();
|
||||
startActivity(new Intent(getContext(), PurchaseActivity.class));
|
||||
return;
|
||||
}
|
||||
|
||||
PreferenceUtil.getInstance(getActivity()).setSleepTimerFinishMusic(shouldFinishLastSong.isChecked());
|
||||
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ public class AboutActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
|
||||
private static String getCurrentVersionName(@NonNull final Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName + (App.isProVersion() ? " Pro" : "");
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -184,11 +184,7 @@ public class AboutActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
} else if (v == rateOnGooglePlay) {
|
||||
openUrl(RATE_ON_GOOGLE_PLAY);
|
||||
} else if (v == donate) {
|
||||
if (App.isProVersion()) {
|
||||
DonationsDialog.create().show(getSupportFragmentManager(), "DONATION_DIALOG");
|
||||
} else {
|
||||
startActivity(new Intent(this, PurchaseActivity.class));
|
||||
}
|
||||
DonationsDialog.create().show(getSupportFragmentManager(), "DONATION_DIALOG");
|
||||
} else if (v == aidanFollestadGooglePlus) {
|
||||
openUrl(AIDAN_FOLLESTAD_GOOGLE_PLUS);
|
||||
} else if (v == aidanFollestadGitHub) {
|
||||
|
|
|
|||
|
|
@ -1,175 +0,0 @@
|
|||
package com.kabouzeid.gramophone.ui.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.anjlab.android.iab.v3.BillingProcessor;
|
||||
import com.anjlab.android.iab.v3.TransactionDetails;
|
||||
import com.kabouzeid.appthemehelper.color.MaterialColor;
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class PurchaseActivity extends AbsBaseActivity implements BillingProcessor.IBillingHandler {
|
||||
|
||||
public static final String TAG = PurchaseActivity.class.getSimpleName();
|
||||
|
||||
private static final int ACTIVITY_COLOR = MaterialColor.Green._500.getAsColor();
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.restore_button)
|
||||
Button restoreButton;
|
||||
@BindView(R.id.purchase_button)
|
||||
Button purchaseButton;
|
||||
|
||||
private BillingProcessor billingProcessor;
|
||||
private AsyncTask restorePurchaseAsyncTask;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_purchase);
|
||||
setDrawUnderStatusbar();
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setStatusbarColor(ACTIVITY_COLOR);
|
||||
setNavigationbarColor(ACTIVITY_COLOR);
|
||||
setTaskDescriptionColor(ACTIVITY_COLOR);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setTitle(getString(R.string.app_name));
|
||||
|
||||
restoreButton.setEnabled(false);
|
||||
purchaseButton.setEnabled(false);
|
||||
|
||||
restoreButton.setOnClickListener(v -> {
|
||||
if (restorePurchaseAsyncTask == null || restorePurchaseAsyncTask.getStatus() != AsyncTask.Status.RUNNING) {
|
||||
restorePurchase();
|
||||
}
|
||||
});
|
||||
|
||||
purchaseButton.setOnClickListener(v -> {
|
||||
billingProcessor.purchase(PurchaseActivity.this, App.PRO_VERSION_PRODUCT_ID);
|
||||
});
|
||||
|
||||
billingProcessor = new BillingProcessor(this, App.GOOGLE_PLAY_LICENSE_KEY, this);
|
||||
}
|
||||
|
||||
private void restorePurchase() {
|
||||
if (restorePurchaseAsyncTask != null) {
|
||||
restorePurchaseAsyncTask.cancel(false);
|
||||
}
|
||||
restorePurchaseAsyncTask = new RestorePurchaseAsyncTask(this).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
|
||||
Toast.makeText(this, R.string.thank_you, Toast.LENGTH_SHORT).show();
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseHistoryRestored() {
|
||||
if (App.isProVersion()) {
|
||||
Toast.makeText(this, R.string.restored_previous_purchase_please_restart, Toast.LENGTH_LONG).show();
|
||||
setResult(RESULT_OK);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.no_purchase_found, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingError(int errorCode, @Nullable Throwable error) {
|
||||
Log.e(TAG, "Billing error: code = " + errorCode, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingInitialized() {
|
||||
restoreButton.setEnabled(true);
|
||||
purchaseButton.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (!billingProcessor.handleActivityResult(requestCode, resultCode, data)) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (billingProcessor != null) {
|
||||
billingProcessor.release();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private static class RestorePurchaseAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private final WeakReference<PurchaseActivity> buyActivityWeakReference;
|
||||
|
||||
public RestorePurchaseAsyncTask(PurchaseActivity purchaseActivity) {
|
||||
this.buyActivityWeakReference = new WeakReference<>(purchaseActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
PurchaseActivity purchaseActivity = buyActivityWeakReference.get();
|
||||
if (purchaseActivity != null) {
|
||||
Toast.makeText(purchaseActivity, R.string.restoring_purchase, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
PurchaseActivity purchaseActivity = buyActivityWeakReference.get();
|
||||
if (purchaseActivity != null) {
|
||||
return purchaseActivity.billingProcessor.loadOwnedPurchasesFromGoogle();
|
||||
}
|
||||
cancel(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean b) {
|
||||
super.onPostExecute(b);
|
||||
PurchaseActivity purchaseActivity = buyActivityWeakReference.get();
|
||||
if (purchaseActivity == null || b == null) return;
|
||||
|
||||
if (b) {
|
||||
purchaseActivity.onPurchaseHistoryRestored();
|
||||
} else {
|
||||
Toast.makeText(purchaseActivity, R.string.could_not_restore_purchase, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -159,16 +159,9 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
setSummary(generalTheme);
|
||||
generalTheme.setOnPreferenceChangeListener((preference, o) -> {
|
||||
String themeName = (String) o;
|
||||
if (themeName.equals("black") && !App.isProVersion()) {
|
||||
Toast.makeText(getActivity(), R.string.black_theme_is_a_pro_feature, Toast.LENGTH_LONG).show();
|
||||
startActivity(new Intent(getContext(), PurchaseActivity.class));
|
||||
return false;
|
||||
}
|
||||
|
||||
setSummary(generalTheme, o);
|
||||
|
||||
ThemeStore.markChanged(getActivity());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
// Set the new theme so that updateAppShortcuts can pull it
|
||||
getActivity().setTheme(PreferenceUtil.getThemeResFromPrefValue(themeName));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue