diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/courses/CourseDetailFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/courses/CourseDetailFragment.kt index 2c532715ef..3805144cfd 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/courses/CourseDetailFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/courses/CourseDetailFragment.kt @@ -5,26 +5,21 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView -import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import io.realm.Realm import org.ole.planet.myplanet.MainApplication -import org.ole.planet.myplanet.R import org.ole.planet.myplanet.base.BaseContainerFragment import org.ole.planet.myplanet.callback.OnRatingChangeListener import org.ole.planet.myplanet.databinding.FragmentCourseDetailBinding import org.ole.planet.myplanet.datamanager.DatabaseService -import org.ole.planet.myplanet.model.RealmCourseProgress import org.ole.planet.myplanet.model.RealmMyCourse import org.ole.planet.myplanet.model.RealmMyCourse.Companion.getCourseSteps import org.ole.planet.myplanet.model.RealmMyLibrary import org.ole.planet.myplanet.model.RealmRating.Companion.getRatingsById -import org.ole.planet.myplanet.model.RealmRemovedLog import org.ole.planet.myplanet.model.RealmStepExam.Companion.getNoOfExam import org.ole.planet.myplanet.model.RealmUserModel import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.utilities.Markdown.setMarkdownText -import org.ole.planet.myplanet.utilities.Utilities class CourseDetailFragment() : BaseContainerFragment(), OnRatingChangeListener { private lateinit var fragmentCourseDetailBinding: FragmentCourseDetailBinding @@ -94,13 +89,4 @@ class CourseDetailFragment() : BaseContainerFragment(), OnRatingChangeListener { super.onDownloadComplete() setCourseData() } - - private fun getCourseProgress(): Int { - val realm = DatabaseService(requireActivity()).realmInstance - val user = UserProfileDbHandler(requireActivity()).userModel - val courseProgressMap = RealmCourseProgress.getCourseProgress(realm, user?.id) - // Extract the current progress for the specific courseId - val courseProgress = courseProgressMap[courses?.courseId]?.asJsonObject?.get("current")?.asInt - return courseProgress ?: 0 - } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/courses/TakeCourseFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/courses/TakeCourseFragment.kt index 4896314892..b3b02b4924 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/courses/TakeCourseFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/courses/TakeCourseFragment.kt @@ -77,7 +77,11 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl setCourseData() setListeners() currentStep = getCourseProgress() - fragmentTakeCourseBinding.viewPager2.currentItem = currentStep + if (currentStep != 0) { + position = currentStep - 1 + } + fragmentTakeCourseBinding.viewPager2.currentItem = position + } private fun setListeners() {