mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[UI] Make fragments disable pull to refresh when not scrolled to the top.
This commit is contained in:
parent
85fe2636cc
commit
c9992d9fe8
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user