Skip to content

Commit 1b1ac24

Browse files
committed
Progress marker -- About to try a reasonable method to make the scroller work, cn remove much ugly junk code
1 parent 97884da commit 1b1ac24

7 files changed

Lines changed: 393 additions & 45 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ public int getItemCount() {
110110

111111
@Override
112112
public long getItemId(int posIndex) {
113-
return fileItemsData.get(posIndex).getLayoutContainer().hashCode();
114-
//return posIndex;
113+
if(fileItemsData.get(posIndex).getLayoutContainer() != null){
114+
return fileItemsData.get(posIndex).getLayoutContainer().hashCode();
115+
}
116+
else if(fileItemsData.get(posIndex) != null) {
117+
return fileItemsData.get(posIndex).hashCode();
118+
}
119+
return posIndex;
115120
}
116121

117122
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public class DisplayFragments {
4848
public FileFilter.FileItemsSortFunc localFilesListSortFunc;
4949

5050
public DisplayFragments() {
51-
folderIconInst = GradientDrawableFactory.getDrawableFromResource(R.drawable.folder_icon32);
52-
fileIconInst = GradientDrawableFactory.getDrawableFromResource(R.drawable.generic_file_icon32);
53-
hiddenFileIconInst = GradientDrawableFactory.getDrawableFromResource(R.drawable.hidden_file_icon32);
51+
folderIconInst = DrawUtils.getDrawableFromResource(R.drawable.folder_icon32);
52+
fileIconInst = DrawUtils.getDrawableFromResource(R.drawable.generic_file_icon32);
53+
hiddenFileIconInst = DrawUtils.getDrawableFromResource(R.drawable.hidden_file_icon32);
5454
localFilesListFilter = null;
5555
localFilesListSortFunc = null;
5656
}
@@ -283,7 +283,7 @@ public static boolean removeItemsAtTop(int itemCount) {
283283

284284
}
285285

286-
public static boolean removeItemsFromBottom(int itemCount) {
286+
public static boolean removeItemsFromBack(int itemCount) {
287287

288288
FileChooserRecyclerView mainRV = DisplayFragments.getInstance().getMainRecyclerView();
289289
FileChooserRecyclerView.LayoutManager rvLayoutManager = (FileChooserRecyclerView.LayoutManager) mainRV.getLayoutManager();
@@ -295,7 +295,7 @@ public static boolean removeItemsFromBottom(int itemCount) {
295295

296296
}
297297

298-
public static boolean appendItemsToBackTrimmedFromFront(int itemCount,
298+
/*public static boolean appendItemsToBackTrimmedFromFront(int itemCount,
299299
List<String> fileNamesList, List<DisplayTypes.FileType> fileItemsList) {
300300
301301
FileChooserRecyclerView mainRV = DisplayFragments.getInstance().getMainRecyclerView();
@@ -325,7 +325,7 @@ public static boolean prependItemsAtTopTrimmedFromBack(int itemCount,
325325
rvLayoutManager.restoreDefaultMode();
326326
return true;
327327
328-
}
328+
}*/
329329

330330
}
331331

AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/GradientDrawableFactory.java renamed to AndroidFilePickerLightLibrary/src/main/java/com/maxieds/androidfilepickerlightlibrary/DrawUtils.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ This program (the AndroidFilePickerLight library) is free software written by
2222
import android.graphics.drawable.GradientDrawable;
2323
import android.util.TypedValue;
2424

25-
public class GradientDrawableFactory {
25+
public class DrawUtils {
2626

27-
private static String LOGTAG = GradientDrawableFactory.class.getSimpleName();
27+
private static String LOGTAG = DrawUtils.class.getSimpleName();
2828

2929
private static Activity defaultActivityContextRef = FileChooserActivity.getInstance();
3030
public static void setDefaultActivityContext(Activity activityContextRef) {
@@ -277,7 +277,7 @@ public static GradientDrawable generateNamedGradientType(BorderStyleSpec borderS
277277
return generateNamedGradientType(borderStyleSpec, resolveColorFromAttribute(R.attr.colorPrimaryDark), namedColorTheme);
278278
}
279279

280-
public static class Builder {
280+
public static class GradientDrawableBuilder {
281281

282282
private int[] colorsList;
283283
private GradientMethodSpec gradientType;
@@ -288,8 +288,7 @@ public static class Builder {
288288
private boolean useNamedColorTheme;
289289
private NamedGradientColorThemes namedColorTheme;
290290

291-
292-
public Builder() {
291+
public GradientDrawableBuilder() {
293292
colorsList = new int[] {};
294293
gradientType = GradientMethodSpec.GRADIENT_METHOD_LINEAR;
295294
gradientAngle = 90.0f;
@@ -300,37 +299,37 @@ public Builder() {
300299
namedColorTheme = null;
301300
}
302301

303-
public Builder setColorsArray(int[] colorsArray) {
302+
public GradientDrawableBuilder setColorsArray(int[] colorsArray) {
304303
colorsList = colorsArray;
305304
return this;
306305
}
307306

308-
public Builder setGradientType(GradientMethodSpec gradType) {
307+
public GradientDrawableBuilder setGradientType(GradientMethodSpec gradType) {
309308
gradientType = gradType;
310309
return this;
311310
}
312311

313-
public Builder setGradientAngle(float gradAngle) {
312+
public GradientDrawableBuilder setGradientAngle(float gradAngle) {
314313
gradientAngle = (float) Math.floor(gradAngle / 45.0f); /* Otherwise, Android throws at fatal warning if it is not a multiple of 45.0f */
315314
return this;
316315
}
317316

318-
public Builder setBorderColor(int bdrColor) {
317+
public GradientDrawableBuilder setBorderColor(int bdrColor) {
319318
borderColor = bdrColor;
320319
return this;
321320
}
322321

323-
public Builder setBorderStyle(BorderStyleSpec bdrStyle) {
322+
public GradientDrawableBuilder setBorderStyle(BorderStyleSpec bdrStyle) {
324323
borderStyle = bdrStyle;
325324
return this;
326325
}
327326

328-
public Builder setFillStyle(GradientTypeSpec gradFillStyle) {
327+
public GradientDrawableBuilder setFillStyle(GradientTypeSpec gradFillStyle) {
329328
gradientFillStyle = gradFillStyle;
330329
return this;
331330
}
332331

333-
public Builder setNamedColorScheme(NamedGradientColorThemes namedTheme) {
332+
public GradientDrawableBuilder setNamedColorScheme(NamedGradientColorThemes namedTheme) {
334333
if(namedTheme != null) {
335334
namedColorTheme = namedTheme;
336335
useNamedColorTheme = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public int getFolderIconResId() {
131131

132132
public Drawable getFolderIconDrawable() {
133133
if(customIconObj == null) {
134-
return GradientDrawableFactory.resolveDrawableFromAttribute(folderIconResId);
134+
return DrawUtils.resolveDrawableFromAttribute(folderIconResId);
135135
}
136136
return customIconObj;
137137
}

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ This program (the AndroidFilePickerLight library) is free software written by
2020
import android.content.Context;
2121
import android.content.res.TypedArray;
2222
import android.graphics.Canvas;
23-
import android.graphics.PointF;
2423
import android.graphics.drawable.Drawable;
2524
import android.util.AttributeSet;
2625
import android.util.DisplayMetrics;
@@ -30,7 +29,6 @@ This program (the AndroidFilePickerLight library) is free software written by
3029
import android.view.ViewConfiguration;
3130
import android.view.ViewGroup;
3231
import android.widget.LinearLayout;
33-
import android.widget.TextView;
3432

3533
import androidx.annotation.NonNull;
3634
import androidx.core.view.ViewCompat;
@@ -78,7 +76,7 @@ public void setupRecyclerViewLayout(DisplayFragments displayFragmentsContext) {
7876
FileChooserRecyclerView.LayoutManager rvLayoutManager = new FileChooserRecyclerView.LayoutManager(getContext());
7977
setLayoutManager((FileChooserRecyclerView.LayoutManager) rvLayoutManager);
8078
addItemDecoration(new FileChooserRecyclerView.CustomDividerItemDecoration(R.drawable.rview_file_item_divider));
81-
setOnScrollListener(new FileChooserRecyclerView.OnScrollListener(rvLayoutManager, displayFragmentsContext));
79+
//setOnScrollListener(new FileChooserRecyclerView.OnScrollListener(rvLayoutManager, displayFragmentsContext));
8280
}
8381

8482
@Override
@@ -102,6 +100,23 @@ public boolean onTouchEvent(MotionEvent mevent) {
102100
return returnStatus;
103101
}
104102

103+
public interface RecyclerViewSlidingContextWindow {
104+
105+
public void setWeightBufferSize(int size);
106+
107+
public int getBalance();
108+
public int getActiveCountToBalanceTop();
109+
public int getActiveTopBufferSize();
110+
public int getActiveCountToBalanceBottom();
111+
public int getActiveBottomBufferSize();
112+
113+
public int getLayoutVisibleDisplaySize();
114+
public int getLayoutFirstVisibleItemIndex();
115+
public int getLayoutLastVisibleItemIndex();
116+
public int getActiveLayoutItemsCount();
117+
118+
}
119+
105120
/* See: https://developer.android.com/reference/androidx/recyclerview/widget/LinearSnapHelper */
106121
public static class LayoutManager extends LinearLayoutManager {
107122

@@ -120,7 +135,7 @@ public LayoutManager(Context layoutCtx) {
120135
setStackFromEnd(true);
121136
setSmoothScrollbarEnabled(true);
122137
localStaticInst = this;
123-
nextPositionOffsetDiff = 3;
138+
nextPositionOffsetDiff = 1;
124139
}
125140

126141
@Override
@@ -186,8 +201,8 @@ public void smoothScrollToPosition(RecyclerView recyclerView, State state, int p
186201

187202
final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
188203

189-
private float distanceInPixels = 1000;
190-
private float scrollDuration = 0.5f;
204+
private float distanceInPixels = 250;
205+
private float scrollDuration = 1.65f;
191206

192207
protected int getHorizontalSnapPreference() {
193208
return SNAP_TO_START;
@@ -203,11 +218,11 @@ protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
203218
return SCROLLER_MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
204219
}
205220

206-
@Override
207-
protected int calculateTimeForScrolling(int deltaX) {
208-
float alpha = (float) deltaX / distanceInPixels;
209-
return (int) (scrollDuration * alpha);
210-
}
221+
//@Override
222+
//protected int calculateTimeForScrolling(int deltaX) {
223+
// float alpha = (float) deltaX / distanceInPixels;
224+
// return (int) (scrollDuration * alpha);
225+
//}
211226

212227
};
213228
linearSmoothScroller.setTargetPosition(position);
@@ -234,7 +249,7 @@ public int getScrollPositionToFixSnapState() {
234249

235250
}
236251

237-
public static class OnScrollListener extends RecyclerView.OnScrollListener {
252+
/*public static class OnScrollListener extends RecyclerView.OnScrollListener {
238253
239254
private static final String LOGTAG = OnScrollListener.class.getSimpleName();
240255
@@ -276,7 +291,7 @@ private boolean invokeNewDataLoader() {
276291
int initFirstItemIndex = rvLayoutManager.findFirstCompletelyVisibleItemPosition();
277292
displayFragmentsCtx.lastFileDataStartIndex = Math.max(0, displayFragmentsCtx.lastFileDataStartIndex - SCROLL_BY_ITEMS);
278293
displayFragmentsCtx.lastFileDataEndIndex = Math.max(0, displayFragmentsCtx.lastFileDataEndIndex - SCROLL_BY_ITEMS);
279-
DisplayFragments.RecyclerViewUtils.removeItemsFromBottom(SCROLL_BY_ITEMS);
294+
DisplayFragments.RecyclerViewUtils.removeItemsFromBack(SCROLL_BY_ITEMS);
280295
cwdFolderContextLocal.computeDirectoryContents(
281296
displayFragmentsCtx.lastFileDataStartIndex,
282297
displayFragmentsCtx.lastFileDataEndIndex,
@@ -390,13 +405,13 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int nextSta
390405
391406
@Override
392407
public void onScrolled(@NonNull RecyclerView recyclerView, int deltaX, int deltaY) {
393-
super.onScrolled(recyclerView, deltaX, deltaY);
408+
//super.onScrolled(recyclerView, deltaX, deltaY);
394409
Log.i(LOGTAG, String.format(Locale.getDefault(), "onScrolled: SCROLLER SHOWING [%d, %d] -- getCount = %d",
395410
rvLayoutManager.findFirstCompletelyVisibleItemPosition(), rvLayoutManager.findLastCompletelyVisibleItemPosition(),
396411
displayFragmentsCtx.getInstance().getMainRecyclerView().getAdapter().getItemCount()));
397412
}
398413
399-
}
414+
}*/
400415

401416
public static class CustomDividerItemDecoration extends RecyclerView.ItemDecoration {
402417

@@ -420,7 +435,7 @@ public CustomDividerItemDecoration(Context ctx, int dividerTypeIndex, boolean di
420435
}
421436

422437
public CustomDividerItemDecoration(int resId) {
423-
listingsDivider = GradientDrawableFactory.getDrawableFromResource(resId);
438+
listingsDivider = DrawUtils.getDrawableFromResource(resId);
424439
}
425440

426441
public static void setMarginAdjustments(int leftAdjust, int topAdjust, int rightAdjust, int bottomAdjust) {

0 commit comments

Comments
 (0)