2023-04-16 21:41:46 +02:00
|
|
|
package com.denizk0461.studip.adapter
|
|
|
|
|
|
2023-04-30 22:47:59 +02:00
|
|
|
import android.os.Bundle
|
2023-04-27 21:58:10 +02:00
|
|
|
import androidx.fragment.app.Fragment
|
2023-04-30 22:47:59 +02:00
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
|
import androidx.lifecycle.Lifecycle
|
2023-04-27 21:58:10 +02:00
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
|
|
|
|
import com.denizk0461.studip.fragment.CanteenPageFragment
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
/**
|
2023-04-27 21:58:10 +02:00
|
|
|
* Custom ViewPager adapter for managing multiple pages of canteen offers.
|
2023-04-23 11:57:03 +02:00
|
|
|
*
|
2023-04-30 22:47:59 +02:00
|
|
|
* @param childFragmentManager child fragment manager of the parent fragment
|
|
|
|
|
* @param lifecycle parent fragment lifecycle
|
2023-04-23 11:57:03 +02:00
|
|
|
*/
|
|
|
|
|
class CanteenOfferPageAdapter(
|
2023-04-30 22:47:59 +02:00
|
|
|
childFragmentManager: FragmentManager,
|
|
|
|
|
lifecycle: Lifecycle,
|
|
|
|
|
) : FragmentStateAdapter(childFragmentManager, lifecycle) {
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-28 22:44:23 +02:00
|
|
|
private var count: Int = 0
|
|
|
|
|
|
2023-04-23 11:57:03 +02:00
|
|
|
// Returns the count of days covered
|
2023-04-28 22:44:23 +02:00
|
|
|
override fun getItemCount(): Int = count
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-27 21:58:10 +02:00
|
|
|
override fun createFragment(position: Int): Fragment =
|
2023-04-30 22:47:59 +02:00
|
|
|
CanteenPageFragment().also { f ->
|
|
|
|
|
val bundle = Bundle()
|
|
|
|
|
bundle.putInt("currentDay", position)
|
|
|
|
|
f.arguments = bundle
|
|
|
|
|
}
|
2023-04-16 21:41:46 +02:00
|
|
|
|
2023-04-28 22:44:23 +02:00
|
|
|
fun setItemCount(newCount: Int) {
|
|
|
|
|
count = newCount
|
2023-04-16 21:41:46 +02:00
|
|
|
notifyDataSetChanged()
|
|
|
|
|
}
|
|
|
|
|
}
|