Transitioned from a fairly custom solution to using a colour palette generated by the Material Theme Builder to simplify colour management. Also began work on a bottom sheet for displaying allergens and additives in canteen offers.

This commit is contained in:
denizk0461
2023-04-23 17:13:48 +02:00
parent fbad84aa09
commit b957172721
42 changed files with 456 additions and 273 deletions
@@ -0,0 +1,21 @@
package com.denizk0461.studip.fragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.denizk0461.studip.sheet.AppSheet
/**
* Fragment super class providing common functionality. Fragments are used for providing the user
* with different views and functionality. All fragments should inherit from this.
*/
open class AppFragment : Fragment() {
/**
* Opens a bottom sheet. Sheet must be a subclass of [com.denizk0461.studip.sheet.AppSheet].
*
* @param sheet element that will be displayed
*/
protected fun openBottomSheet(sheet: AppSheet) {
sheet.show((context as FragmentActivity).supportFragmentManager, sheet.javaClass.simpleName)
}
}
@@ -5,11 +5,12 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.denizk0461.studip.adapter.CanteenOfferItemAdapter
import com.denizk0461.studip.adapter.CanteenOfferPageAdapter
import com.denizk0461.studip.databinding.FragmentCanteenBinding
import com.denizk0461.studip.model.*
import com.denizk0461.studip.sheet.AllergenSheet
import com.denizk0461.studip.viewmodel.CanteenViewModel
import com.google.android.material.tabs.TabLayoutMediator
@@ -17,7 +18,7 @@ import com.google.android.material.tabs.TabLayoutMediator
* User-facing fragment view that displays the canteen offers from the website of the
* Studierendenwerk Bremen.
*/
class CanteenFragment : Fragment() {
class CanteenFragment : AppFragment(), CanteenOfferItemAdapter.OnClickListener {
// Nullable view binding reference
private var _binding: FragmentCanteenBinding? = null
@@ -91,7 +92,7 @@ class CanteenFragment : Fragment() {
}
// Set up the view pager's adapter
viewPagerAdapter = CanteenOfferPageAdapter(listOf(), 0)
viewPagerAdapter = CanteenOfferPageAdapter(listOf(), 0, this)
// Assign the adapter to the view pager
binding.viewPager.adapter = viewPagerAdapter
@@ -268,4 +269,23 @@ class CanteenFragment : Fragment() {
)
}
}
/**
* Executed when an item has been clicked.
*
* @param offer item that has been clicked
*/
override fun onClick(offer: CanteenOfferGroupElement) {
openBottomSheet(AllergenSheet(offer))
}
/**
* Executed when an item has been long-pressed.
*
* @param offer item that has been long-pressed
* @return whether the long press was successful
*/
override fun onLongClick(offer: CanteenOfferGroupElement): Boolean {
return false
}
}
@@ -1,7 +1,6 @@
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
@@ -18,7 +17,7 @@ import java.util.*
/**
* User-facing fragment view that displays the user's Stud.IP schedule.
*/
class EventFragment : Fragment() {
class EventFragment : AppFragment() {
// Nullable view binding reference
private var _binding: FragmentEventBinding? = null
@@ -7,7 +7,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.denizk0461.studip.BuildConfig
import com.denizk0461.studip.activity.FetcherActivity
import com.denizk0461.studip.databinding.FragmentSettingsBinding
@@ -15,7 +14,7 @@ import com.denizk0461.studip.databinding.FragmentSettingsBinding
/**
* User-facing fragment view that is used to change app settings.
*/
class SettingsFragment : Fragment() {
class SettingsFragment : AppFragment() {
// Nullable view binding reference
private var _binding: FragmentSettingsBinding? = null