Search in sources :

Example 1 with Product

use of com.github.asifmujteba.easyvolleysample.Models.Product in project EasyVolley by asifmujteba.

the class ProductsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    productsAdapter = new ProductsAdapter(mContext, new ArrayList<Product>());
    gridView.setEmptyView(emptyElement);
    gridView.setAdapter(productsAdapter);
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Product product = productsAdapter.getItem(position);
            DetailsActivity.launch(mContext, product, (ImageView) view.findViewById(R.id.imageView));
        }
    });
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            loadProducts();
        }
    });
    loadProducts();
}
Also used : ArrayList(java.util.ArrayList) Product(com.github.asifmujteba.easyvolleysample.Models.Product) GridView(android.widget.GridView) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ProductsAdapter(com.github.asifmujteba.easyvolleysample.UI.adapters.ProductsAdapter) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView)

Example 2 with Product

use of com.github.asifmujteba.easyvolleysample.Models.Product in project EasyVolley by asifmujteba.

the class ServerController method getWomenClothingProducts.

public void getWomenClothingProducts(Object subscriber, final OnServerResponseListener<ArrayList<Product>> listener) {
    EasyVolley.withGlobalQueue().load(URLWomenClothing).addParam("p1", "something").asJsonObject().setSubscriber(subscriber).setCallback(new ASFRequestListener<JsonObject>() {

        @Override
        public void onSuccess(JsonObject response) {
            JsonArray results = response.get("metadata").getAsJsonObject().getAsJsonArray("results");
            ArrayList<Product> products = Product.parseJsonArray(results);
            if (listener != null) {
                listener.onSuccess(products);
            }
        }

        @Override
        public void onFailure(Exception e) {
            if (listener != null) {
                listener.onError(e);
            }
        }
    }).start();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Product(com.github.asifmujteba.easyvolleysample.Models.Product) ASFRequestListener(com.github.asifmujteba.easyvolley.ASFRequestListener)

Example 3 with Product

use of com.github.asifmujteba.easyvolleysample.Models.Product in project EasyVolley by asifmujteba.

the class ProductsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.item_product, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Product product = products.get(position);
    holder.lblTitle.setText(product.getData().getName());
    holder.lblPrice.setText("RM " + product.getData().getPrice());
    if (product.getImages().length > 0) {
        holder.imageView.setImageResource(R.mipmap.unknown);
        App.getInstance().getServerController().loadImage(product.getImages()[0].getPath() + "?thumb=1").setMaxWidth(375).setMaxHeight(375).setScaleType(ImageView.ScaleType.CENTER_INSIDE).into(holder.imageView).start();
    }
    return convertView;
}
Also used : Product(com.github.asifmujteba.easyvolleysample.Models.Product)

Aggregations

Product (com.github.asifmujteba.easyvolleysample.Models.Product)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 ASFRequestListener (com.github.asifmujteba.easyvolley.ASFRequestListener)1 ProductsAdapter (com.github.asifmujteba.easyvolleysample.UI.adapters.ProductsAdapter)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1