Skip to content

Commit

Permalink
Implement native quizzes
Browse files Browse the repository at this point in the history
  • Loading branch information
bengelhaupt committed Apr 9, 2020
1 parent 510a544 commit da851e5
Show file tree
Hide file tree
Showing 44 changed files with 2,124 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package de.xikolo.controllers.section

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.TextView
import androidx.core.app.NavUtils
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -56,9 +53,14 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
@BindView(R.id.tabs)
lateinit var tabLayout: TabLayout

@BindView(R.id.stub_bottom)
lateinit var stubBottom: ViewStub

private var course: Course? = null
private var section: Section? = null

var activeFragment: Fragment? = null

override fun createViewModel(): CourseItemsViewModel {
return CourseItemsViewModel(courseId, sectionId)
}
Expand All @@ -69,6 +71,11 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
setContentView(R.layout.activity_blank_tabs)
setupActionBar()

if (stubBottom.parent != null) {
stubBottom.layoutResource = R.layout.view_floating_button
stubBottom.inflate()
}

Crashlytics.setString("course_id", courseId)
Crashlytics.setString("section_id", sectionId)

Expand Down Expand Up @@ -99,6 +106,18 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
viewPager.adapter = adapter
viewPager.offscreenPageLimit = 2

viewPager.clearOnPageChangeListeners()
viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageSelected(position: Int) {
stubBottom.visibility = View.GONE
activeFragment = adapter.getItem(position)
(activeFragment as? QuizFragment)?.notifyActive()
}

override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
})

tabLayout.setupWithViewPager(viewPager)
tabLayout.addOnTabSelectedListener(adapter)

Expand All @@ -112,6 +131,15 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
onItemSelected(index)
}

fun updateActionButton(sender: Fragment, text: String, icon: String, click: (View) -> Unit) {
if (sender == activeFragment) {
findViewById<TextView>(R.id.actionText).text = text
findViewById<TextView>(R.id.actionIcon).text = icon
findViewById<View>(R.id.actionButton).setOnClickListener(click)
stubBottom.visibility = View.VISIBLE
}
}

private fun onItemSelected(position: Int) {
index = position

Expand Down Expand Up @@ -211,16 +239,17 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
if (fragment == null) {
fragment = if (course?.enrollment?.proctored == true && item.proctored) {
ProctoredItemFragment()
} else when (item.contentType) {
Item.TYPE_LTI -> LtiExerciseFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
Item.TYPE_PEER -> PeerAssessmentFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
Item.TYPE_QUIZ -> WebViewFragmentAutoBundle.builder(url)
} else when {
item.contentType == Item.TYPE_LTI -> LtiExerciseFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
item.contentType == Item.TYPE_PEER -> PeerAssessmentFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
item.contentType == Item.TYPE_QUIZ && item.exerciseType == Item.EXERCISE_TYPE_SELFTEST -> QuizFragmentAutoBundle.builder(courseId, sectionId, item.id, item.contentId).build()
item.contentType == Item.TYPE_QUIZ -> WebViewFragmentAutoBundle.builder(url)
.inAppLinksEnabled(true)
.externalLinksEnabled(false)
.build()
Item.TYPE_TEXT -> RichTextFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
Item.TYPE_VIDEO -> VideoPreviewFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
else -> WebViewFragmentAutoBundle.builder(url)
item.contentType == Item.TYPE_TEXT -> RichTextFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
item.contentType == Item.TYPE_VIDEO -> VideoPreviewFragmentAutoBundle.builder(courseId, sectionId, item.id).build()
else -> WebViewFragmentAutoBundle.builder(url)
.inAppLinksEnabled(false)
.externalLinksEnabled(false)
.build()
Expand Down Expand Up @@ -258,7 +287,6 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
}

override fun onTabReselected(tab: TabLayout.Tab) {}

}

}
Loading

0 comments on commit da851e5

Please sign in to comment.