Archived
Timetable now shows the schedule for the current day when opening the app
This commit is contained in:
@@ -15,6 +15,10 @@ import com.denizk0461.studip.data.DummyData
|
||||
import com.denizk0461.studip.data.StudIPParser
|
||||
import com.denizk0461.studip.databinding.FragmentEventBinding
|
||||
import com.denizk0461.studip.viewmodel.EventViewModel
|
||||
import java.time.DayOfWeek
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalTime
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass as the default destination in the navigation.
|
||||
@@ -28,6 +32,7 @@ class EventFragment : Fragment() {
|
||||
private val binding get() = _binding!!
|
||||
private lateinit var recyclerViewAdapter: StudIPEventPageAdapter
|
||||
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
|
||||
private var dayOfWeek: Int = 0
|
||||
|
||||
private val viewModel: EventViewModel by viewModels()
|
||||
|
||||
@@ -39,6 +44,14 @@ class EventFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
dayOfWeek = when (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.TUESDAY -> 1
|
||||
Calendar.WEDNESDAY -> 2
|
||||
Calendar.THURSDAY -> 3
|
||||
Calendar.FRIDAY -> 4
|
||||
else -> 0
|
||||
}
|
||||
|
||||
viewModel.allEvents.observe(viewLifecycleOwner) { events ->
|
||||
recyclerViewAdapter = StudIPEventPageAdapter(events)//DummyData.events.toList())
|
||||
binding.recyclerView.adapter = recyclerViewAdapter
|
||||
@@ -47,7 +60,8 @@ class EventFragment : Fragment() {
|
||||
binding.recyclerView.layoutManager = recyclerViewLayoutManager
|
||||
binding.recyclerView.onFlingListener = null
|
||||
PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
|
||||
binding.recyclerView.scheduleLayoutAnimation()
|
||||
// binding.recyclerView.scheduleLayoutAnimation()
|
||||
binding.recyclerView.scrollToPosition(dayOfWeek)
|
||||
}
|
||||
|
||||
// viewModel.doAsync { StudIPParser().parse(requireContext()) }
|
||||
|
||||
Reference in New Issue
Block a user