Added similar product section on the product page

This commit is contained in:
Gilbert Kimutai 2019-03-18 05:51:48 +03:00
parent c161bc454a
commit aa218fe992
4 changed files with 73 additions and 3 deletions

View File

@ -1,17 +1,20 @@
package me.gilo.wc.ui.product
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.text.Html
import android.view.View
import kotlinx.android.synthetic.main.activity_product.*
import kotlinx.android.synthetic.main.content_product.*
import me.gilo.wc.R
import me.gilo.wc.adapter.HomeProductAdapter
import me.gilo.wc.adapter.ImagePagerAdapter
import me.gilo.wc.common.BaseActivity
import me.gilo.wc.common.Status
import me.gilo.wc.ui.state.ProgressDialogFragment
import me.gilo.wc.viewmodels.ProductViewModel
import me.gilo.woodroid.models.Product
import java.util.ArrayList
class ProductActivity : BaseActivity() {
@ -31,12 +34,57 @@ class ProductActivity : BaseActivity() {
if (productId != 0){
product(productId)
similarProducts()
}
fab.setOnClickListener{addToCart(productId)}
}
lateinit var adapter: HomeProductAdapter
private lateinit var products: ArrayList<Product>
//TODO(Use the include product filter to get related products from API)
private fun similarProducts() {
val layoutManager = LinearLayoutManager(baseContext, LinearLayoutManager.HORIZONTAL, false)
rvShop.layoutManager = layoutManager
rvShop.isNestedScrollingEnabled = false
products = ArrayList()
adapter = HomeProductAdapter(products)
rvShop.adapter = adapter
viewModel.products().observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) {
Status.LOADING -> {
}
Status.SUCCESS -> {
products.clear()
val productsResponse = response.data()
for (product in productsResponse) {
products.add(product)
}
adapter.notifyDataSetChanged()
}
Status.ERROR -> {
}
Status.EMPTY -> {
}
}
})
}
private fun addToCart(productId: Int) {
viewModel.addToCart(baseContext, productId).observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) {
@ -62,6 +110,7 @@ class ProductActivity : BaseActivity() {
})
}
private fun product(productId : Int) {
viewModel.product(productId).observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) {

View File

@ -104,6 +104,27 @@
</LinearLayout>
<TextView
fontPath="@string/font_medium"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:gravity="left"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:text="More Like this"
android:textColor="@color/text_black_2"
android:textSize="20sp"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rvShop"
android:layout_marginTop="16dp"
></android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View File

@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0-alpha05'
classpath 'com.android.tools.build:gradle:3.5.0-alpha07'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Fri Mar 01 19:09:10 EAT 2019
#Mon Mar 18 05:31:54 EAT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip