Added loading state on product page and empty state on cart page

This commit is contained in:
Gilbert Kimutai 2019-04-16 05:17:28 +03:00
parent 3e9ad9fa6a
commit 58a8cd5f6a
10 changed files with 249 additions and 45 deletions

View File

@ -56,9 +56,9 @@ class CartViewHolder(val context: Context, itemView: View) :
val salePrice = product.sale_price
if (product.isOn_sale) {
tvPrice.text = SpannableString("$$salePrice")
tvPrice.text = SpannableString("Ksh$salePrice")
}else{
tvPrice.text = SpannableString("$$regularPrice")
tvPrice.text = SpannableString("Ksh$regularPrice")
}

View File

@ -4,10 +4,13 @@ import android.content.Context
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.text.SpannableString
import android.view.View
import com.google.common.primitives.UnsignedBytes.toInt
import io.github.inflationx.viewpump.ViewPumpContextWrapper
import kotlinx.android.synthetic.main.activity_cart.*
import kotlinx.android.synthetic.main.content_cart.*
import kotlinx.android.synthetic.main.single_cart_item.*
import kotlinx.android.synthetic.main.state_empty.*
import me.gilo.wc.R
import me.gilo.wc.adapter.CartAdapter
import me.gilo.wc.common.Status
@ -53,6 +56,7 @@ class CartActivity : WooDroidActivity<CartViewModel>() {
cart()
llEmptyState_layout.visibility = View.GONE
}
@ -84,6 +88,8 @@ class CartActivity : WooDroidActivity<CartViewModel>() {
Status.EMPTY -> {
stopShowingLoading()
llEmptyState_layout.visibility = View.VISIBLE
}
}
@ -97,9 +103,9 @@ class CartActivity : WooDroidActivity<CartViewModel>() {
for (cartitem in cartItems){
var price = if (cartitem.product.isOn_sale) {
cartitem.product.sale_price.toInt()
cartitem.product.sale_price.replace(",","").toInt()
}else{
cartitem.product.regular_price.toInt()
cartitem.product.regular_price.replace(",","").toInt()
}
var qty = cartitem.quantity

View File

@ -114,14 +114,14 @@ class ProductActivity : BaseActivity() {
viewModel.product(productId).observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) {
Status.LOADING -> {
flLoading.visibility = View.VISIBLE
}
Status.SUCCESS -> {
val product = response.data()
setUpPage(product)
//similarProducts(product)
flLoading.visibility = View.GONE
EventBus.getDefault().post(ProductEvent(product))
@ -129,11 +129,10 @@ class ProductActivity : BaseActivity() {
}
Status.ERROR -> {
flLoading.visibility = View.GONE
}
Status.EMPTY -> {
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#adb3be"
android:dashGap="8dp"
android:dashWidth="8dp"
/>
<corners
android:radius="1dp"
/>
</shape>

View File

@ -23,6 +23,8 @@
<include layout="@layout/content_cart"/>
<include layout="@layout/state_empty"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -23,6 +23,23 @@
<include layout="@layout/content_product"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg"
android:elevation="2dp"
android:id="@+id/flLoading"
>
<include
layout="@layout/loading_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"

View File

@ -17,42 +17,52 @@
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:layout_margin="16dp"
android:layout_height="wrap_content"
android:background="@drawable/rect_white"
android:elevation="2dp"
android:orientation="vertical"
tools:ignore="MissingPrefix">
>
<android.support.v4.view.ViewPager
android:id="@+id/vpImages"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="280dp"
>
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="8dp"
android:layout_margin="16dp"
app:ci_height="4dp"
app:ci_width="4dp"
android:layout_gravity="bottom|center"
/>
<android.support.v4.view.ViewPager
android:id="@+id/vpImages"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/tvOnSale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:background="@color/colorPrimary"
android:textColor="#ffffff"
android:text="SALE!"
fontPath="@string/font_medium"
android:padding="8dp"
/>
</FrameLayout>
<TextView
android:id="@+id/tvOnSale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:background="@color/colorPrimary"
android:textColor="#ffffff"
android:text="SALE!"
fontPath="@string/font_medium"
android:padding="8dp"
/>
</FrameLayout>
</LinearLayout>
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="8dp"
app:ci_height="4dp"
app:ci_width="4dp"
android:layout_gravity="bottom|center"
/>
<LinearLayout
@ -109,17 +119,15 @@
<fragment
android:name="me.gilo.wc.ui.product.section.RelatedProductsFragment"
android:id="@+id/fRelatedProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:id="@+id/fRelatedProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:name="me.gilo.wc.ui.product.section.ProductReviewsFragment"
android:id="@+id/fProductReviews"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="32dp"
android:padding="16dp"
android:background="#ffffff"
android:id="@+id/ivImage"
android:scaleType="center"/>

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/bg"
android:padding="16dp"
android:gravity="center"
android:elevation="3dp"
android:id="@+id/llEmptyState_layout"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center_horizontal"
android:background="@drawable/rect_grey_bg_dotted_stroke"
>
<TextView
android:id="@+id/tvEmptyState_title"
fontPath="@string/font_medium"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="No items in Cart"
android:textColor="@color/text_black_2"
android:textSize="18sp"
android:layout_weight="1"
tools:ignore="MissingPrefix" />
<TextView
android:id="@+id/tvEmptyState_description"
fontPath="@string/font_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.16959"
android:gravity="center"
android:layout_marginTop="8dp"
android:text="When you add items to cart they will appear here"
android:textColor="@color/text_black_5"
android:textSize="16sp"
tools:ignore="MissingPrefix" />
<Button
android:id="@+id/bEmptyState_action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="16dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:background="@color/colorPrimary"
android:text="Browse Products"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp"
/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/bg"
android:padding="16dp"
android:gravity="center"
android:id="@+id/llEmptyState_layout"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center_horizontal"
android:background="@drawable/rect_grey_bg_dotted_stroke"
>
<TextView
android:id="@+id/tvErrorState_title"
fontPath="@string/font_medium"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Something went wrong"
android:textColor="@color/text_black_2"
android:textSize="18sp"
android:layout_weight="1"
tools:ignore="MissingPrefix" />
<TextView
android:id="@+id/tvErrorState_description"
fontPath="@string/font_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.16959"
android:gravity="center"
android:layout_marginTop="16dp"
android:text="It appears that something has gone terribly wrong. Please hold on as we attempt to correct the issue."
android:textColor="@color/text_black_5"
android:textSize="16sp"
tools:ignore="MissingPrefix" />
<Button
android:id="@+id/bErrorState_action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="16dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:background="@color/colorPrimary"
android:text="Go Back"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp"
/>
</LinearLayout>
</LinearLayout>