diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/announcements/AnnouncementsFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/announcements/AnnouncementsFragment.java index c9e74c8d..2f0a185e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/announcements/AnnouncementsFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/announcements/AnnouncementsFragment.java @@ -33,6 +33,7 @@ import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration; import pl.szczodrzynski.edziennik.utils.Themes; import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem; +import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE; import static pl.szczodrzynski.edziennik.data.db.entity.LoginStore.LOGIN_TYPE_LIBRUS; import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ANNOUNCEMENT; @@ -90,6 +91,18 @@ public class AnnouncementsFragment extends Fragment { recyclerView.setLayoutManager(linearLayoutManager); recyclerView.addItemDecoration(new SimpleDividerItemDecoration(view.getContext())); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + if (recyclerView.canScrollVertically(-1)) { + b.refreshLayout.setEnabled(false); + } + if (!recyclerView.canScrollVertically(-1) && newState == SCROLL_STATE_IDLE) { + b.refreshLayout.setEnabled(true); + } + } + }); + app.db.announcementDao().getAll(App.Companion.getProfileId()).observe(this, announcements -> { if (app == null || activity == null || b == null || !isAdded()) return; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.java index 18a6fe7d..2b5317a6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/attendance/AttendanceFragment.java @@ -21,6 +21,7 @@ import androidx.core.graphics.ColorUtils; import androidx.databinding.DataBindingUtil; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial; @@ -40,6 +41,7 @@ import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration; import pl.szczodrzynski.edziennik.utils.Themes; import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem; +import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE; import static pl.szczodrzynski.edziennik.data.db.entity.Attendance.TYPE_ABSENT; import static pl.szczodrzynski.edziennik.data.db.entity.Attendance.TYPE_ABSENT_EXCUSED; import static pl.szczodrzynski.edziennik.data.db.entity.Attendance.TYPE_BELATED; @@ -181,6 +183,18 @@ public class AttendanceFragment extends Fragment { b.attendanceView.setLayoutManager(linearLayoutManager); b.attendanceView.addItemDecoration(new SimpleDividerItemDecoration(getContext())); + b.attendanceView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + if (recyclerView.canScrollVertically(-1)) { + b.refreshLayout.setEnabled(false); + } + if (!recyclerView.canScrollVertically(-1) && newState == SCROLL_STATE_IDLE) { + b.refreshLayout.setEnabled(true); + } + } + }); + App.db.attendanceDao().getAll(App.Companion.getProfileId()).observe(this, attendance -> { if (app == null || activity == null || b == null || !isAdded()) return; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/BehaviourFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/BehaviourFragment.java index ea95989d..4ec8b4c6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/BehaviourFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/behaviour/BehaviourFragment.java @@ -15,6 +15,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.databinding.DataBindingUtil; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial; @@ -31,6 +32,7 @@ import pl.szczodrzynski.edziennik.databinding.FragmentBehaviourBinding; import pl.szczodrzynski.edziennik.utils.Themes; import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem; +import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE; import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_NOTICE; public class BehaviourFragment extends Fragment { @@ -97,6 +99,18 @@ public class BehaviourFragment extends Fragment { b.noticesView.setHasFixedSize(true); b.noticesView.setLayoutManager(linearLayoutManager); + b.noticesView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + if (recyclerView.canScrollVertically(-1)) { + b.refreshLayout.setEnabled(false); + } + if (!recyclerView.canScrollVertically(-1) && newState == SCROLL_STATE_IDLE) { + b.refreshLayout.setEnabled(true); + } + } + }); + app.db.noticeDao().getAll(App.Companion.getProfileId()).observe(this, notices -> { if (app == null || activity == null || b == null || !isAdded()) return; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.kt index a20f1b24..d4eea3ba 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.kt @@ -13,6 +13,8 @@ import android.widget.Toast import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon2 import kotlinx.coroutines.* @@ -81,6 +83,16 @@ class GradesFragment : Fragment(), CoroutineScope { setHasFixedSize(true) layoutManager = LinearLayoutManager(context) //addItemDecoration(SimpleDividerItemDecoration(context)) + addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + if (recyclerView.canScrollVertically(-1)) { + b.refreshLayout.isEnabled = false + } + if (!recyclerView.canScrollVertically(-1) && newState == SCROLL_STATE_IDLE) { + b.refreshLayout.isEnabled = true + } + } + }) } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt index 29c98d4d..6f6df88a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt @@ -13,6 +13,7 @@ import android.widget.Toast import androidx.core.view.AccessibilityDelegateCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat +import androidx.core.widget.NestedScrollView import androidx.fragment.app.Fragment import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -123,6 +124,10 @@ class HomeFragment : Fragment(), CoroutineScope { HomeConfigDialog(activity, reloadOnDismiss = true) } + b.scrollView.setOnScrollChangeListener { _: NestedScrollView?, _: Int, scrollY: Int, _: Int, _: Int -> + b.refreshLayout.isEnabled = scrollY == 0 + } + val showUnified = false val cards = app.config.forProfile().ui.homeCards.filter { it.profileId == app.profile.id }.toMutableList() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt index 93fa4b3d..24bb408a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/homework/HomeworkFragment.kt @@ -85,9 +85,7 @@ class HomeworkFragment : Fragment() { b.viewPager.clearOnPageChangeListeners() b.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) { - if (b.refreshLayout != null) { - b.refreshLayout.isEnabled = state == ViewPager.SCROLL_STATE_IDLE - } + b.refreshLayout.isEnabled = state == ViewPager.SCROLL_STATE_IDLE } override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} override fun onPageSelected(position: Int) { diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index ab4c5a83..fe0e56a8 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -12,6 +12,7 @@ android:layout_height="match_parent">