use of com.zype.android.Billing.Subscription in project zype-android by zype.
the class SubscribeOrLoginActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case REQUEST_CONSUMER:
if (resultCode == RESULT_OK) {
List<Purchase> purchases = ZypeApp.marketplaceGateway.getBillingManager().getPurchases();
if (purchases != null && purchases.size() > 0) {
Subscription subscription = ZypeApp.marketplaceGateway.findSubscriptionBySku(purchases.get(0).getSku());
if (subscription != null) {
showProgress();
ZypeApp.marketplaceGateway.verifySubscription(subscription).observe(this, new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean result) {
hideProgress();
if (result) {
setResult(RESULT_OK);
finish();
} else {
DialogHelper.showErrorAlert(SubscribeOrLoginActivity.this, getString(R.string.subscribe_or_login_error_validation));
}
}
});
} else {
Logger.e("Not found Zype Plan for existing in-app purchase, sku=" + purchases.get(0).getSku());
DialogHelper.showErrorAlert(this, getString(R.string.subscribe_or_login_error_restore_purchase_zype));
}
/*for (String itemSku : purchases.get(0).getSkus()){
Subscription subscription = ZypeApp.marketplaceGateway.findSubscriptionBySku(itemSku);
if (subscription != null) {
showProgress();
ZypeApp.marketplaceGateway.verifySubscription(subscription).observe(this, new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean result) {
hideProgress();
if (result) {
setResult(RESULT_OK);
finish();
}
else {
DialogHelper.showErrorAlert(SubscribeOrLoginActivity.this,
getString(R.string.subscribe_or_login_error_validation));
}
}
});
}
else {
Logger.e("Not found Zype Plan for existing in-app purchase, sku=" + itemSku);
DialogHelper.showErrorAlert(this, getString(R.string.subscribe_or_login_error_restore_purchase_zype));
}
}*/
} else {
NavigationHelper.getInstance(this).switchToSubscriptionScreen(this, getIntent().getExtras());
}
} else {
// onCancel();
}
break;
case REQUEST_LOGIN:
if (resultCode == RESULT_OK) {
if (SubscriptionHelper.hasSubscription()) {
NavigationHelper.getInstance(this).switchToVideoDetailsScreen(this, getIntent().getExtras().getString(BundleConstants.VIDEO_ID), getIntent().getExtras().getString(BundleConstants.PLAYLIST_ID), false);
finish();
} else {
NavigationHelper.getInstance(this).switchToSubscriptionScreen(this, getIntent().getExtras());
}
} else {
// onCancel();
}
break;
case REQUEST_SUBSCRIPTION:
if (resultCode == RESULT_OK) {
NavigationHelper.getInstance(this).switchToVideoDetailsScreen(this, getIntent().getExtras().getString(BundleConstants.VIDEO_ID), getIntent().getExtras().getString(BundleConstants.PLAYLIST_ID), false);
finish();
} else {
// onCancel();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
use of com.zype.android.Billing.Subscription in project zype-android by zype.
the class SubscriptionActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subscription);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.subscription_title);
initParameters(savedInstanceState);
listSubscriptions = findViewById(R.id.listSubscriptions);
adapter = new SubscriptionsAdapter();
listSubscriptions.setAdapter(adapter);
layoutLogin = findViewById(R.id.layoutLogin);
buttonLogin = findViewById(R.id.buttonLogin);
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NavigationHelper.getInstance(SubscriptionActivity.this).switchToLoginScreen(SubscriptionActivity.this);
}
});
layoutLoggedIn = findViewById(R.id.layoutLoggedIn);
textUsername = findViewById(R.id.textUsername);
ZypeApp.marketplaceGateway.getSubscriptions().observe(this, new Observer<Map<String, Subscription>>() {
@Override
public void onChanged(@Nullable Map<String, Subscription> subscriptions) {
Log.d("BillingManager", "getSubscriptions: observe: " + subscriptions);
List<Subscription> subscriptionList = new ArrayList<>();
for (Map.Entry<String, Subscription> entry : subscriptions.entrySet()) {
Log.d("BillingManager", "getSubscriptions: map: " + entry.getValue().getMarketplace());
if (entry.getValue().getMarketplace() != null) {
subscriptionList.add(entry.getValue());
}
}
adapter.setData(subscriptionList);
}
});
billingManager = new BillingManager(this, this);
hideProgress();
updateViews();
}
use of com.zype.android.Billing.Subscription in project zype-android by zype.
the class SubscribeOrLoginFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_subscribe_or_login, container, false);
final NavigationHelper navigationHelper = NavigationHelper.getInstance(getActivity());
TextView textTitle = rootView.findViewById(R.id.textTitle);
textTitle.setText(String.format(getString(R.string.subscribe_or_login_title), getString(R.string.app_name)));
Button buttonSubscribe = rootView.findViewById(R.id.buttonSubscribe);
buttonSubscribe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (AuthHelper.isLoggedIn()) {
navigationHelper.switchToSubscriptionScreen(getActivity(), getActivity().getIntent().getExtras());
} else {
navigationHelper.switchToConsumerScreen(getActivity());
}
}
});
Button buttonLogin = rootView.findViewById(R.id.buttonLogin);
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
navigationHelper.switchToLoginScreen(getActivity(), null);
}
});
final List<Purchase> purchases = ZypeApp.marketplaceGateway.getBillingManager().getPurchases();
Button buttonRestorePurchases = rootView.findViewById(R.id.buttonRestorePurchases);
buttonRestorePurchases.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (AuthHelper.isLoggedIn()) {
// Get first purchase from the purchase list and try to validate it
Subscription subscription = ZypeApp.marketplaceGateway.findSubscriptionBySku(purchases.get(0).getSku());
if (subscription != null) {
showProgress(getString(R.string.subscription_verify));
ZypeApp.marketplaceGateway.verifySubscription(subscription).observe(SubscribeOrLoginFragment.this, new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean result) {
hideProgress();
if (result) {
getActivity().setResult(RESULT_OK);
getActivity().finish();
} else {
DialogHelper.showErrorAlert(getActivity(), getString(R.string.subscribe_or_login_error_validation));
}
}
});
} else {
Logger.e("Not found Zype Plan for existing in-app purchase, sku=" + purchases.get(0).getSku());
DialogHelper.showErrorAlert(getActivity(), getString(R.string.subscribe_or_login_error_restore_purchase_zype));
}
/*for (String itemSku : purchases.get(0).getSkus()){
Subscription subscription = ZypeApp.marketplaceGateway.findSubscriptionBySku(itemSku);
if (subscription != null) {
showProgress(getString(R.string.subscription_verify));
ZypeApp.marketplaceGateway.verifySubscription(subscription).observe(SubscribeOrLoginFragment.this, new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean result) {
hideProgress();
if (result) {
getActivity().setResult(RESULT_OK);
getActivity().finish();
}
else {
DialogHelper.showErrorAlert(getActivity(),
getString(R.string.subscribe_or_login_error_validation));
}
}
});
}
else {
Logger.e("Not found Zype Plan for existing in-app purchase, sku=" + itemSku);
DialogHelper.showErrorAlert(getActivity(), getString(R.string.subscribe_or_login_error_restore_purchase_zype));
}
}*/
} else {
navigationHelper.switchToConsumerScreen(getActivity());
}
}
});
if (purchases != null && purchases.size() > 0) {
Logger.d("There are purchases, size=" + purchases.size());
buttonRestorePurchases.setVisibility(View.VISIBLE);
} else {
Logger.d("There are no purchases on the device");
buttonRestorePurchases.setVisibility(View.GONE);
}
api.subscribe(this);
return rootView;
}
Aggregations