From 8931338a66ec1d71c2cfe4c3620392e175d0b20b Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 30 Sep 2016 00:05:39 -0300 Subject: [PATCH] Reduce amount of scrolling needed to load more information Closes #217 --- res/xml/changelog_master.xml | 1 + src/de/grobox/liberario/activities/TripsActivity.java | 5 +++++ src/de/grobox/liberario/fragments/DeparturesFragment.java | 3 +++ .../grobox/liberario/fragments/NearbyStationsFragment.java | 3 +++ src/de/grobox/liberario/utils/TransportrUtils.java | 6 ++++++ 5 files changed, 18 insertions(+) diff --git a/res/xml/changelog_master.xml b/res/xml/changelog_master.xml index f63f8db46..d7fa66a46 100644 --- a/res/xml/changelog_master.xml +++ b/res/xml/changelog_master.xml @@ -3,6 +3,7 @@ Added France North West (Thanks Patrick!) + Reduce amount of scrolling needed to load more information Added help screens Reduced size of the app diff --git a/src/de/grobox/liberario/activities/TripsActivity.java b/src/de/grobox/liberario/activities/TripsActivity.java index 2769cf27d..dabd7ffff 100644 --- a/src/de/grobox/liberario/activities/TripsActivity.java +++ b/src/de/grobox/liberario/activities/TripsActivity.java @@ -27,6 +27,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.util.DisplayMetrics; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -54,6 +55,8 @@ import de.schildbach.pte.dto.QueryTripsResult; import de.schildbach.pte.dto.Trip; +import static de.grobox.liberario.utils.TransportrUtils.getDragDistance; + public class TripsActivity extends TransportrActivity { private QueryTripsResult start_context; private QueryTripsResult end_context; @@ -96,6 +99,8 @@ protected void onCreate(Bundle savedInstanceState) { swipeRefresh = (SwipyRefreshLayout) findViewById(R.id.swipe_refresh_layout); swipeRefresh.setColorSchemeResources(R.color.accent); + swipeRefresh.setDistanceToTriggerSync(getDragDistance(this)); + mRecyclerView = (RecyclerView) findViewById(R.id.trips_recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); diff --git a/src/de/grobox/liberario/fragments/DeparturesFragment.java b/src/de/grobox/liberario/fragments/DeparturesFragment.java index 68611a29f..18e024db0 100644 --- a/src/de/grobox/liberario/fragments/DeparturesFragment.java +++ b/src/de/grobox/liberario/fragments/DeparturesFragment.java @@ -52,6 +52,8 @@ import de.schildbach.pte.dto.QueryDeparturesResult; import de.schildbach.pte.dto.StationDepartures; +import static de.grobox.liberario.utils.TransportrUtils.getDragDistance; + public class DeparturesFragment extends TransportrFragment { public static final String TAG = "de.grobox.liberario.departures"; @@ -92,6 +94,7 @@ public void onClick(View v) { // Swipe to Refresh ui.swipe_refresh.setColorSchemeResources(R.color.accent); ui.swipe_refresh.setDirection(SwipyRefreshLayoutDirection.BOTH); + ui.swipe_refresh.setDistanceToTriggerSync(getDragDistance(getContext())); ui.swipe_refresh.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener() { @Override public void onRefresh(final SwipyRefreshLayoutDirection direction) { diff --git a/src/de/grobox/liberario/fragments/NearbyStationsFragment.java b/src/de/grobox/liberario/fragments/NearbyStationsFragment.java index e89256058..5685a3a34 100644 --- a/src/de/grobox/liberario/fragments/NearbyStationsFragment.java +++ b/src/de/grobox/liberario/fragments/NearbyStationsFragment.java @@ -53,6 +53,8 @@ import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.NearbyLocationsResult; +import static de.grobox.liberario.utils.TransportrUtils.getDragDistance; + public class NearbyStationsFragment extends TransportrFragment { public static final String TAG = "de.grobox.liberario.nearby_locations"; @@ -127,6 +129,7 @@ public void onLocationChanged(Location location) { ui.swipe_refresh.setColorSchemeResources(R.color.accent); ui.swipe_refresh.setDirection(SwipyRefreshLayoutDirection.BOTTOM); + ui.swipe_refresh.setDistanceToTriggerSync(getDragDistance(getContext())); ui.swipe_refresh.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener() { @Override public void onRefresh(final SwipyRefreshLayoutDirection direction) { diff --git a/src/de/grobox/liberario/utils/TransportrUtils.java b/src/de/grobox/liberario/utils/TransportrUtils.java index 17c6a5974..f22bc536a 100644 --- a/src/de/grobox/liberario/utils/TransportrUtils.java +++ b/src/de/grobox/liberario/utils/TransportrUtils.java @@ -28,6 +28,7 @@ import android.graphics.drawable.GradientDrawable; import android.net.Uri; import android.support.v4.content.ContextCompat; +import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; @@ -588,4 +589,9 @@ static public NetworkProvider.WalkSpeed getWalkSpeed(Context context) { return NetworkProvider.WalkSpeed.valueOf(walkString); } + static public int getDragDistance(Context context) { + final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); + return (int) (25 * metrics.density); + } + }