-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
388 additions
and
53 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
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
10 changes: 9 additions & 1 deletion
10
app/src/main/java/com/muhammedesadcomert/shopping/data/remote/ApiService.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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
package com.muhammedesadcomert.shopping.data.remote | ||
|
||
import com.muhammedesadcomert.shopping.ui.home.model.CategoryApiModel | ||
import com.muhammedesadcomert.shopping.ui.home.model.ProductApiModel | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface ApiService { | ||
@GET("categories") | ||
suspend fun getCategories(): Response<CategoryApiModel> | ||
} | ||
|
||
@GET("products/advanced-filtered") | ||
suspend fun getProducts( | ||
@Query("categoryId") categoryId: String, | ||
@Query("sort") sort: String, | ||
): Response<ProductApiModel> | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/muhammedesadcomert/shopping/ui/home/ProductAdapter.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,51 @@ | ||
package com.muhammedesadcomert.shopping.ui.home | ||
|
||
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.muhammedesadcomert.shopping.databinding.ProductItemBinding | ||
import com.muhammedesadcomert.shopping.ui.home.ProductAdapter.ProductViewHolder | ||
import com.muhammedesadcomert.shopping.ui.home.model.Product | ||
|
||
class ProductAdapter(private val onItemClicked: (Product) -> Unit) : | ||
ListAdapter<Product, ProductViewHolder>(DIFF_CALLBACK) { | ||
inner class ProductViewHolder(private val binding: ProductItemBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun bind(product: Product) { | ||
with(binding) { | ||
textViewProductTitle.text = product.title | ||
textViewProductPrice.text = "$".plus(product.price.toString()) | ||
Glide.with(itemView).load(product.featuredImage!!.t).into(imageViewProductImage) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder { | ||
return ProductViewHolder( | ||
ProductItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ProductViewHolder, position: Int) { | ||
val product = currentList[position] | ||
holder.bind(product) | ||
holder.itemView.setOnClickListener { | ||
onItemClicked(product) | ||
} | ||
} | ||
|
||
companion object { | ||
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Product>() { | ||
override fun areItemsTheSame(oldItem: Product, newItem: Product): Boolean { | ||
return oldItem == newItem | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: Product, newItem: Product): Boolean { | ||
return oldItem == newItem | ||
} | ||
} | ||
} | ||
} |
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.