-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from MuindiStephen/agrodealers/hotdeals
Agrodealers/hotdeals, Checkout & Pay.
- Loading branch information
Showing
39 changed files
with
1,725 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/steve_md/smartmkulima/adapter/AgroDealersOffersListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.steve_md.smartmkulima.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.steve_md.smartmkulima.databinding.ItemAgrodealersDealsRowBinding | ||
import com.steve_md.smartmkulima.model.AgroDealerOffers | ||
|
||
class AgroDealersOffersListAdapter(private val onItemClicked : (agrodealerOffers: AgroDealerOffers) -> Unit) : RecyclerView.Adapter<AgroDealersOffersListAdapter.MyViewHolder>() { | ||
|
||
private var offers: List<AgroDealerOffers> = ArrayList() | ||
|
||
inner class MyViewHolder(private val binding: ItemAgrodealersDealsRowBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
val buttonShopNow : Button = binding.buttonAddToCartShopNow | ||
|
||
fun bind(offer: AgroDealerOffers) { | ||
binding.imageViewProductFarmInputName.setImageResource(offer.productImageResId) | ||
binding.textViewProductName.text = offer.productName | ||
binding.textViewDiscountPercentage.text = offer.discountPercentage | ||
binding.textViewOriginalPrice.text = "Kes. "+offer.originalPrice.toString() | ||
binding.textViewProductPriceDiscounted.text = "Kes. "+offer.discountedPrice.toString() | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | ||
val binding = | ||
ItemAgrodealersDealsRowBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return MyViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | ||
val offer = offers[position] | ||
holder.bind(offer) | ||
|
||
holder.itemView.setOnClickListener { | ||
onItemClicked(offer) | ||
} | ||
holder.buttonShopNow.setOnClickListener { | ||
onItemClicked(offer) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return offers.size | ||
} | ||
|
||
@SuppressLint("NotifyDataSetChanged") | ||
fun submitList(offersList: List<AgroDealerOffers>) { | ||
offers = offersList | ||
notifyDataSetChanged() | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/steve_md/smartmkulima/adapter/AgroDealsCartItemsListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.steve_md.smartmkulima.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.steve_md.smartmkulima.databinding.ItemDealAgrodealerAddToCartBinding | ||
import com.steve_md.smartmkulima.model.FarmInputAgroDealerCartItem | ||
|
||
|
||
/** | ||
* Will Attach to the Ui all the cart items stored temporary in the ViewModel | ||
*/ | ||
class AgroDealsCartItemsListAdapter (private val onClickListener: OnClickListener) | ||
: ListAdapter<FarmInputAgroDealerCartItem, AgroDealsCartItemsListAdapter.MyViewHolder>(MyDiffUtil) { | ||
object MyDiffUtil : DiffUtil.ItemCallback<FarmInputAgroDealerCartItem>() { | ||
override fun areItemsTheSame(oldItem: FarmInputAgroDealerCartItem, newItem: FarmInputAgroDealerCartItem): Boolean { | ||
return oldItem.offerProduct.id == newItem.offerProduct.id | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: FarmInputAgroDealerCartItem, newItem: FarmInputAgroDealerCartItem): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
} | ||
inner class MyViewHolder(private val binding: ItemDealAgrodealerAddToCartBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
val btnRemoveItemFromCart = binding.buttonRemoveCartItem | ||
val btnIncreaseQ = binding.imageButtonIncrease | ||
val btnDecreaseQ = binding.imageButtonDecrease | ||
|
||
@SuppressLint("SetTextI18n") | ||
fun bind(offerAddedToCart: FarmInputAgroDealerCartItem?) { | ||
binding.textViewProductName.text = offerAddedToCart?.offerProduct?.productName | ||
binding.textViewProductPriceAfterDiscount.text = "Kes. "+offerAddedToCart?.offerProduct?.discountedPrice.toString() | ||
binding.textViewDiscountPercentage.text = offerAddedToCart?.offerProduct?.discountPercentage | ||
|
||
Glide.with(binding.imageViewProductFarmInputName) | ||
.load(offerAddedToCart?.offerProduct?.productImageResId) | ||
.centerCrop() | ||
.into(binding.imageViewProductFarmInputName) | ||
|
||
binding.textViewCartValue.text = offerAddedToCart?.quantity.toString() | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { | ||
return MyViewHolder( | ||
ItemDealAgrodealerAddToCartBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} | ||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | ||
val offerAddedToCart = getItem(position) | ||
holder.bind(offerAddedToCart) | ||
|
||
holder.btnRemoveItemFromCart.setOnClickListener { | ||
onClickListener.onClick(offerAddedToCart) | ||
} | ||
|
||
holder.btnIncreaseQ.setOnClickListener { | ||
onClickListener.onIncreaseQuantity(offerAddedToCart) | ||
} | ||
|
||
holder.btnDecreaseQ.setOnClickListener { | ||
onClickListener.onDecreaseQuantity(offerAddedToCart) | ||
} | ||
|
||
|
||
} | ||
|
||
class OnClickListener( | ||
val clickListener: (cart: FarmInputAgroDealerCartItem) -> Unit, | ||
val increaseQuantity: (cartItem: FarmInputAgroDealerCartItem) -> Unit, | ||
val decreaseQuantity: (cartItem: FarmInputAgroDealerCartItem) -> Unit | ||
) { | ||
fun onClick(cart: FarmInputAgroDealerCartItem) = clickListener(cart) | ||
fun onIncreaseQuantity(cart: FarmInputAgroDealerCartItem) = increaseQuantity(cart) | ||
fun onDecreaseQuantity(cart: FarmInputAgroDealerCartItem) = decreaseQuantity(cart) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/steve_md/smartmkulima/model/FarmInputAgroDealerCartItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.steve_md.smartmkulima.model | ||
|
||
/** | ||
* The Cart item for Agricultural inputs | ||
*/ | ||
data class FarmInputAgroDealerCartItem( | ||
val offerProduct: AgroDealerOffers, | ||
var quantity: Int = 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.