2023-04-08 11:41:02 +02:00
|
|
|
package com.denizk0461.studip.fragment
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
2023-04-08 17:30:05 +02:00
|
|
|
import androidx.fragment.app.viewModels
|
2023-04-10 14:50:57 +02:00
|
|
|
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
|
2023-04-08 13:43:26 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
import androidx.recyclerview.widget.PagerSnapHelper
|
2023-04-10 14:50:57 +02:00
|
|
|
import com.denizk0461.studip.R
|
2023-04-08 15:13:11 +02:00
|
|
|
import com.denizk0461.studip.adapter.StudIPEventPageAdapter
|
2023-04-08 13:43:26 +02:00
|
|
|
import com.denizk0461.studip.data.DummyData
|
2023-04-10 20:54:15 +02:00
|
|
|
import com.denizk0461.studip.data.StudIPParser
|
2023-04-08 17:30:05 +02:00
|
|
|
import com.denizk0461.studip.databinding.FragmentEventBinding
|
|
|
|
|
import com.denizk0461.studip.viewmodel.EventViewModel
|
2023-04-08 11:41:02 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A simple [Fragment] subclass as the default destination in the navigation.
|
|
|
|
|
*/
|
2023-04-08 17:30:05 +02:00
|
|
|
class EventFragment : Fragment() {
|
2023-04-08 11:41:02 +02:00
|
|
|
|
2023-04-08 17:30:05 +02:00
|
|
|
private var _binding: FragmentEventBinding? = null
|
2023-04-08 11:41:02 +02:00
|
|
|
|
|
|
|
|
// This property is only valid between onCreateView and
|
|
|
|
|
// onDestroyView.
|
|
|
|
|
private val binding get() = _binding!!
|
2023-04-08 15:13:11 +02:00
|
|
|
private lateinit var recyclerViewAdapter: StudIPEventPageAdapter
|
2023-04-08 13:43:26 +02:00
|
|
|
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
|
2023-04-08 11:41:02 +02:00
|
|
|
|
2023-04-08 17:30:05 +02:00
|
|
|
private val viewModel: EventViewModel by viewModels()
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
|
|
_binding = FragmentEventBinding.inflate(inflater, container, false)
|
2023-04-08 11:41:02 +02:00
|
|
|
return binding.root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
2023-04-08 17:30:05 +02:00
|
|
|
viewModel.allEvents.observe(viewLifecycleOwner) { events ->
|
2023-04-10 20:54:15 +02:00
|
|
|
recyclerViewAdapter = StudIPEventPageAdapter(events)//DummyData.events.toList())
|
2023-04-08 17:30:05 +02:00
|
|
|
binding.recyclerView.adapter = recyclerViewAdapter
|
|
|
|
|
recyclerViewLayoutManager =
|
|
|
|
|
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
|
|
|
|
binding.recyclerView.layoutManager = recyclerViewLayoutManager
|
2023-04-10 20:54:15 +02:00
|
|
|
binding.recyclerView.onFlingListener = null
|
2023-04-08 17:30:05 +02:00
|
|
|
PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
|
|
|
|
|
binding.recyclerView.scheduleLayoutAnimation()
|
|
|
|
|
}
|
2023-04-08 13:43:26 +02:00
|
|
|
|
2023-04-10 20:54:15 +02:00
|
|
|
// viewModel.doAsync { StudIPParser().parse(requireContext()) }
|
2023-04-08 18:53:51 +02:00
|
|
|
|
2023-04-10 14:50:57 +02:00
|
|
|
binding.fab.setOnClickListener { view ->
|
|
|
|
|
launchWebview()
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 11:41:02 +02:00
|
|
|
// binding.buttonFirst.setOnClickListener {
|
|
|
|
|
// findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDestroyView() {
|
|
|
|
|
super.onDestroyView()
|
|
|
|
|
_binding = null
|
|
|
|
|
}
|
2023-04-10 14:50:57 +02:00
|
|
|
|
|
|
|
|
private fun launchWebview() {
|
|
|
|
|
findNavController(this).navigate(R.id.action_FirstFragment_to_SecondFragment)
|
|
|
|
|
}
|
2023-04-08 11:41:02 +02:00
|
|
|
}
|