فهرست منبع

product model

dola 1 سال پیش
والد
کامیت
f2e957ff0e

+ 2 - 0
app/src/main/java/com/sambath/kunkhmer/adapter/ProductAdapter.kt

@@ -27,6 +27,7 @@ class ProductAdapter(var cardList: MutableList<ProductInfo>, private val listene
         Picasso.get().load(Config.BASE_URL + "/v1/product/image/" + currentItem.filename).into(holder.imageView)
         holder.subTitleTextView.text = currentItem.desc
         holder.titleTextView.text = currentItem.name
+        holder.priceTextView.text = "$" + currentItem.price
     }
 
     override fun getItemCount() = cardList.size
@@ -35,6 +36,7 @@ class ProductAdapter(var cardList: MutableList<ProductInfo>, private val listene
         val imageView: ImageView = itemView.findViewById(R.id.product_image)
         val subTitleTextView: TextView = itemView.findViewById(R.id.product_desc)
         val titleTextView: TextView = itemView.findViewById(R.id.product_title)
+        val priceTextView: TextView = itemView.findViewById(R.id.product_price)
 
         init {
             itemView.setOnClickListener {

+ 29 - 7
app/src/main/java/com/sambath/kunkhmer/screen/shop/ShopFragment.kt

@@ -5,13 +5,12 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.appcompat.widget.SearchView
+import androidx.recyclerview.widget.GridLayoutManager
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.adapter.ProductAdapter
-import com.sambath.kunkhmer.adapter.ProductCardItem
 import com.sambath.kunkhmer.app.App
-import com.sambath.kunkhmer.screen.news.NewsViewState
-import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNews
+import com.sambath.kunkhmer.remote.ProductInfo
 import kotlinx.android.synthetic.main.fragment_shop.view.recyclerViewShop
 
 
@@ -19,7 +18,7 @@ class ShopFragment : Fragment(), ProductAdapter.OnItemClickListener {
 
     private var _root: View? = null
     private val binding get() = _root!!
-    private var cardList: List<ProductCardItem>? = null
+    private var cardList: List<ProductInfo>? = null
     private lateinit var productAdapter: ProductAdapter
     private lateinit var shopViewModel: ShopViewModel
 
@@ -38,7 +37,7 @@ class ShopFragment : Fragment(), ProductAdapter.OnItemClickListener {
         shopViewModel.getProducts()
 
         binding.recyclerViewShop.apply {
-            layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
+            layoutManager = GridLayoutManager(context, 2)
             adapter = productAdapter
         }
 
@@ -46,13 +45,37 @@ class ShopFragment : Fragment(), ProductAdapter.OnItemClickListener {
             render(it)
         })
 
+        val searchView = binding.findViewById<SearchView>(R.id.searchView)
+        searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
+            override fun onQueryTextSubmit(query: String?): Boolean {
+                searchView.clearFocus() // close the keyboard after submitting the query
+                return true
+            }
+
+            override fun onQueryTextChange(newText: String?): Boolean {
+                filter(newText.orEmpty())
+                return true
+            }
+        })
+
+
         return binding
     }
 
+    private fun filter(query: String) {
+        val filteredList = cardList?.filter {
+            it.name.contains(query, ignoreCase = true)
+        }
+
+        productAdapter.cardList = filteredList.orEmpty().toMutableList()
+        productAdapter.notifyDataSetChanged()
+    }
+
     private fun render(state: ShopViewModel.ProductViewState) {
         if (state.isLoginSuccess) {
             if(state.productData != null) {
                 productAdapter.cardList = state.productData
+                cardList = productAdapter.cardList
                 productAdapter.notifyDataSetChanged()
             }
         }
@@ -60,6 +83,5 @@ class ShopFragment : Fragment(), ProductAdapter.OnItemClickListener {
     }
 
     override fun onItemClick(position: Int) {
-        TODO("Not yet implemented")
     }
 }

+ 60 - 1
app/src/main/res/layout/fragment_shop.xml

@@ -4,10 +4,69 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
     android:background="@color/color_black"
+    android:orientation="vertical"
     tools:context=".screen.shop.ShopFragment">
 
+    <androidx.cardview.widget.CardView
+        android:layout_width="match_parent"
+        android:layout_height="200dp"
+        android:layout_marginTop="5dp"
+        android:layout_marginBottom="5dp"
+        app:cardCornerRadius="5dp">
+
+        <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@color/color_black">
+
+            <ImageView
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@drawable/default_background" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="#66000000" />
+
+        </FrameLayout>
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"
+            android:gravity="center"
+            android:orientation="vertical">
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/shope_title"
+                android:textColor="@color/color_white"
+                android:textSize="30sp"
+                android:textStyle="bold|italic" />
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center"
+                android:gravity="center"
+                android:text="@string/shope_title_2"
+                android:textColor="@color/color_white"
+                android:textSize="20sp"
+                android:textStyle="italic" />
+        </LinearLayout>
+
+    </androidx.cardview.widget.CardView>
+
+    <androidx.appcompat.widget.SearchView
+        android:id="@+id/searchView"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/color_white"
+        android:queryHint="Search products..." />
+
     <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/recyclerViewShop"
         android:layout_width="match_parent"

+ 23 - 7
app/src/main/res/layout/layout_product_item_card.xml

@@ -1,19 +1,22 @@
-<?xml version="1.0" encoding="utf-8"?>
 <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="260dp"
+    android:layout_margin="5dp"
+    app:cardCornerRadius="5dp"
     android:orientation="vertical">
 
     <androidx.appcompat.widget.LinearLayoutCompat
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="match_parent"
         android:orientation="vertical">
 
         <ImageView
             android:id="@+id/product_image"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:padding="10dp"
+            android:layout_height="0dp"
+            android:layout_weight="1"
+            android:layout_margin="10dp"
             android:src="@drawable/ic_logo_header" />
 
         <TextView
@@ -31,8 +34,21 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center"
-            android:text="Product title"
+            android:padding="5dp"
+            android:text="Product description"
             android:textSize="12sp" />
-    </androidx.appcompat.widget.LinearLayoutCompat>
 
+        <TextView
+            android:id="@+id/product_price"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="bottom"
+            android:background="@color/color_blue_600"
+            android:gravity="center"
+            android:padding="10dp"
+            android:text="Product price"
+            android:textColor="@color/color_white"
+            android:textSize="14sp"
+            android:textStyle="bold" />
+    </androidx.appcompat.widget.LinearLayoutCompat>
 </androidx.cardview.widget.CardView>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -80,4 +80,6 @@
     <string name="title_date">Date</string>
     <string name="agreement_hint"><![CDATA[By signing up, you agree with our <font color="#0000FF">Term & Condition</font> and <font color="#0000FF">Privacy Policy</font>]]></string>
     <string name="booking_now">Booking Now</string>
+    <string name="shope_title">HOME BOXING EQUIPMENT</string>
+    <string name="shope_title_2">WHAT YOU NEED TO TRAIN AT HOME</string>
 </resources>

+ 7 - 0
app/src/main/res/values/styles.xml

@@ -8,6 +8,13 @@
         <item name="colorPrimaryVariant">@color/light_yellow</item>
     </style>
 
+    <style name="MySearchView" parent="Widget.AppCompat.SearchView">
+        <!-- Text color -->
+        <item name="android:textColor">@color/color_white</item>
+        <!-- Hint text color -->
+        <item name="android:textColorHint">@color/color_white</item>
+    </style>
+
     <style name="AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
 
     <style name="PopupOverlay" parent="ThemeOverlay.MaterialComponents.Dark" />