Skip to content

Commit 28da340

Browse files
committed
Cleaning up code and tweaking (disabling) some default drawing settings on RecyclerView
1 parent 5a1d41e commit 28da340

4 files changed

Lines changed: 18 additions & 33 deletions

File tree

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DisplayAdapters.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public int getItemCount() {
120120

121121
@Override
122122
public long getItemId(int posIndex) {
123+
if(posIndex < fileListData.size()) {
124+
return fileListData.get(posIndex).hashCode();
125+
}
123126
return posIndex;
124127
}
125128

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DisplayFragments.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ private void setViewportMaxFilesCount(int viewportFilesCap) {
9999
}
100100

101101
public boolean resetViewportMaxFilesCount(View parentViewContainer) {
102-
Log.i(LOGTAG, "resetViewportMaxFilesCount");
103102
if(!viewportCapacityMesaured) {
104103
int viewportDisplayHeight = parentViewContainer.getMeasuredHeight();
105104
if(fileItemDisplayHeight == 0 || viewportDisplayHeight == 0) {
@@ -108,6 +107,9 @@ public boolean resetViewportMaxFilesCount(View parentViewContainer) {
108107
setViewportMaxFilesCount((int) Math.floor((double) viewportDisplayHeight / fileItemDisplayHeight));
109108
Log.i(LOGTAG, String.format("DELAYED RESPONSE: VP Height = %d, FItemDisp Height = %d ====> %d",
110109
viewportDisplayHeight, fileItemDisplayHeight, getViewportMaxFilesCount()));
110+
getMainRecyclerView().setItemViewCacheSize(2 * getViewportMaxFilesCount());
111+
getMainRecyclerView().setDrawingCacheEnabled(true);
112+
getMainRecyclerView().setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
111113
viewportCapacityMesaured = true;
112114
}
113115
return true;
@@ -278,7 +280,6 @@ public static void resetLayout(View layoutContainer, DisplayTypes.FileType fileI
278280
selectionBox.setTag(displayPosition);
279281
selectionBox.setOnCheckedChangeListener(new DisplayAdapters.OnSelectListener());
280282

281-
282283
}
283284

284285
}

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/FileChooserRecyclerView.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This program (the AndroidFilePickerLight library) is free software written by
3636
import androidx.recyclerview.widget.LinearLayoutManager;
3737
import androidx.recyclerview.widget.LinearSmoothScroller;
3838
import androidx.recyclerview.widget.RecyclerView;
39+
import androidx.recyclerview.widget.SimpleItemAnimator;
3940

4041
import java.util.Locale;
4142

@@ -60,8 +61,7 @@ public FileChooserRecyclerView(Context context, AttributeSet attrSet, int defSty
6061

6162
public void setupRecyclerViewLayout() {
6263

63-
setHasFixedSize(false);
64-
//setItemViewCacheSize(0);
64+
setHasFixedSize(true);
6565
setNestedScrollingEnabled(false);
6666
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
6767
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -72,12 +72,14 @@ public void setupRecyclerViewLayout() {
7272
setLayoutManager((FileChooserRecyclerView.LayoutManager) rvLayoutManager);
7373
addItemDecoration(new FileChooserRecyclerView.CustomDividerItemDecoration(R.drawable.rview_file_item_divider));
7474
//addOnItemTouchListener(...);
75+
//((SimpleItemAnimator) getItemAnimator()).setSupportsChangeAnimations(false);
76+
getItemAnimator().setChangeDuration(0);
7577

7678
}
7779

78-
// We want it to move when flung and be responsive, but keep a constant rate of movement:
79-
private static final int FLING_VELOCITY_DAMPENAT = 850;
80-
80+
// We want it to move when flung and be responsive, but keep an approximately
81+
// constant rate of movement through the items:
82+
private static final int FLING_VELOCITY_DAMPENAT = 500;
8183

8284
@Override
8385
public boolean fling(int velocityX, int velocityY) {
@@ -88,11 +90,6 @@ public boolean fling(int velocityX, int velocityY) {
8890
return super.fling(0, scaledVelocityY);
8991
}
9092

91-
/*@Override
92-
public void smoothScrollToPosition(int indexPos) {
93-
getLayoutManager().smoothScrollToPosition(this, new RecyclerView.State(), indexPos);
94-
}*/
95-
9693
public interface RecyclerViewSlidingContextWindow {
9794

9895
void setWeightBufferSize(int size);
@@ -120,7 +117,7 @@ public LayoutManager(Context layoutCtx) {
120117
setOrientation(LinearLayoutManager.VERTICAL);
121118
setAutoMeasureEnabled(true);
122119
setReverseLayout(false);
123-
setStackFromEnd(true); // ???
120+
setStackFromEnd(true);
124121
setSmoothScrollbarEnabled(true);
125122
localStaticInst = this;
126123
}
@@ -130,13 +127,8 @@ public boolean isAutoMeasureEnabled() {
130127
return true;
131128
}
132129

133-
/*// intent is to speed it up for the prefetch thread smooth scrolling:
130+
/*
134131
public static final float SCROLLER_MILLISECONDS_PER_INCH = 16.0f; // larger values slow it down, 25.0 ~ default behavior
135-
136-
private int intendedNextScrollPos;
137-
private LinearSmoothScroller linearSmoothScroller;
138-
private RecyclerView scrollInvokingRV;
139-
140132
@Override
141133
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
142134
scrollInvokingRV = recyclerView;
@@ -149,19 +141,7 @@ protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
149141
linearSmoothScroller.setTargetPosition(position);
150142
startSmoothScroll(linearSmoothScroller);
151143
}
152-
153-
public boolean completeLastSmoothScroll() {
154-
if(linearSmoothScroller == null || intendedNextScrollPos < 0 ||
155-
intendedNextScrollPos >= getItemCount() || scrollInvokingRV == null) {
156-
return false;
157-
}
158-
else if(!linearSmoothScroller.isRunning()) {
159-
return false;
160-
}
161-
scrollInvokingRV.stopScroll();
162-
scrollInvokingRV.scrollToPosition(intendedNextScrollPos);
163-
return true;
164-
}*/
144+
*/
165145

166146
}
167147

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/PrefetchFilesUpdater.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This program (the AndroidFilePickerLight library) is free software written by
1919

2020
import android.os.AsyncTask;
2121
import android.util.Log;
22+
import android.view.View;
2223

2324
import java.util.ArrayList;
2425
import java.util.HashMap;
@@ -343,7 +344,7 @@ else if(updateDataType.equals(UpdateDataStruct.UpdateDataType.PREPEND_DATA_AT_TO
343344
}
344345

345346
private static final long THREAD_INIT_PAUSE_TIMEOUT = 125; // Milliseconds
346-
private static final long THREAD_PAUSE_TIMEOUT = 500; //250; // Milliseconds
347+
private static final long THREAD_PAUSE_TIMEOUT = 550; // Milliseconds
347348

348349
@Override
349350
public void run() {

0 commit comments

Comments
 (0)