Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Quizzes #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.ViewStub
import android.widget.TextView
import androidx.core.app.NavUtils
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -56,9 +57,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 +75,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 +110,23 @@ 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 +140,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 @@ -143,7 +180,7 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
android.R.id.home -> {
NavUtils.navigateUpFromSameTask(this)
true
}
Expand All @@ -156,7 +193,7 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
dialog.show(supportFragmentManager, CreateTicketDialog.TAG)
true
}
else -> super.onOptionsItemSelected(item)
else -> super.onOptionsItemSelected(item)
}
}

Expand All @@ -170,7 +207,10 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
}
}

inner class ItemsPagerAdapter(private val fragmentManager: FragmentManager, private val items: List<Item>) : FragmentPagerAdapter(fragmentManager), TabLayout.OnTabSelectedListener {
inner class ItemsPagerAdapter(
private val fragmentManager: FragmentManager,
private val items: List<Item>
) : FragmentPagerAdapter(fragmentManager), TabLayout.OnTabSelectedListener {

fun getCustomTabView(position: Int, currentPosition: Int, parent: ViewGroup): View =
layoutInflater.inflate(R.layout.view_tab_section, parent, false).apply {
Expand Down Expand Up @@ -211,16 +251,40 @@ 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 +322,5 @@ class CourseItemsActivity : ViewModelActivity<CourseItemsViewModel>() {
}

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

}

}
Loading