Skip to content

Commit

Permalink
finish material details
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedshasho committed Aug 14, 2023
1 parent bfc5fca commit 5a67211
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Review> = emptyList(),
private var items: List<Rate> = emptyList(),
) : RecyclerView.Adapter<MaterialReviewAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand All @@ -16,7 +16,7 @@ class MaterialReviewAdapter(
return ViewHolder(binding)
}

fun setMaterialReviewsList(newItems: List<Review>) {
fun setMaterialReviewsList(newItems: List<Rate>) {
items = newItems
notifyItemChanged(0, newItems.size)
}
Expand All @@ -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

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_material_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/material_teacher_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
Expand Down
44 changes: 37 additions & 7 deletions app/src/main/res/layout/fragment_material_information.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".ui.materials.detail.MaterialInformationFragment"
android:padding="20dp">

<TextView
android:id="@+id/material_information_description"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subject"
android:layout_marginBottom="5dp"
android:textAppearance="@style/TextBody1"
android:textStyle="normal"/>

<TextView
android:id="@+id/material_information_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subject"
android:layout_marginBottom="5dp"
android:layout_marginStart="5dp"
android:textAppearance="@style/TextBody1"/>
</LinearLayout>

<TextView
android:id="@+id/material_information_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_blank_fragment"
android:layout_marginBottom="20dp"
android:textAppearance="@style/TextBody1"/>

</FrameLayout>
<TextView
android:id="@+id/material_information_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_blank_fragment"
android:textAppearance="@style/TextBody2"/>
</LinearLayout>
14 changes: 9 additions & 5 deletions app/src/main/res/layout/material_review_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">

<ImageView
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/material_review_student_profile"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_profile" />
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"/>


<LinearLayout
android:layout_width="wrap_content"
Expand Down Expand Up @@ -55,6 +58,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:text="student comment"
android:textAppearance="@style/TextBody2" />
</LinearLayout>
Expand Down

0 comments on commit 5a67211

Please sign in to comment.