Skip to content

Commit

Permalink
fix(android): implement preload interval
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews committed Jun 7, 2021
1 parent 2c6ae6d commit 2d586a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.Handler;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;

Expand All @@ -44,6 +45,7 @@ public class TiListView extends TiSwipeRefreshLayout implements OnSearchChangeLi
private static final String TAG = "TiListView";

private static final int CACHE_SIZE = 32;
private static final int PRELOAD_INTERVAL = 800;

private final ListViewAdapter adapter;
private final DividerItemDecoration decoration;
Expand Down Expand Up @@ -574,8 +576,9 @@ public void update()
// Pre-load items of empty list.
if (shouldPreload) {
final Handler handler = new Handler();
final long startTime = SystemClock.elapsedRealtime();

for (int i = 0; i < this.items.size(); i++) {
for (int i = 0; i < Math.min(this.items.size(), PRELOAD_INTERVAL / 8); i++) {
final ListItemProxy item = this.items.get(i);

// Fill event queue with pre-load attempts.
Expand All @@ -584,7 +587,13 @@ public void update()
@Override
public void run()
{
if (recyclerView.getLastTouchX() == 0
final long currentTime = SystemClock.elapsedRealtime();
final long delta = currentTime - startTime;

// Only pre-load views for a maximum period of time.
// This prevents over-taxing older devices.
if (delta <= PRELOAD_INTERVAL
&& recyclerView.getLastTouchX() == 0
&& recyclerView.getLastTouchY() == 0) {

// While there is no user interaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.Handler;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;

Expand Down Expand Up @@ -49,6 +50,7 @@ public class TiTableView extends TiSwipeRefreshLayout implements OnSearchChangeL
private static final String TAG = "TiTableView";

private static final int CACHE_SIZE = 32;
private static final int PRELOAD_INTERVAL = 800;

private final TableViewAdapter adapter;
private final DividerItemDecoration decoration;
Expand Down Expand Up @@ -532,8 +534,9 @@ public void update()
// Pre-load items of empty list.
if (shouldPreload) {
final Handler handler = new Handler();
final long startTime = SystemClock.elapsedRealtime();

for (int i = 0; i < this.rows.size(); i++) {
for (int i = 0; i < Math.min(this.rows.size(), PRELOAD_INTERVAL / 8); i++) {
final TableViewRowProxy row = this.rows.get(i);

// Fill event queue with pre-load attempts.
Expand All @@ -542,7 +545,13 @@ public void update()
@Override
public void run()
{
if (recyclerView.getLastTouchX() == 0
final long currentTime = SystemClock.elapsedRealtime();
final long delta = currentTime - startTime;

// Only pre-load views for a maximum period of time.
// This prevents over-taxing older devices.
if (delta <= PRELOAD_INTERVAL
&& recyclerView.getLastTouchX() == 0
&& recyclerView.getLastTouchY() == 0) {

// While there is no user interaction;
Expand Down

0 comments on commit 2d586a9

Please sign in to comment.