From 5a67211a595e0907c3fc31d607a5caf28d79e2c2 Mon Sep 17 00:00:00 2001 From: mohamedshasho Date: Mon, 14 Aug 2023 21:00:22 +0300 Subject: [PATCH] finish material details --- .../center/adapter/MaterialReviewAdapter.kt | 8 ++-- .../ui/dialogs/LoadingDialogFragment.kt | 18 ++++++++ .../detail/MaterialDetailFragment.kt | 28 ++++++++++-- .../detail/MaterialInformationFragment.kt | 17 ++++++- .../detail/MaterialReviewsFragment.kt | 18 ++++---- .../res/layout/fragment_material_detail.xml | 1 + .../layout/fragment_material_information.xml | 44 ++++++++++++++++--- .../main/res/layout/material_review_item.xml | 14 +++--- 8 files changed, 119 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/scholar/center/ui/dialogs/LoadingDialogFragment.kt diff --git a/app/src/main/java/com/scholar/center/adapter/MaterialReviewAdapter.kt b/app/src/main/java/com/scholar/center/adapter/MaterialReviewAdapter.kt index 6ce3a5b..09171c4 100644 --- a/app/src/main/java/com/scholar/center/adapter/MaterialReviewAdapter.kt +++ b/app/src/main/java/com/scholar/center/adapter/MaterialReviewAdapter.kt @@ -4,10 +4,10 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.scholar.center.databinding.MaterialReviewItemBinding -import com.scholar.domain.model.Review +import com.scholar.domain.model.Rate class MaterialReviewAdapter( - private var items: List = emptyList(), + private var items: List = emptyList(), ) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { @@ -16,7 +16,7 @@ class MaterialReviewAdapter( return ViewHolder(binding) } - fun setMaterialReviewsList(newItems: List) { + fun setMaterialReviewsList(newItems: List) { items = newItems notifyItemChanged(0, newItems.size) } @@ -25,7 +25,7 @@ class MaterialReviewAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { val item = items[position] - holder.binding.materialReviewRatingBar.rating = item.rating + holder.binding.materialReviewRatingBar.rating = item.rate.toFloat() holder.binding.materialReviewStudentComment.text = item.comment } diff --git a/app/src/main/java/com/scholar/center/ui/dialogs/LoadingDialogFragment.kt b/app/src/main/java/com/scholar/center/ui/dialogs/LoadingDialogFragment.kt new file mode 100644 index 0000000..25b412a --- /dev/null +++ b/app/src/main/java/com/scholar/center/ui/dialogs/LoadingDialogFragment.kt @@ -0,0 +1,18 @@ +package com.scholar.center.ui.dialogs + + +import android.app.Dialog +import android.os.Bundle +import android.view.Window +import androidx.fragment.app.DialogFragment +import com.scholar.center.R + +class LoadingDialogFragment : DialogFragment(R.layout.dialog_loading) { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) + dialog.setCancelable(false) + dialog.setCanceledOnTouchOutside(false) + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) + return dialog + } +} \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt index e10cd2b..6b1c1b6 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialDetailFragment.kt @@ -9,10 +9,13 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.fragment.findNavController +import com.bumptech.glide.Glide import com.google.android.material.tabs.TabLayoutMediator import com.scholar.center.R import com.scholar.center.adapter.TeacherPagerAdapter import com.scholar.center.databinding.FragmentMaterialDetailBinding +import com.scholar.center.ui.dialogs.LoadingDialogFragment +import com.scholar.center.unit.Constants.BASE_URL import com.scholar.center.unit.applyDiscount import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @@ -31,7 +34,7 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { val viewPager = binding.materialViewPager val fragments = listOf( - MaterialInformationFragment(), MaterialReviewsFragment(), + MaterialInformationFragment(viewModel), MaterialReviewsFragment(viewModel), ) val materialAdapter = TeacherPagerAdapter( fragments = fragments, @@ -46,11 +49,16 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { else -> throw IllegalArgumentException("Invalid position: $position") } }.attach() - + val loadingDialog = LoadingDialogFragment() viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.material.collect { + if (it == null) { + loadingDialog.show(parentFragmentManager, "loading_dialog") + } it?.let { materialWithDetail -> + + val material = materialWithDetail.material binding.materialName.text = material.title binding.materialType.text = materialWithDetail.category @@ -75,14 +83,28 @@ class MaterialDetailFragment : Fragment(R.layout.fragment_material_detail) { ) } else { binding.materialDiscount.visibility = View.GONE - binding.materialPriceValue.text = getString(R.string.syr, material.price) + binding.materialPriceValue.text = + getString(R.string.syr, material.price) } } else { binding.materialPriceLayout.visibility = View.GONE binding.materialPriceButton.text = getText(R.string.view) } + if (materialWithDetail.teacher.name != null) { + binding.materialTeacherName.text = materialWithDetail.teacher.name + materialWithDetail.teacher.image?.let { image -> + Glide.with(requireContext()) + .load("${BASE_URL}$image") + .placeholder(R.drawable.ic_person) + .error(R.drawable.ic_person) + .into(binding.materialTeacherImage) + } + } else { + binding.materialTeacherLayout.visibility = View.GONE + } + loadingDialog.dismiss() binding.materialPriceButton.setOnClickListener { diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialInformationFragment.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialInformationFragment.kt index 0848618..6fc52c3 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialInformationFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialInformationFragment.kt @@ -3,14 +3,27 @@ package com.scholar.center.ui.materials.detail import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope import com.scholar.center.R import com.scholar.center.databinding.FragmentMaterialInformationBinding +import kotlinx.coroutines.launch -class MaterialInformationFragment : Fragment(R.layout.fragment_material_information) { +class MaterialInformationFragment(private val viewModel: MaterialDetailVM) : + Fragment(R.layout.fragment_material_information) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val binding = FragmentMaterialInformationBinding.bind(view) - binding.materialInformationDescription.text = " نوطة رياضيات\n نوطة رياضيات للصف الاول شاملة " + lifecycleScope.launch { + viewModel.material.collect { + it?.let { materialWithDetail -> + binding.materialInformationSubject.text = materialWithDetail.subject + binding.materialInformationTitle.text = materialWithDetail.material.title + binding.materialInformationDescription.text = + materialWithDetail.material.description + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt index 5af2904..bde5511 100644 --- a/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt +++ b/app/src/main/java/com/scholar/center/ui/materials/detail/MaterialReviewsFragment.kt @@ -3,14 +3,16 @@ package com.scholar.center.ui.materials.detail import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.scholar.center.R import com.scholar.center.adapter.MaterialReviewAdapter import com.scholar.center.databinding.FragmentMaterialReviewsBinding import com.scholar.domain.model.Review +import kotlinx.coroutines.launch -class MaterialReviewsFragment : Fragment(R.layout.fragment_material_reviews) { +class MaterialReviewsFragment(private val viewModel:MaterialDetailVM) : Fragment(R.layout.fragment_material_reviews) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -24,13 +26,13 @@ class MaterialReviewsFragment : Fragment(R.layout.fragment_material_reviews) { adapter = reviewsAdapter } - val list = listOf( - TestR(1, 3.5f, "comment 1"), - TestR(1, 5f, "comment 2"), - TestR(1, 2f, "comment 3") - ) - reviewsAdapter.setMaterialReviewsList(list) - + lifecycleScope.launch { + viewModel.material.collect { + it?.let { materialWithDetail -> + reviewsAdapter.setMaterialReviewsList(materialWithDetail.rates) + } + } + } } } diff --git a/app/src/main/res/layout/fragment_material_detail.xml b/app/src/main/res/layout/fragment_material_detail.xml index 0f89427..b849ce6 100644 --- a/app/src/main/res/layout/fragment_material_detail.xml +++ b/app/src/main/res/layout/fragment_material_detail.xml @@ -129,6 +129,7 @@ - - + + + + + + + - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/material_review_item.xml b/app/src/main/res/layout/material_review_item.xml index 827b1f4..3cf12a0 100644 --- a/app/src/main/res/layout/material_review_item.xml +++ b/app/src/main/res/layout/material_review_item.xml @@ -19,12 +19,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> - - + android:layout_width="40dp" + android:layout_height="40dp" + android:src="@drawable/ic_person" + android:layout_marginStart="5dp" + app:civ_border_width="1dp" + app:civ_border_color="#FF000000"/> +