From 37a94595c064a8c7feee11efc2cbee9d6671cb7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 9 Jul 2024 18:15:03 +0200 Subject: [PATCH] [UI] Enable colored app bars on scroll (#211) * Extract fragment scroll listener to separate file * Replace canRefresh with isScrolled * Add empty helper class to animate app bar color * Implement AppBarColorAnimator * Rename getRefreshScrollingView() to getScrollingView() * Set isScrolled on drag start * Clear isScrolled on fling to top * Add getSyncParams() to fragments * Convert getAppBars() to property * Tint TabLayout background drawable --- .../edziennik/ui/agenda/AgendaFragment.kt | 3 + .../ui/attendance/AttendanceFragment.kt | 2 + .../ui/attendance/AttendanceListFragment.kt | 2 +- .../attendance/AttendanceSummaryFragment.kt | 2 +- .../ui/base/fragment/ActivityUtil.kt | 49 +------ .../ui/base/fragment/BaseFragment.kt | 64 +++++++-- .../ui/base/fragment/PagerFragment.kt | 35 +++-- .../edziennik/ui/base/fragment/ScrollUtil.kt | 130 ++++++++++++++++++ .../ui/behaviour/BehaviourFragment.kt | 4 +- .../edziennik/ui/debug/LabPageFragment.kt | 2 +- .../ui/debug/LabPlaygroundFragment.kt | 2 +- .../edziennik/ui/debug/LabProfileFragment.kt | 2 +- .../edziennik/ui/grades/GradesListFragment.kt | 4 +- .../edziennik/ui/home/HomeFragment.kt | 3 +- .../ui/homework/HomeworkListFragment.kt | 4 +- .../ui/messages/list/MessagesListFragment.kt | 16 ++- .../edziennik/ui/notes/NotesFragment.kt | 1 + .../NotificationsListFragment.kt | 1 + .../ui/teachers/TeachersListFragment.kt | 2 + .../ui/template/TemplateListFragment.kt | 2 +- .../ui/template/TemplateListPageFragment.kt | 2 +- .../ui/template/TemplatePageFragment.kt | 6 +- .../ui/timetable/TimetableDayFragment.kt | 8 +- .../main/res/layout/contributors_fragment.xml | 8 +- 24 files changed, 254 insertions(+), 100 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/ScrollUtil.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/agenda/AgendaFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/agenda/AgendaFragment.kt index b7843324..8395881c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/agenda/AgendaFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/agenda/AgendaFragment.kt @@ -19,6 +19,7 @@ import kotlinx.coroutines.withContext import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.db.entity.Profile +import pl.szczodrzynski.edziennik.data.enums.FeatureType import pl.szczodrzynski.edziennik.data.enums.MetadataType import pl.szczodrzynski.edziennik.databinding.FragmentAgendaCalendarBinding import pl.szczodrzynski.edziennik.databinding.FragmentAgendaDefaultBinding @@ -45,6 +46,7 @@ class AgendaFragment : BaseFragment( override fun getFab() = R.string.add to CommunityMaterial.Icon3.cmd_plus override fun getMarkAsReadType() = MetadataType.EVENT + override fun getSyncParams() = FeatureType.AGENDA to null override fun getBottomSheetItems() = listOf( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_add_event) @@ -114,6 +116,7 @@ class AgendaFragment : BaseFragment( private suspend fun createDefaultAgendaView(b: FragmentAgendaDefaultBinding) { if (!isAdded) return + canRefreshDisabled = true checkEventTypes() delay(500) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceFragment.kt index 0b6fb457..6a58d147 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceFragment.kt @@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.ui.attendance import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.data.enums.FeatureType import pl.szczodrzynski.edziennik.data.enums.MetadataType import pl.szczodrzynski.edziennik.databinding.BasePagerFragmentBinding import pl.szczodrzynski.edziennik.ext.Bundle @@ -32,6 +33,7 @@ class AttendanceFragment : PagerFragment } override fun getMarkAsReadType() = MetadataType.ATTENDANCE + override fun getSyncParams() = FeatureType.ATTENDANCE to null override fun getBottomSheetItems() = listOf( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_attendance_config) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceListFragment.kt index 444e6288..1fe92f93 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceListFragment.kt @@ -29,7 +29,7 @@ class AttendanceListFragment : BaseFragment.setupCanRefresh() { - when (val view = getRefreshScrollingView()) { - is RecyclerView -> { - canRefresh = !view.canScrollVertically(-1) - view.addOnScrollListener(object : RecyclerView.OnScrollListener() { - override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - // disable refresh when scrolled down - if (recyclerView.canScrollVertically(-1)) - canRefresh = false - // enable refresh when scrolled to the top and not scrolling anymore - else if (newState == RecyclerView.SCROLL_STATE_IDLE) - canRefresh = true - } - }) - } - - is View -> { - canRefresh = !view.canScrollVertically(-1) - var isTouched = false - view.setOnTouchListener { _, event -> - // keep track of the touch state - when (event.action) { - MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> isTouched = false - MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> isTouched = true - } - // disable refresh when scrolled down - if (view.canScrollVertically(-1)) - canRefresh = false - // enable refresh when scrolled to the top and not touching anymore - else if (!isTouched) - canRefresh = true - false - } - } - - else -> { - // dispatch the default value to the activity - canRefresh = canRefresh - } - } -} - internal fun BaseFragment<*, *>.setupMainActivity(activity: MainActivity) { val items = getBottomSheetItems().toMutableList() getMarkAsReadType()?.let { metadataType -> @@ -97,6 +50,8 @@ internal fun BaseFragment<*, *>.setupMainActivity(activity: MainActivity) { } } } + + appBars += activity.navView.toolbar } internal fun BaseFragment<*, *>.setupLoginActivity(activity: LoginActivity) {} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/BaseFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/BaseFragment.kt index 50d8d561..84941b61 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/BaseFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/BaseFragment.kt @@ -12,6 +12,7 @@ import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.viewbinding.ViewBinding +import com.google.gson.JsonObject import com.mikepenz.iconics.typeface.IIcon import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -19,6 +20,7 @@ import kotlinx.coroutines.Job import org.greenrobot.eventbus.EventBus import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.data.enums.FeatureType import pl.szczodrzynski.edziennik.data.enums.MetadataType import pl.szczodrzynski.edziennik.ext.registerSafe import pl.szczodrzynski.edziennik.ext.startCoroutineTimer @@ -38,31 +40,37 @@ abstract class BaseFragment( private var isViewReady: Boolean = false private var inState: Bundle? = null + private var appBarAnimator: AppBarColorAnimator? = null /** - * Enables or disables the activity's SwipeRefreshLayout. - * Use only if [getRefreshScrollingView] is not used. - * - * The [PagerFragment] manages its [canRefresh] state - * based on the value of the currently selected page. + * Whether the view is currently being scrolled + * or is left scrolled away from the top. */ - internal var canRefresh = false - set(value) { + internal var isScrolled = false + set(value) { // cannot be private - PagerFragment onPageScrollStateChanged field = value - (activity as? MainActivity)?.swipeRefreshLayout?.isEnabled = - !canRefreshDisabled && value + dispatchCanRefresh() + appBarAnimator?.dispatchLiftOnScroll() } /** - * Forcefully disables the activity's SwipeRefreshLayout - * if [getRefreshScrollingView] is used. + * Forcefully disables the activity's SwipeRefreshLayout. + * + * The [PagerFragment] manages its [canRefreshDisabled] state + * based on the value of the currently selected page. */ internal var canRefreshDisabled = false set(value) { field = value - canRefresh = canRefresh + dispatchCanRefresh() } + /** + * A list of views (usually app bars) that should have their + * background color elevated when the fragment is scrolled. + */ + internal var appBars = mutableSetOf() + private var job = Job() final override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main @@ -83,6 +91,7 @@ abstract class BaseFragment( ?: return null isViewReady = false // reinitialize the view in onResume() inState = savedInstanceState // save the instance state for onResume() + appBarAnimator = AppBarColorAnimator(activity, appBars) return b.root } @@ -92,9 +101,17 @@ abstract class BaseFragment( if (!isAdded || isViewReady) return isViewReady = true - setupCanRefresh() + // setup the activity (bottom sheet, FAB, etc.) + // run before setupScrollListener {} to populate appBars (activity as? MainActivity)?.let(::setupMainActivity) (activity as? LoginActivity)?.let(::setupLoginActivity) + // listen to scroll state changes + var first = true + setupScrollListener { + if (isScrolled != it || first) + isScrolled = it + first = false + } // let the UI transition for a moment startCoroutineTimer(100L) { if (!isAdded) @@ -141,9 +158,10 @@ abstract class BaseFragment( /** * Called to retrieve the scrolling view contained in the fragment. - * The scrolling view is configured to act nicely with the SwipeRefreshLayout. + * The scrolling view is configured to work nicely with the app bars + * and the SwipeRefreshLayout. */ - open fun getRefreshScrollingView(): View? = null + open fun getScrollingView(): View? = null /** * Called to retrieve the FAB label resource and the icon. @@ -157,6 +175,22 @@ abstract class BaseFragment( */ open fun getMarkAsReadType(): MetadataType? = null + /** + * Called to retrieve the [FeatureType] this fragment is associated with. + * May also return arguments for the sync task. + * + * If not provided, swipe-to-refresh is disabled and the manual sync dialog + * selects all features by default. + * + * If [FeatureType] is null, all features are synced (and selected by the + * manual sync dialog). + * + * It is important to return the desired [FeatureType] from the first + * call of this method, which runs before [onViewReady]. Otherwise, + * swipe-to-refresh will not be enabled unless the view is scrolled. + */ + open fun getSyncParams(): Pair? = null + /** * Called to retrieve any extra bottom sheet items that should be displayed. */ diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/PagerFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/PagerFragment.kt index 0f43229d..f12e4aaa 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/PagerFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/PagerFragment.kt @@ -23,8 +23,8 @@ abstract class PagerFragment( inflater: ((inflater: LayoutInflater, parent: ViewGroup?, attachToParent: Boolean) -> B)?, ) : BaseFragment(inflater) { - private lateinit var pages: List> - private val fragmentCache = mutableMapOf() + private lateinit var pages: List, String>> + private val fragmentCache = mutableMapOf>() /** * Stores the default page index that is activated when @@ -37,6 +37,18 @@ abstract class PagerFragment( */ protected open var savedPageSelection = -1 + protected val currentFragment: BaseFragment<*, *>? + get() = fragmentCache[getViewPager().currentItem] + + final override fun getScrollingView() = null + override fun getSyncParams() = currentFragment?.getSyncParams() + + override fun onResume() { + // add TabLayout before super's setupScrollListener {} + appBars += getTabLayout() + super.onResume() + } + override suspend fun onViewReady(savedInstanceState: Bundle?) { if (savedPageSelection == -1) savedPageSelection = savedInstanceState?.getInt("pageSelection") ?: 0 @@ -47,6 +59,7 @@ abstract class PagerFragment( override fun getItemCount() = getPageCount() override fun createFragment(position: Int): Fragment { val fragment = getPageFragment(position) + fragment.appBars += getTabLayout() fragmentCache[position] = fragment return fragment } @@ -58,15 +71,15 @@ abstract class PagerFragment( it.setCurrentItem(savedPageSelection, false) it.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { override fun onPageScrollStateChanged(state: Int) { - canRefresh = when (state) { - ViewPager2.SCROLL_STATE_IDLE -> { - val fragment = - fragmentCache[it.currentItem] as? BaseFragment<*, *> - fragment != null && !fragment.canRefreshDisabled && fragment.canRefresh - } - - else -> false + if (state != ViewPager2.SCROLL_STATE_IDLE) { + // disable swipe-to-refresh during scrolling + canRefreshDisabled = true + return } + // take child fragment's values + val fragment = currentFragment + canRefreshDisabled = fragment?.canRefreshDisabled == true + isScrolled = fragment?.isScrolled == true } override fun onPageSelected(position: Int) { @@ -125,7 +138,7 @@ abstract class PagerFragment( * Only used with the default implementation of [getPageCount], [getPageFragment] * and [getPageTitle]. */ - open suspend fun onCreatePages() = listOf>() + open suspend fun onCreatePages() = listOf, String>>() open fun getPageCount() = pages.size open fun getPageFragment(position: Int) = pages[position].first diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/ScrollUtil.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/ScrollUtil.kt new file mode 100644 index 00000000..b6ce159d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/base/fragment/ScrollUtil.kt @@ -0,0 +1,130 @@ +/* + * Copyright (c) Kuba SzczodrzyƄski 2024-7-9. + */ + +package pl.szczodrzynski.edziennik.ui.base.fragment + +import android.animation.ValueAnimator +import android.annotation.SuppressLint +import android.content.Context +import android.content.res.ColorStateList +import android.graphics.drawable.LayerDrawable +import android.view.MotionEvent +import android.view.View +import android.view.animation.LinearInterpolator +import androidx.core.widget.NestedScrollView +import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.color.MaterialColors +import com.google.android.material.motion.MotionUtils +import com.google.android.material.shape.MaterialShapeDrawable +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.ext.resolveAttr +import pl.szczodrzynski.edziennik.ext.setTintColor + +@SuppressLint("ClickableViewAccessibility") +internal fun BaseFragment<*, *>.setupScrollListener(setIsScrolled: (Boolean) -> Unit) { + when (val view = getScrollingView()) { + is RecyclerView -> { + setIsScrolled(view.canScrollVertically(-1)) + view.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + if (view.canScrollVertically(-1)) + setIsScrolled(true) + else if (newState == RecyclerView.SCROLL_STATE_IDLE) + setIsScrolled(false) + } + + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + if (view.canScrollVertically(-1)) + setIsScrolled(true) + } + }) + } + + is View -> { + setIsScrolled(view.canScrollVertically(-1)) + var isTouched = false + view.setOnTouchListener { _, event -> + // keep track of the touch state + when (event.action) { + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> isTouched = false + MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> isTouched = true + } + if (view.canScrollVertically(-1)) + setIsScrolled(true) + else if (!isTouched) + setIsScrolled(false) + false + } + (view as? NestedScrollView)?.setOnScrollChangeListener( + NestedScrollView.OnScrollChangeListener { _, _, _, _, _ -> + if (!isTouched && !view.canScrollVertically(-1)) + setIsScrolled(false) + } + ) + } + + else -> { // null + // dispatch the default value to the activity + setIsScrolled(false) + } + } +} + +internal fun BaseFragment<*, *>.dispatchCanRefresh() { + (activity as? MainActivity)?.swipeRefreshLayout?.isEnabled = + !canRefreshDisabled && !isScrolled && getSyncParams() != null +} + +internal class AppBarColorAnimator( + context: Context, + private val bars: Set, +) : ValueAnimator.AnimatorUpdateListener { + companion object { + // keep track of the current animation value applied globally to the view + private var currentValue = 0.0f + } + + private lateinit var animator: ValueAnimator + + private val barColor = R.attr.colorSurface.resolveAttr(context) + private val liftColor = R.attr.colorSurfaceContainer.resolveAttr(context) + + context(BaseFragment<*, *>) + fun dispatchLiftOnScroll() { + if (::animator.isInitialized) + animator.cancel() + animator = ValueAnimator.ofFloat( + currentValue, + if (isScrolled) 1.0f else 0.0f, + ) + animator.duration = MotionUtils.resolveThemeDuration( + activity, + R.attr.motionDurationMedium2, + resources.getInteger(R.integer.app_bar_elevation_anim_duration), + ).toLong() + animator.interpolator = MotionUtils.resolveThemeInterpolator( + activity, + R.attr.motionEasingStandardInterpolator, + LinearInterpolator(), + ) + animator.addUpdateListener(this) + animator.start() + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + currentValue = animation.animatedValue as Float + val mixedColor = MaterialColors.layer( + barColor, + liftColor, + currentValue, + ) + for (bar in bars) { + when (val drawable = bar.background) { + is MaterialShapeDrawable -> drawable.fillColor = ColorStateList.valueOf(mixedColor) + is LayerDrawable -> drawable.getDrawable(0).setTintColor(mixedColor) + } + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/behaviour/BehaviourFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/behaviour/BehaviourFragment.kt index 62405e76..82a5dd2b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/behaviour/BehaviourFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/behaviour/BehaviourFragment.kt @@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.db.entity.Notice import pl.szczodrzynski.edziennik.data.db.full.NoticeFull +import pl.szczodrzynski.edziennik.data.enums.FeatureType import pl.szczodrzynski.edziennik.data.enums.MetadataType import pl.szczodrzynski.edziennik.databinding.FragmentBehaviourBinding import pl.szczodrzynski.edziennik.ext.resolveAttr @@ -20,8 +21,9 @@ class BehaviourFragment : BaseFragment( inflater = FragmentBehaviourBinding::inflate, ) { - override fun getRefreshScrollingView() = b.noticesView + override fun getScrollingView() = b.noticesView override fun getMarkAsReadType() = MetadataType.NOTICE + override fun getSyncParams() = FeatureType.BEHAVIOUR to null private var displayMode = MODE_YEAR private var noticeList: List? = null diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPageFragment.kt index ad99e004..638d7e35 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPageFragment.kt @@ -39,7 +39,7 @@ class LabPageFragment : BaseFragment( inflater = LabFragmentBinding::inflate, ) { - override fun getRefreshScrollingView() = b.scrollView + override fun getScrollingView() = b.scrollView override suspend fun onViewReady(savedInstanceState: Bundle?) { b.app = app diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPlaygroundFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPlaygroundFragment.kt index 56e1573f..34b559e3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPlaygroundFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/debug/LabPlaygroundFragment.kt @@ -17,7 +17,7 @@ class LabPlaygroundFragment : BaseFragment inflater = GradesListFragmentBinding::inflate, ) { - override fun getRefreshScrollingView() = b.list + override fun getScrollingView() = b.list override fun getMarkAsReadType() = MetadataType.GRADE + override fun getSyncParams() = FeatureType.GRADES to null override fun getBottomSheetItems() = listOf( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_grades_config) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/home/HomeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/home/HomeFragment.kt index 1c3d6d04..bfe9e57d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/home/HomeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/home/HomeFragment.kt @@ -78,7 +78,8 @@ class HomeFragment : BaseFragment( } } - override fun getRefreshScrollingView() = b.scrollView + override fun getScrollingView() = b.scrollView + override fun getSyncParams() = null to null override fun getBottomSheetItems() = listOf( BottomSheetPrimaryItem(true) .withTitle(R.string.menu_add_remove_cards) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/homework/HomeworkListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/homework/HomeworkListFragment.kt index 0f4b8aa0..8c8dce28 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/homework/HomeworkListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/homework/HomeworkListFragment.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.data.db.entity.Event +import pl.szczodrzynski.edziennik.data.enums.FeatureType import pl.szczodrzynski.edziennik.databinding.HomeworkListFragmentBinding import pl.szczodrzynski.edziennik.ext.getInt import pl.szczodrzynski.edziennik.ui.base.fragment.BaseFragment @@ -20,7 +21,8 @@ class HomeworkListFragment : BaseFragment FeatureType.MESSAGES_INBOX to null + Message.TYPE_SENT -> FeatureType.MESSAGES_SENT to null + else -> null + } private lateinit var adapter: MessagesAdapter private val manager get() = app.messageManager var teachers = listOf() + private val messageType by lazy { + arguments.getInt("messageType", Message.TYPE_RECEIVED) + } + @SuppressLint("RestrictedApi") override suspend fun onViewReady(savedInstanceState: Bundle?) { - val messageType = arguments.getInt("messageType", Message.TYPE_RECEIVED) var recyclerViewState = savedInstanceState?.getParcelable("recyclerViewState") val searchText = savedInstanceState?.getString("searchText") @@ -75,9 +84,6 @@ class MessagesListFragment : BaseFragment( inflater = NotesFragmentBinding::inflate, ) { + override fun getScrollingView() = b.list override fun getFab() = R.string.notes_action_add to CommunityMaterial.Icon3.cmd_text_box_plus_outline diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/notifications/NotificationsListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/notifications/NotificationsListFragment.kt index a5d5182f..68246f5c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/notifications/NotificationsListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/notifications/NotificationsListFragment.kt @@ -27,6 +27,7 @@ class NotificationsListFragment : BaseFragment - canRefresh = isChecked + canRefreshDisabled = !isChecked } - b.button.isChecked = canRefresh + b.button.isChecked = !canRefreshDisabled } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/timetable/TimetableDayFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/timetable/TimetableDayFragment.kt index 6e300e20..0a3a3f1c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/timetable/TimetableDayFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/timetable/TimetableDayFragment.kt @@ -74,6 +74,7 @@ class TimetableDayFragment : BaseFragment launch { diff --git a/app/src/main/res/layout/contributors_fragment.xml b/app/src/main/res/layout/contributors_fragment.xml index b26364bc..e2e92cfe 100644 --- a/app/src/main/res/layout/contributors_fragment.xml +++ b/app/src/main/res/layout/contributors_fragment.xml @@ -92,16 +92,10 @@