home page design
This commit is contained in:
parent
9786252c78
commit
3272450dd7
34
app/src/main/java/me/gilo/wc/adapter/HomeProductAdapter.java
Normal file
34
app/src/main/java/me/gilo/wc/adapter/HomeProductAdapter.java
Normal file
@ -0,0 +1,34 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HomeProductAdapter extends RecyclerView.Adapter<ProductViewHolder> {
|
||||
private List<Product> products;
|
||||
|
||||
public HomeProductAdapter(List<Product> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ProductViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_home_product_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ProductViewHolder holder, int position) {
|
||||
holder.renderView(products.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return products.size() == 0 ? 0 : products.size();
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,13 @@
|
||||
package me.gilo.wc.adapter.viewholder
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.Html
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.ui.product.ShopActivity
|
||||
import me.gilo.woodroid.models.Category
|
||||
|
||||
class CategoryViewHolder(val context: Context, itemView: View) :
|
||||
@ -18,12 +20,13 @@ class CategoryViewHolder(val context: Context, itemView: View) :
|
||||
tvTitle.text = category.name
|
||||
tvDescription.text = Html.fromHtml(category.description)
|
||||
|
||||
// itemView.setOnClickListener{
|
||||
// val intent = Intent(context, CouponActivity::class.java)
|
||||
// intent.putExtra("couponId", coupon.id)
|
||||
//
|
||||
// context.startActivity(intent)
|
||||
// }
|
||||
itemView.setOnClickListener{
|
||||
val intent = Intent(context, ShopActivity::class.java)
|
||||
intent.putExtra("categoryId",category.id)
|
||||
intent.putExtra("name",category.name)
|
||||
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -59,6 +59,8 @@ class CategoryFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun categories() {
|
||||
|
||||
//TODO ('Exclude the uncategorized category')
|
||||
viewModel.categories().observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
|
||||
@ -2,11 +2,18 @@ package me.gilo.wc.ui.home
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.HomeProductAdapter
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.viewmodels.ProductViewModel
|
||||
import me.gilo.woodroid.models.Product
|
||||
import me.gilo.woodroid.models.filters.ProductFilter
|
||||
import java.util.*
|
||||
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
@ -15,6 +22,12 @@ class HomeFragment : Fragment() {
|
||||
lateinit var viewModel: ProductViewModel
|
||||
val TAG = "HomeFragment"
|
||||
|
||||
lateinit var adapter: HomeProductAdapter
|
||||
private lateinit var products: ArrayList<Product>
|
||||
|
||||
lateinit var hoodieAdapter: HomeProductAdapter
|
||||
private lateinit var hoodieProducts: ArrayList<Product>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
@ -22,9 +35,11 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater,
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View {
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
|
||||
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||
}
|
||||
@ -32,9 +47,45 @@ class HomeFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
viewModel = (activity as HomeActivity).getViewModel(ProductViewModel::class.java)
|
||||
|
||||
setUpProducts()
|
||||
setUpHoodies()
|
||||
|
||||
}
|
||||
|
||||
private fun setUpProducts() {
|
||||
val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
|
||||
rvShop.layoutManager = layoutManager
|
||||
rvShop.isNestedScrollingEnabled = false
|
||||
|
||||
products = ArrayList()
|
||||
|
||||
adapter = HomeProductAdapter(products)
|
||||
rvShop.adapter = adapter
|
||||
|
||||
products()
|
||||
}
|
||||
|
||||
|
||||
private fun setUpHoodies() {
|
||||
val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
|
||||
|
||||
rvHoodies.layoutManager = layoutManager
|
||||
rvHoodies.isNestedScrollingEnabled = false
|
||||
|
||||
hoodieProducts = ArrayList()
|
||||
|
||||
hoodieAdapter = HomeProductAdapter(hoodieProducts)
|
||||
rvHoodies.adapter = hoodieAdapter
|
||||
|
||||
|
||||
val filter = ProductFilter()
|
||||
filter.category = 21
|
||||
products(filter)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance() =
|
||||
@ -45,4 +96,66 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun products() {
|
||||
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 products(filter: ProductFilter) {
|
||||
viewModel.products(filter).observe(this, android.arch.lifecycle.Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
}
|
||||
|
||||
Status.SUCCESS -> {
|
||||
hoodieProducts.clear()
|
||||
|
||||
val productsResponse = response.data()
|
||||
for (product in productsResponse) {
|
||||
hoodieProducts.add(product)
|
||||
}
|
||||
|
||||
hoodieAdapter.notifyDataSetChanged()
|
||||
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
Status.EMPTY -> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,13 +3,11 @@ package me.gilo.wc.ui.product
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.view.GravityCompat
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||
import kotlinx.android.synthetic.main.activity_shop.*
|
||||
import kotlinx.android.synthetic.main.content_shop.*
|
||||
import kotlinx.android.synthetic.main.drawer_filter.*
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.ProductAdapter
|
||||
@ -43,19 +41,22 @@ class ShopActivity : BaseActivity() {
|
||||
|
||||
title = "Shop"
|
||||
|
||||
val layoutManager = GridLayoutManager(baseContext, 2)
|
||||
rvShop.layoutManager = layoutManager
|
||||
rvShop.isNestedScrollingEnabled = false
|
||||
|
||||
products = ArrayList()
|
||||
|
||||
adapter = ProductAdapter(products)
|
||||
rvShop.adapter = adapter
|
||||
|
||||
products()
|
||||
cart()
|
||||
|
||||
bFilter.setOnClickListener{filter()}
|
||||
|
||||
if(intent.hasExtra("categoryId")){
|
||||
val filter = ProductFilter()
|
||||
filter.category = intent.getIntExtra("categoryId", 0)
|
||||
products(filter)
|
||||
|
||||
title = intent.getStringExtra("name")
|
||||
}else{
|
||||
products()
|
||||
}
|
||||
}
|
||||
|
||||
private fun filter() {
|
||||
@ -125,7 +126,6 @@ class ShopActivity : BaseActivity() {
|
||||
|
||||
Status.SUCCESS -> {
|
||||
val cartResponse = response.data()
|
||||
toast("Cart items are " + cartResponse.size)
|
||||
}
|
||||
|
||||
Status.ERROR -> {
|
||||
|
||||
@ -12,59 +12,77 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/rect_white"
|
||||
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:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="left"
|
||||
android:text="This is an example of a title"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp"/>
|
||||
android:text="Some of our popular products"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDescription"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="left"
|
||||
android:text="@string/lorem"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="We have a feeling you will like these"
|
||||
android:maxLines="6"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_5"
|
||||
android:textSize="14sp"/>
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
<TextView
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Check out our hoodies"
|
||||
android:textColor="@color/text_black_2"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCallToAction"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:gravity="left"
|
||||
android:padding="16dp"
|
||||
android:text="Call to Action"
|
||||
android:textColor="#1c5c9a"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="Classic pullover silhouette in a durable reverse weave cotton fleece"
|
||||
android:layout_marginRight="16dp"
|
||||
android:maxLines="6"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_9"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rvHoodies"
|
||||
android:layout_marginTop="16dp"
|
||||
></android.support.v7.widget.RecyclerView>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
82
app/src/main/res/layout/single_home_product_item.xml
Normal file
82
app/src/main/res/layout/single_home_product_item.xml
Normal file
@ -0,0 +1,82 @@
|
||||
<?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="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/rect_white"
|
||||
android:elevation="2dp"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingPrefix">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="160dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
/>
|
||||
|
||||
<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/tvTitle"
|
||||
fontPath="@string/font_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="left"
|
||||
android:textColor="@color/text"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDescription"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="left"
|
||||
android:maxLines="2"
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
android:textColor="@color/text_black_5"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCallToAction"
|
||||
fontPath="@string/font_regular"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:gravity="left"
|
||||
android:padding="16dp"
|
||||
android:textColor="#1c5c9a"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
package me.gilo.woodroid.models.filters;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProductFilter extends ListFilter{
|
||||
private int[] parent;
|
||||
private int[] parent_exclude;
|
||||
@ -11,7 +8,7 @@ public class ProductFilter extends ListFilter{
|
||||
private String type;
|
||||
private String sku;
|
||||
private boolean featured;
|
||||
private String category;
|
||||
private int category;
|
||||
private String tag;
|
||||
private String shipping_class;
|
||||
private String attribute;
|
||||
@ -96,11 +93,11 @@ public class ProductFilter extends ListFilter{
|
||||
addFilter("featured", featured);
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
public int getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
public void setCategory(int category) {
|
||||
this.category = category;
|
||||
|
||||
addFilter("category", category);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user