updated order detailed page
This commit is contained in:
parent
31602df99e
commit
fcaec04239
@ -44,9 +44,9 @@ class OrderViewHolder(val context: Context, itemView: View) :
|
||||
tvDescription.text = description
|
||||
|
||||
itemView.setOnClickListener{
|
||||
var intent = Intent(context, OrderActivity::class.java);
|
||||
intent.putExtra("orderId", order.id);
|
||||
context.startActivity(intent);
|
||||
var intent = Intent(context, OrderActivity::class.java)
|
||||
intent.putExtra("orderId", order.id)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
package me.gilo.wc.ui.order
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import me.gilo.wc.R
|
||||
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.activity_order.*
|
||||
import me.gilo.wc.adapter.OrderAdapter
|
||||
import kotlinx.android.synthetic.main.content_order.*
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.CartAdapter
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.models.CartLineItem
|
||||
import me.gilo.wc.ui.WooDroidActivity
|
||||
import me.gilo.wc.viewmodels.OrderViewModel
|
||||
import me.gilo.woodroid.models.Order
|
||||
import me.gilo.woodroid.models.filters.ProductFilter
|
||||
|
||||
class OrderActivity : WooDroidActivity<OrderViewModel>() {
|
||||
|
||||
@ -18,7 +19,11 @@ class OrderActivity : WooDroidActivity<OrderViewModel>() {
|
||||
override lateinit var viewModel: OrderViewModel
|
||||
var orders: ArrayList<Order> = ArrayList()
|
||||
|
||||
lateinit var adapter: OrderAdapter
|
||||
var cartItems: ArrayList<CartLineItem> = ArrayList()
|
||||
lateinit var adapter: CartAdapter
|
||||
|
||||
var orderId = 0
|
||||
lateinit var order : Order
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -27,6 +32,21 @@ class OrderActivity : WooDroidActivity<OrderViewModel>() {
|
||||
|
||||
viewModel = getViewModel(OrderViewModel::class.java)
|
||||
title = "Orders"
|
||||
|
||||
orderId = intent.getIntExtra("orderId", 0)
|
||||
|
||||
val layoutManager = LinearLayoutManager(baseContext, LinearLayoutManager.VERTICAL, false)
|
||||
rvCart.layoutManager = layoutManager
|
||||
rvCart.isNestedScrollingEnabled = false
|
||||
|
||||
cartItems = ArrayList()
|
||||
|
||||
adapter = CartAdapter(cartItems)
|
||||
rvCart.adapter = adapter
|
||||
|
||||
if(orderId != 0){
|
||||
order(orderId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun order(orderId : Int) {
|
||||
@ -39,6 +59,23 @@ class OrderActivity : WooDroidActivity<OrderViewModel>() {
|
||||
Status.SUCCESS -> {
|
||||
stopShowingLoading()
|
||||
|
||||
order = response.data()
|
||||
var productIds = ArrayList<Int>()
|
||||
|
||||
for(orderLineItem in order.lineItems){
|
||||
var cartLineItem = CartLineItem()
|
||||
cartLineItem.name = orderLineItem.name
|
||||
cartLineItem.price = orderLineItem.price.toFloat()
|
||||
cartLineItem.quantity= orderLineItem.quantity
|
||||
cartLineItem.productId = orderLineItem.productId
|
||||
|
||||
cartItems.add(cartLineItem)
|
||||
|
||||
productIds.add(orderLineItem.productId)
|
||||
}
|
||||
|
||||
products(productIds.toIntArray())
|
||||
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
@ -56,4 +93,73 @@ class OrderActivity : WooDroidActivity<OrderViewModel>() {
|
||||
|
||||
}
|
||||
|
||||
private fun products(productIds : IntArray) {
|
||||
var filter = ProductFilter()
|
||||
filter.setInclude(productIds)
|
||||
|
||||
viewModel.products(filter).observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
showLoading()
|
||||
}
|
||||
|
||||
Status.SUCCESS -> {
|
||||
stopShowingLoading()
|
||||
var products = response.data()
|
||||
|
||||
var tempCartItems = ArrayList(cartItems)
|
||||
cartItems.clear()
|
||||
|
||||
for (cartItem in tempCartItems){
|
||||
var product = products.find { product -> product.id == cartItem.productId }
|
||||
cartItem.product = product
|
||||
cartItems.add(cartItem)
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
setUpPage()
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
stopShowingLoading()
|
||||
}
|
||||
|
||||
Status.EMPTY -> {
|
||||
stopShowingLoading()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private fun setUpPage() {
|
||||
var itemCount = cartItems.size
|
||||
var total = 0
|
||||
|
||||
for (cartitem in cartItems){
|
||||
var price = if (cartitem.product.isOn_sale) {
|
||||
cartitem.product.sale_price.replace(",","").toInt()
|
||||
}else{
|
||||
cartitem.product.regular_price.replace(",","").toInt()
|
||||
}
|
||||
|
||||
var qty = cartitem.quantity
|
||||
|
||||
total += price * qty
|
||||
|
||||
}
|
||||
|
||||
if (itemCount == 1){
|
||||
tvTotalItemCountTitle.text = "Item ($itemCount)"
|
||||
}else{
|
||||
tvTotalItemCountTitle.text = "Items ($itemCount)"
|
||||
}
|
||||
|
||||
tvTotalItemCost.text = "Ksh$total"
|
||||
tvTotal.text = "Ksh$total"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,10 +3,13 @@ package me.gilo.wc.viewmodels;
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import me.gilo.wc.common.WooLiveData;
|
||||
import me.gilo.wc.repo.OrderRepository;
|
||||
import me.gilo.wc.repo.ProductRepository;
|
||||
import me.gilo.wc.repo.ReviewRepository;
|
||||
import me.gilo.woodroid.models.Order;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
import me.gilo.woodroid.models.ProductReview;
|
||||
import me.gilo.woodroid.models.filters.OrderFilter;
|
||||
import me.gilo.woodroid.models.filters.ProductFilter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
@ -14,10 +17,12 @@ import java.util.List;
|
||||
|
||||
public final class OrderViewModel extends ViewModel {
|
||||
private final OrderRepository orderRepository;
|
||||
private final ProductRepository productRepository;
|
||||
|
||||
@Inject
|
||||
OrderViewModel(OrderRepository orderRepository) {
|
||||
OrderViewModel(OrderRepository orderRepository, ProductRepository productRepository) {
|
||||
this.orderRepository = orderRepository;
|
||||
this.productRepository = productRepository;
|
||||
}
|
||||
|
||||
public WooLiveData<Order> addToCart(int productId) {
|
||||
@ -34,6 +39,10 @@ public final class OrderViewModel extends ViewModel {
|
||||
return orderRepository.order(id);
|
||||
}
|
||||
|
||||
public WooLiveData<List<Product>> products(ProductFilter filter) {
|
||||
return productRepository.products(filter);
|
||||
}
|
||||
|
||||
public WooLiveData<List<Order>> orders() {
|
||||
return orderRepository.orders();
|
||||
}
|
||||
|
||||
@ -1,12 +1,249 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingPrefix"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/activity_order"
|
||||
tools:context=".ui.order.OrderActivity">
|
||||
>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="80dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:id="@+id/rvCart"
|
||||
android:elevation="2dp"
|
||||
android:background="@drawable/rect_white"
|
||||
>
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:background="#d8d8d8"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalItemCountTitle"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:text="Item (1)"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotalItemCost"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:text="$0"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShippingTitle"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:text="Shipping within San Fransisco"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShippingCost"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:text="$0"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:background="#d8d8d8"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:text="Total"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTotal"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:text="$0"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:background="#d8d8d8"
|
||||
android:layout_marginBottom="16dp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="Shipping To"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/rect_white"
|
||||
android:elevation="2dp"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShippingAddress"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:text="@string/dummy_address"
|
||||
android:maxLines="6"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_5"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShippingAddressEdit"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:text="Edit"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:layout_gravity="right"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="Pay with"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/rect_white"
|
||||
android:elevation="2dp"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="16dp">
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
Loading…
Reference in New Issue
Block a user