Android Open Source - AndroidCouponAssistant Global Cart






From Project

Back to project page AndroidCouponAssistant.

License

The source code is released under:

MIT License

If you think the Android project AndroidCouponAssistant listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.corylucasjeffery.couponassistant;
//  ww w  .  jav a2s  . c  om
import android.app.Application;
import android.util.Log;

import java.util.ArrayList;


public class GlobalCart extends Application {
    private ArrayList<Coupon> couponsInCart = new ArrayList<Coupon>();
    private ArrayList<Item> itemsInCart = new ArrayList<Item>();
    private int cartSize = 0;
    private int cartIndex = 0;

    private final String TAG = "global";

    public boolean isEmpty() {
        return cartSize == 0;
    }

    public void addToCart(Coupon c, Item i) {
        couponsInCart.add(c);
        itemsInCart.add(i);
        cartSize++;
    }

    public void removeFromCart() {
        if(cartSize != 0)
        {
            Coupon c = getCurrentCoupon();
            Item i = getCurrentItem();
            couponsInCart.remove(c);
            itemsInCart.remove(i);
            cartSize--;
        }
    }

    public Coupon getNextCoupon() {
        Coupon returnC;
        if (cartIndex < cartSize-1) {
            returnC = couponsInCart.get(cartIndex);
            cartIndex++;
        }
        else {
            returnC = new Coupon("empty", "empty", "empty");
        }

        return returnC;
    }

    public Coupon getPreviousCoupon() {
        Coupon returnC;
        Log.v(TAG, "get prev cartSize: "+Integer.toString(cartSize)+" cartIndex: "+Integer.toString(cartIndex));
        if (cartIndex > 0) {
            returnC = couponsInCart.get(cartIndex);
            cartIndex--;
        }
        else {
            returnC = new Coupon("empty", "empty", "empty");
        }

        return returnC;
    }

    public Coupon getCurrentCoupon() {
        Coupon returnC;
        if (cartIndex >= 0 && cartIndex < cartSize) {
            returnC = couponsInCart.get(cartIndex);
        }
        else {
            returnC = new Coupon("empty", "empty", "empty");
        }

        return returnC;
    }

    public Item getCurrentItem() {
        Item returnI;
        if (cartIndex >= 0 && cartIndex < cartSize) {
            returnI = itemsInCart.get(cartIndex);
        }
        else {
            returnI = new Item("empty");
        }
        return returnI;
    }

    public void emptyCart() {
        cartIndex = 0;
        cartSize = 0;
        couponsInCart.clear();
        itemsInCart.clear();
    }
}




Java Source Code List

com.corylucasjeffery.couponassistant.BMPtoBlob.java
com.corylucasjeffery.couponassistant.BarcodeGenerator.java
com.corylucasjeffery.couponassistant.BlobtoBMP.java
com.corylucasjeffery.couponassistant.CameraPreview.java
com.corylucasjeffery.couponassistant.CouponAdapter.java
com.corylucasjeffery.couponassistant.Coupon.java
com.corylucasjeffery.couponassistant.DateChooserDialog.java
com.corylucasjeffery.couponassistant.DbGetCoupons.java
com.corylucasjeffery.couponassistant.DbPurchaseItem.java
com.corylucasjeffery.couponassistant.DbSubmitCoupon.java
com.corylucasjeffery.couponassistant.DbSubmitItem.java
com.corylucasjeffery.couponassistant.DbUserRegister.java
com.corylucasjeffery.couponassistant.DbUserStats.java
com.corylucasjeffery.couponassistant.GlobalCart.java
com.corylucasjeffery.couponassistant.Item.java
com.corylucasjeffery.couponassistant.ManualEntryDialog.java
com.corylucasjeffery.couponassistant.ParseUPC.java
com.corylucasjeffery.couponassistant.PhpWrapper.java
com.corylucasjeffery.couponassistant.ProgressBarHelper.java
com.corylucasjeffery.couponassistant.Statistics.java
com.corylucasjeffery.couponassistant.UserInfo.java
com.corylucasjeffery.couponassistant.ValueCodeDict.java
com.corylucasjeffery.couponassistant.activities.AndroidBarcodeView.java
com.corylucasjeffery.couponassistant.activities.CheckoutActivity.java
com.corylucasjeffery.couponassistant.activities.LoginActivity.java
com.corylucasjeffery.couponassistant.activities.MainActivity.java
com.corylucasjeffery.couponassistant.activities.SettingsActivity.java
com.corylucasjeffery.couponassistant.activities.ShowCouponsActivity.java
com.corylucasjeffery.couponassistant.activities.StatisticsActivity.java
com.google.zxing.integration.android.IntentIntegrator.java
com.google.zxing.integration.android.IntentResult.java