package org.deke.risk.riskahead;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.widget.Button;

import com.android.vending.billing.IInAppBillingService;

import org.deke.risk.riskahead.helper.BaseActivity;


public class SubscriptionsActivity extends BaseActivity implements ServiceConnection{

    private final static String mActivityTitle = "Subscriptions";
    private final static String TAG = StartActivity.class.getSimpleName();

    private Button btnPurchaseNoAds;
    private Button btnPurchaseExtraFunctions;

    IInAppBillingService mService;
    ServiceConnection mServiceConn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userHasToBeLoggedIn();

        btnPurchaseNoAds = (Button) findViewById(R.id.btn_subscription_1);
        btnPurchaseExtraFunctions = (Button) findViewById(R.id.btn_subscription_2);

        //Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
       // serviceIntent.setPackage("com.android.vending");
        //bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

       // Bundle activeSubs = mService.getPurchases(3, "org.deke.risk.riskahead", "subs", continueToken);

        btnPurchaseNoAds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*
                Bundle bundle = mService.getBuyIntent(3, "org.deke.risk.riskahead",MY_SKU, "subs", developerPayload);

                PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
                if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
                    // Start purchase flow (this brings up the Google Play UI).
                    // Result will be delivered through onActivityResult().
                    startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
                            Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                }
                */
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        navDrawer.setSelection(subscriptionsAvtivityID, false);
    }



    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_subscriptions;
    }

    @Override
    protected String getActivityName() { return mActivityTitle; }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        mService = IInAppBillingService.Stub.asInterface(service);
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mService = null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mService != null) {
            unbindService(mServiceConn);
        }
    }
}
