Added Filters support for Products
This commit is contained in:
parent
df5f1b0868
commit
256de109c3
@ -10,6 +10,7 @@ import me.gilo.wc.R
|
|||||||
import me.gilo.wc.adapter.ProductAdapter
|
import me.gilo.wc.adapter.ProductAdapter
|
||||||
import me.gilo.woodroid.Woocommerce
|
import me.gilo.woodroid.Woocommerce
|
||||||
import me.gilo.woodroid.models.Product
|
import me.gilo.woodroid.models.Product
|
||||||
|
import me.gilo.woodroid.models.filters.ProductFilter
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
@ -50,10 +51,10 @@ class ShopActivity : BaseActivity() {
|
|||||||
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e")
|
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val filters = HashMap<String, String>()
|
val filters = ProductFilter()
|
||||||
filters["search"] = "ship"
|
filters.per_page = 3
|
||||||
|
|
||||||
woocommerce.ProductRepository().filter(filters).enqueue(object : Callback<List<Product>> {
|
woocommerce.ProductRepository().products(filters).enqueue(object : Callback<List<Product>> {
|
||||||
override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) {
|
override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) {
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
|||||||
@ -47,4 +47,7 @@ dependencies {
|
|||||||
implementation 'io.reactivex:rxjava:1.3.0'
|
implementation 'io.reactivex:rxjava:1.3.0'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
|
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
|
||||||
|
|
||||||
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
package me.gilo.woodroid.models.filters;
|
||||||
|
|
||||||
|
public class ListFilter {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,335 @@
|
|||||||
|
package me.gilo.woodroid.models.filters;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ProductFilter{
|
||||||
|
String context;
|
||||||
|
int page;
|
||||||
|
int per_page;
|
||||||
|
String search;
|
||||||
|
String after;
|
||||||
|
String before;
|
||||||
|
int[] exclude;
|
||||||
|
int[] include;
|
||||||
|
int offset;
|
||||||
|
String order;
|
||||||
|
String orderby;
|
||||||
|
int[] parent;
|
||||||
|
int[] parent_exclude;
|
||||||
|
String slug;
|
||||||
|
String status;
|
||||||
|
String type;
|
||||||
|
String sku;
|
||||||
|
boolean featured;
|
||||||
|
String category;
|
||||||
|
String tag;
|
||||||
|
String shipping_class;
|
||||||
|
String attribute;
|
||||||
|
String attribute_term;
|
||||||
|
String tax_class;
|
||||||
|
boolean on_sale;
|
||||||
|
String min_price;
|
||||||
|
String max_price;
|
||||||
|
String stock_status;
|
||||||
|
|
||||||
|
Map<String, String> filters = new HashMap<>();
|
||||||
|
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(String context) {
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
addFilter("context", context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPage() {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPage(int page) {
|
||||||
|
this.page = page;
|
||||||
|
|
||||||
|
addFilter("page", page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPer_page() {
|
||||||
|
return per_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPer_page(int per_page) {
|
||||||
|
this.per_page = per_page;
|
||||||
|
|
||||||
|
addFilter("per_page", per_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSearch() {
|
||||||
|
return search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearch(String search) {
|
||||||
|
this.search = search;
|
||||||
|
|
||||||
|
addFilter("search", search);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAfter() {
|
||||||
|
return after;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAfter(String after) {
|
||||||
|
this.after = after;
|
||||||
|
|
||||||
|
addFilter("after", after);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBefore() {
|
||||||
|
return before;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBefore(String before) {
|
||||||
|
this.before = before;
|
||||||
|
|
||||||
|
addFilter("before", before);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getExclude() {
|
||||||
|
return exclude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExclude(int[] exclude) {
|
||||||
|
this.exclude = exclude;
|
||||||
|
|
||||||
|
addFilter("exclude", exclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getInclude() {
|
||||||
|
return include;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInclude(int[] include) {
|
||||||
|
this.include = include;
|
||||||
|
|
||||||
|
addFilter("include", include);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
|
||||||
|
addFilter("offset", offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(String order) {
|
||||||
|
this.order = order;
|
||||||
|
|
||||||
|
addFilter("order", order);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrderby() {
|
||||||
|
return orderby;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderby(String orderby) {
|
||||||
|
this.orderby = orderby;
|
||||||
|
|
||||||
|
addFilter("orderby", orderby);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(int[] parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
|
||||||
|
addFilter("parent", parent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getParent_exclude() {
|
||||||
|
return parent_exclude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent_exclude(int[] parent_exclude) {
|
||||||
|
this.parent_exclude = parent_exclude;
|
||||||
|
|
||||||
|
addFilter("parent_exclude", parent_exclude);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSlug() {
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlug(String slug) {
|
||||||
|
this.slug = slug;
|
||||||
|
|
||||||
|
addFilter("slug", slug);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
|
||||||
|
addFilter("status", status);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
|
||||||
|
addFilter("type", type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSku() {
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSku(String sku) {
|
||||||
|
this.sku = sku;
|
||||||
|
|
||||||
|
addFilter("sku", sku);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFeatured() {
|
||||||
|
return featured;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeatured(boolean featured) {
|
||||||
|
this.featured = featured;
|
||||||
|
|
||||||
|
addFilter("featured", featured);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
|
||||||
|
addFilter("category", category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTag() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(String tag) {
|
||||||
|
this.tag = tag;
|
||||||
|
|
||||||
|
addFilter("tag", tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShipping_class() {
|
||||||
|
return shipping_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShipping_class(String shipping_class) {
|
||||||
|
this.shipping_class = shipping_class;
|
||||||
|
|
||||||
|
addFilter("shipping_class", shipping_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttribute() {
|
||||||
|
return attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute(String attribute) {
|
||||||
|
this.attribute = attribute;
|
||||||
|
|
||||||
|
addFilter("attribute", attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAttribute_term() {
|
||||||
|
return attribute_term;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute_term(String attribute_term) {
|
||||||
|
this.attribute_term = attribute_term;
|
||||||
|
|
||||||
|
addFilter("attribute_term", attribute_term);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getTax_class() {
|
||||||
|
return tax_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTax_class(String tax_class) {
|
||||||
|
this.tax_class = tax_class;
|
||||||
|
|
||||||
|
addFilter("tax_class", tax_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOn_sale() {
|
||||||
|
return on_sale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOn_sale(boolean on_sale) {
|
||||||
|
this.on_sale = on_sale;
|
||||||
|
|
||||||
|
addFilter("on_sale", on_sale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMin_price() {
|
||||||
|
return min_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMin_price(String min_price) {
|
||||||
|
this.min_price = min_price;
|
||||||
|
|
||||||
|
addFilter("min_price", min_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMax_price() {
|
||||||
|
return max_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax_price(String max_price) {
|
||||||
|
this.max_price = max_price;
|
||||||
|
|
||||||
|
addFilter("max_price", max_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStock_status() {
|
||||||
|
return stock_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStock_status(String stock_status) {
|
||||||
|
this.stock_status = stock_status;
|
||||||
|
|
||||||
|
addFilter("stock_status", stock_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFilter(String filter, Object value){
|
||||||
|
filters.put(filter, value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getFilters() {
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package me.gilo.woodroid.repo;
|
|||||||
|
|
||||||
import me.gilo.woodroid.data.api.ProductAPI;
|
import me.gilo.woodroid.data.api.ProductAPI;
|
||||||
import me.gilo.woodroid.models.Product;
|
import me.gilo.woodroid.models.Product;
|
||||||
|
import me.gilo.woodroid.models.filters.ProductFilter;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -34,6 +35,32 @@ public class ProductRepository extends WooRepository {
|
|||||||
return apiService.filter(filters);
|
return apiService.filter(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Call<List<Product>> products(ProductFilter productFilter) {
|
||||||
|
return filter(productFilter.getFilters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call<List<Product>> search(String term) {
|
||||||
|
ProductFilter productFilter = new ProductFilter();
|
||||||
|
productFilter.setSearch(term);
|
||||||
|
|
||||||
|
return filter(productFilter.getFilters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call<List<Product>> products(int page, int per_page) {
|
||||||
|
ProductFilter productFilter = new ProductFilter();
|
||||||
|
productFilter.setPage(page);
|
||||||
|
productFilter.setPer_page(per_page);
|
||||||
|
|
||||||
|
return filter(productFilter.getFilters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Call<List<Product>> products(int page) {
|
||||||
|
ProductFilter productFilter = new ProductFilter();
|
||||||
|
productFilter.setPage(page);
|
||||||
|
|
||||||
|
return filter(productFilter.getFilters());
|
||||||
|
}
|
||||||
|
|
||||||
public Call<Product> update(int id, Product product) {
|
public Call<Product> update(int id, Product product) {
|
||||||
return apiService.update(id, product);
|
return apiService.update(id, product);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user