Support for sending arrays in url for filters with arrays
Also able to get similar products in one call
This commit is contained in:
parent
aa218fe992
commit
82c76bb970
@ -3,6 +3,7 @@ package me.gilo.wc.ui.product
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import kotlinx.android.synthetic.main.activity_product.*
|
import kotlinx.android.synthetic.main.activity_product.*
|
||||||
import kotlinx.android.synthetic.main.content_product.*
|
import kotlinx.android.synthetic.main.content_product.*
|
||||||
@ -14,12 +15,15 @@ import me.gilo.wc.common.Status
|
|||||||
import me.gilo.wc.ui.state.ProgressDialogFragment
|
import me.gilo.wc.ui.state.ProgressDialogFragment
|
||||||
import me.gilo.wc.viewmodels.ProductViewModel
|
import me.gilo.wc.viewmodels.ProductViewModel
|
||||||
import me.gilo.woodroid.models.Product
|
import me.gilo.woodroid.models.Product
|
||||||
|
import me.gilo.woodroid.models.filters.ProductFilter
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
class ProductActivity : BaseActivity() {
|
class ProductActivity : BaseActivity() {
|
||||||
|
|
||||||
lateinit var viewModel: ProductViewModel
|
lateinit var viewModel: ProductViewModel
|
||||||
val TAG = this::getLocalClassName
|
val TAG = this::getLocalClassName.toString()
|
||||||
|
|
||||||
|
var related_ids : IntArray = intArrayOf()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -34,7 +38,7 @@ class ProductActivity : BaseActivity() {
|
|||||||
|
|
||||||
if (productId != 0){
|
if (productId != 0){
|
||||||
product(productId)
|
product(productId)
|
||||||
similarProducts()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fab.setOnClickListener{addToCart(productId)}
|
fab.setOnClickListener{addToCart(productId)}
|
||||||
@ -46,7 +50,7 @@ class ProductActivity : BaseActivity() {
|
|||||||
private lateinit var products: ArrayList<Product>
|
private lateinit var products: ArrayList<Product>
|
||||||
|
|
||||||
//TODO(Use the include product filter to get related products from API)
|
//TODO(Use the include product filter to get related products from API)
|
||||||
private fun similarProducts() {
|
private fun similarProducts(product: Product) {
|
||||||
val layoutManager = LinearLayoutManager(baseContext, LinearLayoutManager.HORIZONTAL, false)
|
val layoutManager = LinearLayoutManager(baseContext, LinearLayoutManager.HORIZONTAL, false)
|
||||||
rvShop.layoutManager = layoutManager
|
rvShop.layoutManager = layoutManager
|
||||||
rvShop.isNestedScrollingEnabled = false
|
rvShop.isNestedScrollingEnabled = false
|
||||||
@ -56,7 +60,14 @@ class ProductActivity : BaseActivity() {
|
|||||||
adapter = HomeProductAdapter(products)
|
adapter = HomeProductAdapter(products)
|
||||||
rvShop.adapter = adapter
|
rvShop.adapter = adapter
|
||||||
|
|
||||||
viewModel.products().observe(this, android.arch.lifecycle.Observer { response ->
|
val filter = ProductFilter()
|
||||||
|
filter.include = product.related_ids.toIntArray()
|
||||||
|
|
||||||
|
for (id in product.related_ids){
|
||||||
|
Log.d("Related ids", "" + id)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.products(filter).observe(this, android.arch.lifecycle.Observer { response ->
|
||||||
when (response!!.status()) {
|
when (response!!.status()) {
|
||||||
Status.LOADING -> {
|
Status.LOADING -> {
|
||||||
|
|
||||||
@ -121,6 +132,7 @@ class ProductActivity : BaseActivity() {
|
|||||||
Status.SUCCESS -> {
|
Status.SUCCESS -> {
|
||||||
val product = response.data()
|
val product = response.data()
|
||||||
setUpPage(product)
|
setUpPage(product)
|
||||||
|
similarProducts(product)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
package me.gilo.woodroid.models.filters;
|
package me.gilo.woodroid.models.filters;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import me.gilo.woodroid.utils.Converter;
|
import me.gilo.woodroid.utils.Converter;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ListFilter {
|
public class ListFilter {
|
||||||
|
|
||||||
@ -146,8 +145,26 @@ public class ListFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addFilter(String filter, Object value){
|
public void addFilter(String filter, Object value){
|
||||||
|
if (value.getClass().isArray()){
|
||||||
|
if (value instanceof int[]) {
|
||||||
|
String values = "";
|
||||||
|
int[] items = (int[]) value;
|
||||||
|
for (int item : items){
|
||||||
|
values += item + ",";
|
||||||
|
}
|
||||||
|
|
||||||
|
filters.put(filter, ""+values.substring(0, values.length() - 1));
|
||||||
|
|
||||||
|
}else {
|
||||||
|
List list = Arrays.asList(value);
|
||||||
|
for (Object item : list) {
|
||||||
|
filters.put(filter, item.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
filters.put(filter, value.toString());
|
filters.put(filter, value.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getFilters() {
|
public Map<String, String> getFilters() {
|
||||||
return filters;
|
return filters;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user