-
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
18 changed files
with
354 additions
and
67 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ class CategoryAdapter(private val onItemClicked: (Category) -> Unit) : | |
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ class ProductAdapter(private val onItemClicked: (Product) -> Unit) : | |
} | ||
} | ||
} | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
.../main/java/com/muhammedesadcomert/shopping/ui/home/productdetail/ProductDetailFragment.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,74 @@ | ||
package com.muhammedesadcomert.shopping.ui.home.productdetail | ||
|
||
import android.graphics.Color | ||
import android.graphics.Paint | ||
import android.os.Bundle | ||
import android.text.Html | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import com.bumptech.glide.Glide | ||
import com.muhammedesadcomert.shopping.R | ||
import com.muhammedesadcomert.shopping.databinding.FragmentProductDetailBinding | ||
import com.muhammedesadcomert.shopping.ui.home.HomeViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class ProductDetailFragment : Fragment() { | ||
|
||
private var _binding: FragmentProductDetailBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private val viewModel: HomeViewModel by viewModels() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentProductDetailBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupDetails() | ||
} | ||
|
||
private fun setupDetails() { | ||
viewModel.getSingleProductDetail(requireArguments().get("productId") as String) | ||
viewModel.productDetail.observe(viewLifecycleOwner) { product -> | ||
with(binding) { | ||
textViewProductTitle.text = product.title | ||
textViewProductPrice.text = | ||
(product.price.toString()).plus(getString(R.string.price_postfix)) | ||
|
||
if (product.campaignPrice != null && product.campaignPrice != product.price) { | ||
textViewProductPrice.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG | ||
textViewProductPrice.setTextColor(Color.GRAY) | ||
textViewProductPrice.textSize = 16f | ||
textViewProductCampaignPrice.text = | ||
(product.campaignPrice.toString()).plus(getString(R.string.price_postfix)) | ||
textViewProductCampaignPrice.visibility = View.VISIBLE | ||
} | ||
|
||
if (product.stock == 0) { | ||
imageViewSoldOut.visibility = View.VISIBLE | ||
} | ||
|
||
textViewProductDescription.text = | ||
Html.fromHtml(product.description, Html.FROM_HTML_MODE_LEGACY) | ||
Glide.with(requireContext()).load(product.featuredImage!!.n) | ||
.placeholder(R.drawable.blank_screen) | ||
.into(imageViewProductImage) | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
Oops, something went wrong.