Search in sources :

Example 1 with SkuDetails

use of me.ccrama.redditslide.util.billing.SkuDetails in project Slide by ccrama.

the class DonateView method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_donate);
    Toolbar t = (Toolbar) findViewById(R.id.toolbar);
    t.setTitle(R.string.settings_title_support);
    setRecentBar(getString(R.string.settings_title_support), Palette.getDarkerColor(ContextCompat.getColor(DonateView.this, R.color.md_light_green_500)));
    setSupportActionBar(t);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Palette.getDarkerColor(ContextCompat.getColor(DonateView.this, R.color.md_light_green_500)));
        if (SettingValues.colorNavBar) {
            window.setNavigationBarColor(Palette.getDarkerColor(ContextCompat.getColor(DonateView.this, R.color.md_light_green_500)));
        }
    }
    final Slider slider = (Slider) findViewById(R.id.slider_sl_discrete);
    slider.setValue(4, false);
    final TextView ads = (TextView) findViewById(R.id.ads);
    final TextView hours = (TextView) findViewById(R.id.hours);
    final TextView money = (TextView) findViewById(R.id.money);
    slider.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {

        @Override
        public void onPositionChanged(Slider view, boolean fromUser, float oldPos, float newPos, int oldValue, int newValue) {
            ads.setText(" " + newValue * 330 + " ");
            hours.setText(" " + (double) newValue / 10 + " ");
            money.setText("$" + newValue);
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ads.setText(" " + 4 * 330 + " ");
    hours.setText(" " + (double) 4 / 10 + " ");
    money.setText("$" + 4);
    findViewById(R.id.donate).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String name = "";
            if (Authentication.isLoggedIn) {
                name = Authentication.name;
            }
            if (Reddit.mHelper != null) {
                Reddit.mHelper.flagEndAsync();
            }
            Reddit.mHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {

                @Override
                public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                    if (inv != null) {
                        SkuDetails donation = inv.getSkuDetails("donation_" + slider.getValue());
                        LogUtil.v("Trying to get donation_" + slider.getValue());
                        if (donation != null) {
                            LogUtil.v("Not null");
                            Reddit.mHelper.launchPurchaseFlow(DonateView.this, donation.getSku(), 4000, new IabHelper.OnIabPurchaseFinishedListener() {

                                @Override
                                public void onIabPurchaseFinished(IabResult result, Purchase info) {
                                    if (result.isSuccess()) {
                                        new AlertDialog.Builder(DonateView.this).setTitle("Thank you!").setMessage("Thank you very much for your support :)").setPositiveButton(R.string.btn_done, null).show();
                                    } else {
                                        new AlertDialog.Builder(DonateView.this).setTitle(R.string.err_something_wrong).setMessage("Please try again soon! Sorry for the inconvenience.").setPositiveButton(android.R.string.ok, null).show();
                                    }
                                }
                            });
                        } else {
                            LogUtil.v("Null");
                        }
                    } else {
                        new AlertDialog.Builder(DonateView.this).setTitle(R.string.err_something_wrong).setMessage("Please try again soon! Sorry for the inconvenience.").setPositiveButton(android.R.string.ok, null).show();
                    }
                }
            });
        }
    });
}
Also used : Window(android.view.Window) SkuDetails(me.ccrama.redditslide.util.billing.SkuDetails) AlertDialog(androidx.appcompat.app.AlertDialog) Purchase(me.ccrama.redditslide.util.billing.Purchase) Slider(com.rey.material.widget.Slider) IabResult(me.ccrama.redditslide.util.billing.IabResult) TextView(android.widget.TextView) View(android.view.View) IabHelper(me.ccrama.redditslide.util.billing.IabHelper) TextView(android.widget.TextView) Inventory(me.ccrama.redditslide.util.billing.Inventory) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

View (android.view.View)1 Window (android.view.Window)1 TextView (android.widget.TextView)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Toolbar (androidx.appcompat.widget.Toolbar)1 Slider (com.rey.material.widget.Slider)1 IabHelper (me.ccrama.redditslide.util.billing.IabHelper)1 IabResult (me.ccrama.redditslide.util.billing.IabResult)1 Inventory (me.ccrama.redditslide.util.billing.Inventory)1 Purchase (me.ccrama.redditslide.util.billing.Purchase)1 SkuDetails (me.ccrama.redditslide.util.billing.SkuDetails)1