Skip to content

Commit c68ad34

Browse files
committed
Backup point -- Creating a version to diff against to restore old code (scroll down works, up not)
1 parent ecb7ad2 commit c68ad34

5 files changed

Lines changed: 119 additions & 62 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,19 @@ public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
351351
int startFileIndex = getFilesStartIndex();
352352
int lastFileIndex = startFileIndex + getFilesListLength();
353353
if(lastFileIndex >= docsQueryFilesList.length) {
354+
//int truncateDiff = lastFileIndex + 1 - docsQueryFilesList.length;
354355
lastFileIndex = docsQueryFilesList.length - 1;
355356
startFileIndex = Math.max(0, lastFileIndex - getFilesListLength());
356357
}
357358
int curFileIndex = 0;
358-
for(File file : docsQueryFilesList) {
359-
if(curFileIndex++ < startFileIndex) {
360-
continue;
361-
}
362-
else if(curFileIndex > lastFileIndex) {
359+
for(int folderIndex = startFileIndex; folderIndex < docsQueryFilesList.length; folderIndex++) {
360+
if(curFileIndex > lastFileIndex) {
361+
++curFileIndex;
363362
break;
364363
}
365-
includeFile(mcResult, null, file);
364+
File nextFile = docsQueryFilesList[folderIndex];
365+
includeFile(mcResult, null, nextFile);
366+
++curFileIndex;
366367
}
367368
return mcResult;
368369
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ public FileListAdapter(List<String> nextFileListData, List<DisplayTypes.FileType
4747
this.fileListData.addAll(nextFileListData);
4848
this.fileItemsData = new ArrayList<DisplayTypes.FileType>();
4949
this.fileItemsData.addAll(nextFileItemsData);
50-
this.setHasStableIds(false); // TODO ???
50+
//this.setHasStableIds(true); // TODO ???
5151
notifyDataSetChanged();
5252
}
5353

54-
public void reloadDataSets(List<String> nextDataSet, List<DisplayTypes.FileType> nextFileItemsData) {
54+
public void reloadDataSets(List<String> nextDataSet, List<DisplayTypes.FileType> nextFileItemsData, boolean notifyAdapter) {
5555
fileListData.clear();
5656
fileListData.addAll(nextDataSet);
5757
fileItemsData.clear();
5858
fileItemsData.addAll(nextFileItemsData);
59-
notifyDataSetChanged();
59+
if(notifyAdapter) {
60+
notifyDataSetChanged();
61+
}
6062
}
6163

6264
@Override
@@ -68,7 +70,6 @@ public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
6870

6971
@Override
7072
public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
71-
//Log.i(LOGTAG,"onCreateViewHolder @ " + posIndex);
7273
bvHolder.getDisplayText().setText(fileListData.get(posIndex));
7374
//Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s", posIndex, bvHolder.getDisplayText().getText()));
7475
if(!fileItemsData.isEmpty()) {
@@ -99,6 +100,11 @@ public int getItemCount() {
99100
return fileListData.size();
100101
}
101102

103+
//@Override
104+
//public long getItemId(int posIndex) {
105+
// return posIndex;
106+
//}
107+
102108
}
103109

104110
public static class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener, RecyclerView.OnItemTouchListener {
@@ -128,6 +134,7 @@ public BaseViewHolder(View v) {
128134
v.setOnClickListener(this);
129135
v.setOnLongClickListener(this);
130136
displayText = (TextView) v.findViewById(R.id.fileEntryBaseName);
137+
setIsRecyclable(false);
131138
}
132139

133140
public TextView getDisplayText() { return displayText; }

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,27 @@ public void displayNextDirectoryFilesList(List<DisplayTypes.FileType> workingDir
238238
activeFileItemsDataList.clear();
239239
fileItemBasePathsList.clear();
240240

241+
// This apparently needs to be done when updating the recycler view by posting new data.
242+
// Without this, the size of the list of views it stores grows without bound.
243+
// The other option is to set rv.setHasFixedSize(true), but this similarly causes problems by
244+
// freezing the scrolling when trying to update the layout with new data.
245+
// Thus we are having to just manually clear all the views on each data update to initialize the
246+
// list of subdisplays from a blank container (or thereabouts explains it).
247+
DisplayAdapters.FileListAdapter rvAdapter = (DisplayAdapters.FileListAdapter) mainFileListRecyclerView.getAdapter();
248+
LinearLayoutManager rvLayoutManager = (LinearLayoutManager) getMainRecyclerView().getLayoutManager();
249+
//rvLayoutManager.removeAllViews();
250+
//rvAdapter.notifyDataSetChanged();
251+
241252
final List<DisplayTypes.FileType> filteredFileContents = workingDirContentsList;
242253
for(int fidx = 0; fidx < filteredFileContents.size(); fidx++) {
243254
DisplayTypes.FileType fileItem = filteredFileContents.get(fidx);
244255
fileItemBasePathsList.add(fileItem.getBaseName());
245256
activeFileItemsDataList.add(fileItem);
257+
/*rvAdapter.reloadDataSets(fileItemBasePathsList, activeFileItemsDataList, true);
258+
DisplayAdapters.BaseViewHolder bvHolder = rvAdapter.createViewHolder(getMainRecyclerView(), VIEW_TYPE_FILE_ITEM);
259+
rvAdapter.bindViewHolder(bvHolder, fidx);*/
246260
}
247-
DisplayAdapters.FileListAdapter rvAdapter = (DisplayAdapters.FileListAdapter) mainFileListRecyclerView.getAdapter();
248-
rvAdapter.reloadDataSets(fileItemBasePathsList, activeFileItemsDataList);
261+
rvAdapter.reloadDataSets(fileItemBasePathsList, activeFileItemsDataList, true);
249262

250263
}
251264

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,20 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
7070

7171
public void setNextDirectoryContents(List<FileType> nextFolderFiles) { directoryContentsList = nextFolderFiles; }
7272

73-
public void computeDirectoryContents(int startIndexPos, int maxIndexPos,
73+
public static final int STATUS_ERROR = -1;
74+
public static final int STATUS_SUCCESS = 0;
75+
public static final int STATUS_END_OF_FOLDER = 2;
76+
77+
public int computeDirectoryContents(int startIndexPos, int maxIndexPos,
7478
int trimFromFrontCount, int trimFromBackCount, int newItemsCount,
7579
boolean updateGlobalIndices) {
7680
Log.i(LOGTAG, String.format(Locale.getDefault(), "STARTING: Computing dir contents [%d, %d] -- %s", startIndexPos, maxIndexPos, activeCWDAbsPath));
7781
BasicFileProvider fpInst = BasicFileProvider.getInstance();
7882
if(fpInst == null) {
79-
return;
83+
return STATUS_ERROR;
8084
}
8185
fpInst.setFilesStartIndex(startIndexPos);
86+
//fpInst.setFilesListLength(Math.abs(newItemsCount));
8287
int initStartIndexPos = startIndexPos;
8388
try {
8489
fpInst.noUpdateQueryFilesList(); // save some time processing if we haven't recently loaded a new folder to process
@@ -90,13 +95,13 @@ public void computeDirectoryContents(int startIndexPos, int maxIndexPos,
9095
if(startIndexPos >= getInitialMatrixCursor().getCount() || maxIndexPos < startIndexPos) {
9196
Log.e(LOGTAG, String.format("RETURNING cursor positions out of range %d / [%d, %d] ... ", getInitialMatrixCursor().getCount(), startIndexPos, maxIndexPos));
9297
directoryContentsList.clear();
93-
return;
98+
return STATUS_ERROR;
9499
}
95100
startIndexPos = newItemsCount < 0 ? startIndexPos : startIndexPos + numItemsRequested - newItemsCount;
96101
maxIndexPos = newItemsCount > 0 ? maxIndexPos : maxIndexPos + newItemsCount;
97102
initMatrixCursorListing.moveToFirst();
98103
boolean appendNewItems = newItemsCount > 0;
99-
List<FileType> filesDataList = new ArrayList<FileType>(directoryContentsList.subList(trimFromFrontCount, directoryContentsList.size() - trimFromBackCount));
104+
List<FileType> filesDataList = new ArrayList<FileType>();
100105
int prependInsertIdx = 0, mcRowIdx;
101106
for (mcRowIdx = 0; mcRowIdx < Math.min(initMatrixCursorListing.getCount(), Math.abs(newItemsCount)); mcRowIdx++) {
102107
String[] filePropertiesList = fpInst.getPropertiesOfCurrentRow(initMatrixCursorListing, !BasicFileProvider.CURSOR_TYPE_IS_ROOT);
@@ -107,15 +112,17 @@ public void computeDirectoryContents(int startIndexPos, int maxIndexPos,
107112
boolean isDir = Boolean.parseBoolean(filePropertiesList[BasicFileProvider.PROPERTY_ISDIR]);
108113
boolean isHidden = Boolean.parseBoolean(filePropertiesList[BasicFileProvider.PROPERTY_ISHIDDEN]);
109114
FileType nextFileItem = new FileType(fileAbsPath, fileSize, filePosixPerms, isDir, isHidden, fileProviderDocId, this);
110-
if(appendNewItems) {
111-
filesDataList.add(nextFileItem);
112-
}
113-
else {
114-
filesDataList.add(prependInsertIdx, nextFileItem);
115-
prependInsertIdx++;
116-
}
115+
filesDataList.add(nextFileItem);
117116
initMatrixCursorListing.moveToNext();
118117
}
118+
ArrayList<FileType> priorListings = new ArrayList<FileType>(directoryContentsList.subList(trimFromFrontCount, directoryContentsList.size() - trimFromBackCount));
119+
if(appendNewItems) {
120+
filesDataList.addAll(priorListings);
121+
}
122+
else {
123+
priorListings.addAll(filesDataList);
124+
filesDataList = priorListings;
125+
}
119126
if(updateGlobalIndices) {
120127
int resultSizeDiff = Math.abs(newItemsCount) - mcRowIdx;
121128
Log.i(LOGTAG, String.format(Locale.getDefault(), "UPDATING GLOBAL INDICES: [%d, %d] -> [%d, %d]", initStartIndexPos,
@@ -124,19 +131,24 @@ public void computeDirectoryContents(int startIndexPos, int maxIndexPos,
124131
DisplayFragments.getInstance().lastFileDataEndIndex = DisplayFragments.getInstance().lastFileDataEndIndex - resultSizeDiff;
125132
}
126133
setNextDirectoryContents(filesDataList);
134+
if(mcRowIdx == Math.abs(newItemsCount)) {
135+
return STATUS_SUCCESS;
136+
}
137+
else {
138+
return STATUS_END_OF_FOLDER;
139+
}
127140
}
128141
catch(FileNotFoundException ioe) {
129142
ioe.printStackTrace();
130-
return;
131143
}
132-
144+
return STATUS_ERROR;
133145
}
134146

135-
public void computeDirectoryContents(int startIndexPos, int maxIndexPos) {
147+
public int computeDirectoryContents(int startIndexPos, int maxIndexPos) {
136148
BasicFileProvider fpInst = BasicFileProvider.getInstance();
137149
fpInst.setFilesListLength(DisplayFragments.getViewportMaxFilesCount());
138-
computeDirectoryContents(startIndexPos, maxIndexPos,
139-
0, directoryContentsList.size(),maxIndexPos + 1 - startIndexPos, true);
150+
return computeDirectoryContents(startIndexPos, maxIndexPos,
151+
0, directoryContentsList.size(),maxIndexPos + 1 - startIndexPos, true);
140152
}
141153

142154
public void clearDirectoryContentsList() {

0 commit comments

Comments
 (0)