Search in sources :

Example 1 with IabResult

use of me.ccrama.redditslide.util.IabResult 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(" " + String.valueOf((double) newValue / 10) + " ");
            money.setText("$" + newValue);
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ads.setText(" " + 4 * 330 + " ");
    hours.setText(" " + String.valueOf((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 AlertDialogWrapper.Builder(DonateView.this).setTitle("Thank you!").setMessage("Thank you very much for your support :)").setPositiveButton(R.string.btn_done, null).show();
                                    } else {
                                        new AlertDialogWrapper.Builder(DonateView.this).setTitle("Uh oh, something went wrong.").setMessage("Please try again soon! Sorry for the inconvenience.").setPositiveButton("Ok", null).show();
                                    }
                                }
                            });
                        } else {
                            LogUtil.v("Null");
                        }
                    } else {
                        new AlertDialogWrapper.Builder(DonateView.this).setTitle("Uh oh, something went wrong.").setMessage("Please try again soon! Sorry for the inconvenience.").setPositiveButton("Ok", null).show();
                    }
                }
            });
        }
    });
}
Also used : Window(android.view.Window) SkuDetails(me.ccrama.redditslide.util.SkuDetails) Purchase(me.ccrama.redditslide.util.Purchase) Slider(com.rey.material.widget.Slider) IabResult(me.ccrama.redditslide.util.IabResult) TextView(android.widget.TextView) View(android.view.View) IabHelper(me.ccrama.redditslide.util.IabHelper) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) Inventory(me.ccrama.redditslide.util.Inventory) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 Window (android.view.Window)1 TextView (android.widget.TextView)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1 Slider (com.rey.material.widget.Slider)1 IabHelper (me.ccrama.redditslide.util.IabHelper)1 IabResult (me.ccrama.redditslide.util.IabResult)1 Inventory (me.ccrama.redditslide.util.Inventory)1 Purchase (me.ccrama.redditslide.util.Purchase)1 SkuDetails (me.ccrama.redditslide.util.SkuDetails)1