Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
bengelhaupt committed Apr 16, 2020
1 parent 510a544 commit 8ad0585
Show file tree
Hide file tree
Showing 44 changed files with 2,280 additions and 35 deletions.
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

0 comments on commit 8ad0585

Please sign in to comment.