Skip to content

Instantly share code, notes, and snippets.

@parallelcross
Created September 8, 2014 19:24
Show Gist options
  • Save parallelcross/d633dc7af369d7604b62 to your computer and use it in GitHub Desktop.
Save parallelcross/d633dc7af369d7604b62 to your computer and use it in GitHub Desktop.
package com.mozu.mozuandroidinstoreassistant.app.loaders;
import com.mozu.api.MozuApiContext;
import com.mozu.api.contracts.productadmin.LocationInventoryCollection;
import com.mozu.api.contracts.productruntime.Product;
import com.mozu.api.resources.commerce.catalog.admin.products.LocationInventoryResource;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class InventoryRetriever {
public Observable<LocationInventoryCollection> getInventoryData(final Product product, int tenantId, int siteId) {
final LocationInventoryResource inventoryResource = new LocationInventoryResource(new MozuApiContext(tenantId, siteId));
return Observable
.create(new Observable.OnSubscribe<LocationInventoryCollection>() {
@Override
public void call(Subscriber<? super LocationInventoryCollection> subscriber) {
try {
subscriber.onNext(inventoryResource.getLocationInventories(product.getProductCode()));
subscriber.onCompleted();
} catch (Exception e) {
subscriber.onError(e);
}
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io());
}
}
package com.mozu.mozuandroidinstoreassistant.app.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.mozu.api.contracts.productadmin.LocationInventory;
import com.mozu.mozuandroidinstoreassistant.app.R;
import java.util.List;
public class ProdDetailLocationInventoryAdapter extends ArrayAdapter<LocationInventory> {
private Integer mTenantId;
private Integer mSiteId;
public ProdDetailLocationInventoryAdapter(Context context, List<LocationInventory> locationInventories,Integer tenantId,Integer siteID) {
super(context, R.layout.inventory_list_item);
mTenantId = tenantId;
mSiteId = siteID;
addAll(locationInventories);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ProdDetailInventoryViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.inventory_list_item, parent, false);
viewHolder = new ProdDetailInventoryViewHolder(convertView, mTenantId, mSiteId);
convertView.setTag(viewHolder);
} else {
viewHolder = (ProdDetailInventoryViewHolder) convertView.getTag();
}
LocationInventory locationInventory = getItem(position);
viewHolder.code.setText(locationInventory.getLocationCode());
viewHolder.available.setText( String.valueOf(locationInventory.getStockAvailable()));
viewHolder.onHand.setText(locationInventory.getStockOnHand().toString());
viewHolder.onReserve.setText(locationInventory.getStockOnBackOrder().toString());
viewHolder.name.loadName(locationInventory.getLocationCode());
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment