complete order page
This commit is contained in:
parent
ceda450bb8
commit
1ec0747e26
@ -4,10 +4,13 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.Html
|
||||
import android.text.SpannableString
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.ui.product.ShopActivity
|
||||
import me.gilo.wc.utils.DateUtils
|
||||
import me.gilo.wc.utils.StringFormatter
|
||||
import me.gilo.woodroid.models.Category
|
||||
import me.gilo.woodroid.models.Order
|
||||
|
||||
@ -16,7 +19,28 @@ class OrderViewHolder(val context: Context, itemView: View) :
|
||||
|
||||
fun renderView(order: Order) {
|
||||
val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle)
|
||||
val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription)
|
||||
val tvPrice = itemView.findViewById<TextView>(R.id.tvPrice)
|
||||
val tvStatus = itemView.findViewById<TextView>(R.id.tvStatus)
|
||||
val tvDate = itemView.findViewById<TextView>(R.id.tvDate)
|
||||
|
||||
|
||||
|
||||
tvTitle.text = "#" + order.orderNumber
|
||||
tvStatus.text = order.status
|
||||
|
||||
tvDate.text = DateUtils.getDateString_shortAndSmart(order.getDateCreated())
|
||||
|
||||
tvPrice.text = SpannableString("Ksh${order.total}")
|
||||
|
||||
var description = ""
|
||||
|
||||
for (lineItem in order.lineItems){
|
||||
description += lineItem.name + "(" + lineItem.quantity + "), "
|
||||
}
|
||||
|
||||
|
||||
tvDescription.text = description
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2,21 +2,23 @@ package me.gilo.wc.ui
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.PersistableBundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||
import me.gilo.wc.R
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_basic_customer_details.*
|
||||
import me.gilo.raison.ui.user.onboarding.SignInActivity
|
||||
import me.gilo.wc.common.BaseActivity
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.ui.product.CartActivity
|
||||
import me.gilo.wc.ui.state.ProgressDialogFragment
|
||||
import me.gilo.wc.viewmodels.CustomerViewModel
|
||||
import me.gilo.wc.viewmodels.UserViewModel
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
import me.gilo.wc.viewmodels.CartViewModel
|
||||
import me.gilo.wc.viewmodels.ProductViewModel
|
||||
|
||||
abstract class WooDroidActivity<T : ViewModel> : BaseActivity() {
|
||||
|
||||
@ -26,6 +28,13 @@ abstract class WooDroidActivity<T : ViewModel> : BaseActivity() {
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
cart()
|
||||
}
|
||||
|
||||
fun showLoading() {
|
||||
@ -47,4 +56,71 @@ abstract class WooDroidActivity<T : ViewModel> : BaseActivity() {
|
||||
Toast.makeText(baseContext, text, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
var tvCartCounter : TextView? = null
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.product, menu)
|
||||
|
||||
val item = menu.findItem(me.gilo.wc.R.id.menu_cart)
|
||||
val rootView = item.actionView as FrameLayout
|
||||
tvCartCounter = rootView.findViewById<TextView>(R.id.tvCart_counter)
|
||||
|
||||
rootView.setOnClickListener{startActivity(Intent(baseContext, CartActivity::class.java))}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.menu_cart -> {
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
open fun cart() {
|
||||
var viewModel = getViewModel(CartViewModel::class.java)
|
||||
|
||||
viewModel.cart().observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
|
||||
}
|
||||
|
||||
Status.SUCCESS -> {
|
||||
for (cartItem in response.data()){
|
||||
|
||||
}
|
||||
|
||||
if ( response.data().size == 0 && tvCartCounter != null){
|
||||
tvCartCounter?.visibility = View.GONE
|
||||
}else{
|
||||
tvCartCounter?.visibility = View.VISIBLE
|
||||
tvCartCounter?.text = response.data().size.toString()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
|
||||
}
|
||||
|
||||
Status.EMPTY -> {
|
||||
if ( response.data().size == 0 && tvCartCounter != null){
|
||||
tvCartCounter?.visibility = View.GONE
|
||||
}else{
|
||||
tvCartCounter?.visibility = View.VISIBLE
|
||||
tvCartCounter?.text = response.data().size.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
package me.gilo.wc.ui.home
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.BottomNavigationView
|
||||
import android.support.v4.app.Fragment
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||
import android.view.View
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.common.BaseActivity
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.models.CartLineItem
|
||||
import me.gilo.wc.ui.WooDroidActivity
|
||||
import me.gilo.wc.viewmodels.CartViewModel
|
||||
import me.gilo.wc.viewmodels.ProductViewModel
|
||||
import me.gilo.woodroid.models.CartItem
|
||||
|
||||
class HomeActivity : BaseActivity() {
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||
}
|
||||
class HomeActivity : WooDroidActivity<CartViewModel>() {
|
||||
override lateinit var viewModel: CartViewModel
|
||||
|
||||
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
|
||||
|
||||
@ -42,6 +43,8 @@ class HomeActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_home)
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
|
||||
|
||||
val transaction = supportFragmentManager.beginTransaction()
|
||||
|
||||
@ -25,10 +25,6 @@ class MyOrdersActivity : WooDroidActivity<OrderViewModel>() {
|
||||
|
||||
lateinit var adapter: OrderAdapter
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_my_orders)
|
||||
|
||||
@ -73,7 +73,7 @@ class CartActivity : WooDroidActivity<CartViewModel>() {
|
||||
|
||||
}
|
||||
|
||||
private fun cart() {
|
||||
override fun cart() {
|
||||
viewModel.cart().observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
|
||||
@ -1,29 +1,142 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingPrefix">
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#ffffff"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingPrefix"
|
||||
android:layout_marginTop="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="left"
|
||||
android:text="Hey"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="16sp"/>
|
||||
android:gravity="top"
|
||||
android:orientation="horizontal"
|
||||
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:text="Title"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPrice"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:gravity="left"
|
||||
android:text="$20.00"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_gravity="left"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDescription"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="left"
|
||||
android:maxLines="2"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_5"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStatus"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="4dp"
|
||||
|
||||
android:gravity="left"
|
||||
android:maxLines="2"
|
||||
android:layout_gravity="left"
|
||||
android:text="Pending"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/carnation_red"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDate"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="left"
|
||||
android:maxLines="2"
|
||||
android:layout_gravity="right"
|
||||
android:text="Apr 13, 2019"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/bg"
|
||||
android:layout_marginTop="16dp"
|
||||
/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package me.gilo.woodroid.models;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -12,6 +13,10 @@ public class Order {
|
||||
public String orderNumber;
|
||||
@SerializedName("created_at")
|
||||
public String createdAt;
|
||||
|
||||
@SerializedName("date_created")
|
||||
public Date dateCreated;
|
||||
|
||||
@SerializedName("updated_at")
|
||||
public String updatedAt;
|
||||
@SerializedName("completed_at")
|
||||
@ -305,4 +310,12 @@ public class Order {
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
public void setDateCreated(Date dateCreated) {
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user