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.data.StudIPParser
|
||||||
import com.denizk0461.studip.databinding.FragmentEventBinding
|
import com.denizk0461.studip.databinding.FragmentEventBinding
|
||||||
import com.denizk0461.studip.viewmodel.EventViewModel
|
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.
|
* A simple [Fragment] subclass as the default destination in the navigation.
|
||||||
@@ -28,6 +32,7 @@ class EventFragment : Fragment() {
|
|||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private lateinit var recyclerViewAdapter: StudIPEventPageAdapter
|
private lateinit var recyclerViewAdapter: StudIPEventPageAdapter
|
||||||
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
|
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
|
||||||
|
private var dayOfWeek: Int = 0
|
||||||
|
|
||||||
private val viewModel: EventViewModel by viewModels()
|
private val viewModel: EventViewModel by viewModels()
|
||||||
|
|
||||||
@@ -39,6 +44,14 @@ class EventFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
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 ->
|
viewModel.allEvents.observe(viewLifecycleOwner) { events ->
|
||||||
recyclerViewAdapter = StudIPEventPageAdapter(events)//DummyData.events.toList())
|
recyclerViewAdapter = StudIPEventPageAdapter(events)//DummyData.events.toList())
|
||||||
binding.recyclerView.adapter = recyclerViewAdapter
|
binding.recyclerView.adapter = recyclerViewAdapter
|
||||||
@@ -47,7 +60,8 @@ class EventFragment : Fragment() {
|
|||||||
binding.recyclerView.layoutManager = recyclerViewLayoutManager
|
binding.recyclerView.layoutManager = recyclerViewLayoutManager
|
||||||
binding.recyclerView.onFlingListener = null
|
binding.recyclerView.onFlingListener = null
|
||||||
PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
|
PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
|
||||||
binding.recyclerView.scheduleLayoutAnimation()
|
// binding.recyclerView.scheduleLayoutAnimation()
|
||||||
|
binding.recyclerView.scrollToPosition(dayOfWeek)
|
||||||
}
|
}
|
||||||
|
|
||||||
// viewModel.doAsync { StudIPParser().parse(requireContext()) }
|
// viewModel.doAsync { StudIPParser().parse(requireContext()) }
|
||||||
|
|||||||
Reference in New Issue
Block a user