Skip to content

Commit b618aba

Browse files
committed
Backup point -- Working out bugs in scolling through a large folder of files
1 parent 5755afd commit b618aba

88 files changed

Lines changed: 451 additions & 306 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AndroidFilePickerLightLibrary/build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
defaultConfig {
3131
minSdkVersion 29
3232
targetSdkVersion 30
33-
versionCode 1
34-
versionName "1.0.0"
33+
versionCode 2
34+
versionName "1.0.1"
3535
}
3636

3737
compileOptions {
@@ -44,7 +44,6 @@ android {
4444
release {
4545

4646
minifyEnabled false
47-
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
4847

4948
buildConfigField "String", "BUILD_TIMESTAMP", "\"" + getDateTimestamp() + "\""
5049
buildConfigField "String", "GIT_COMMIT_HASH", "\"" + getGitCommitHash() + "\""
@@ -54,17 +53,25 @@ android {
5453
libraryIcon : "@mipmap/library_profile_icon_round",
5554
libraryTheme : "@style/LibraryDefaultTheme",
5655
libraryDebug : "false",
57-
libraryInstallLocation : "preferExternal" // "internalOnly"
56+
libraryInstallLocation : "preferExternal"
5857
]
5958
}
6059

6160
}
6261

6362
}
6463

64+
repositories {
65+
maven {
66+
url "https://maven.google.com"
67+
name 'Google'
68+
}
69+
}
70+
6571
dependencies {
6672
implementation fileTree(dir: "libs", include: ["*.jar"])
6773
implementation 'androidx.appcompat:appcompat:1.2.0'
6874
implementation 'com.android.support:recyclerview-v7:30.0.0'
75+
implementation 'org.apache.commons:commons-text:1.7'
6976
implementation 'pub.devrel:easypermissions:3.0.0'
7077
}

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

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ public class BasicFileProvider extends DocumentsProvider {
6060
private static BasicFileProvider fileProviderStaticInst = null;
6161
public static BasicFileProvider getInstance() { return fileProviderStaticInst; }
6262

63+
private static int activeStartFilesIndex = 0;
64+
private static int activeFilesListLength = DisplayFragments.DEFAULT_VIEWPORT_FILE_ITEMS_COUNT;
65+
66+
public int getFilesStartIndex() {
67+
return activeStartFilesIndex;
68+
}
69+
70+
public int setFilesStartIndex(int nextStartIndex) {
71+
if (nextStartIndex >= 0) {
72+
activeStartFilesIndex = nextStartIndex;
73+
}
74+
return activeStartFilesIndex;
75+
}
76+
77+
public int getFilesListLength() {
78+
return activeFilesListLength;
79+
}
80+
81+
public int setFilesListLength(int nextLength) {
82+
if (nextLength >= 0) {
83+
activeFilesListLength = nextLength;
84+
}
85+
return activeFilesListLength;
86+
}
87+
6388
private File baseDirPath;
6489

6590
/*
@@ -284,7 +309,6 @@ public Cursor querySearchDocuments(String rootId, String query, String[] project
284309
@Override
285310
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint,
286311
CancellationSignal signal) throws FileNotFoundException {
287-
288312
final File file = getFileForDocId(documentId);
289313
final ParcelFileDescriptor pfd =
290314
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
@@ -293,7 +317,6 @@ public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHi
293317

294318
@Override
295319
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
296-
297320
// Create a cursor with the requested projection, or the default projection.
298321
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
299322
includeFile(result, documentId, null);
@@ -303,12 +326,26 @@ public Cursor queryDocument(String documentId, String[] projection) throws FileN
303326
@Override
304327
public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
305328
String sortOrder) throws FileNotFoundException {
306-
Log.v(LOGTAG, "queryChildDocuments, parentDocumentId: " +
307-
parentDocumentId + " sortOrder: " + sortOrder);
308-
309329
final MatrixCursor mcResult = new MatrixCursor(resolveDocumentProjection(projection));
310330
final File parent = getFileForDocId(parentDocumentId);
311-
for (File file : parent.listFiles()) {
331+
File[] filesList = parent.listFiles(); // ??? TODO : Can set a Java FilenameFilter here ... ???
332+
if(filesList.length == 0) {
333+
return mcResult;
334+
}
335+
int startFileIndex = getFilesStartIndex();
336+
int lastFileIndex = startFileIndex + getFilesListLength();
337+
if(lastFileIndex >= filesList.length) {
338+
lastFileIndex = filesList.length - 1;
339+
startFileIndex = Math.max(0, lastFileIndex - getFilesListLength());
340+
}
341+
int curFileIndex = 0;
342+
for(File file : filesList) {
343+
if(curFileIndex++ < startFileIndex) {
344+
continue;
345+
}
346+
else if(curFileIndex > lastFileIndex) {
347+
break;
348+
}
312349
includeFile(mcResult, null, file);
313350
}
314351
return mcResult;
@@ -480,7 +517,6 @@ private File getFileForDocId(String docId) throws FileNotFoundException {
480517
}
481518

482519
public static final boolean CURSOR_TYPE_IS_ROOT = true;
483-
public static final boolean CURSOR_TYPE_IS_DOCUMENT = false;
484520

485521
public static String getDocumentIdForCursorType(MatrixCursor mcResult, boolean cursorType) {
486522
if(mcResult.getCount() == 0) {
@@ -538,7 +574,7 @@ public String getBaseNameAtCurrentRow(MatrixCursor mcResult, boolean cursorType)
538574
}
539575

540576
public static final int PROPERTY_ABSPATH = 0;
541-
public static final int PROPERTY_BASENAME = 1;
577+
public static final int PROPERTY_FILE_PROVIDER_DOCID = 1;
542578
public static final int PROPERTY_FILE_SIZE = 2;
543579
public static final int PROPERTY_POSIX_PERMS = 3;
544580
public static final int PROPERTY_ISDIR = 4;
@@ -553,7 +589,7 @@ public String[] getPropertiesOfCurrentRow(MatrixCursor mcResult, boolean cursorT
553589
File curWorkingFile = getFileForDocId(docId);
554590
return new String[] {
555591
curWorkingFile.getAbsolutePath(),
556-
curWorkingFile.getName(),
592+
mcResult.getString(DOCS_PROJ_PARENTID_COLUMN_INDEX),
557593
FileUtils.getFileSizeString(curWorkingFile),
558594
FileUtils.getFilePosixPermissionsString(curWorkingFile),
559595
String.format(Locale.getDefault(), "%s", curWorkingFile.isDirectory() ? "true" : "false"),

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ 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(true);
5051
notifyDataSetChanged();
5152
}
5253

5354
@Override
5455
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
55-
Log.i(LOGTAG,"onCreateViewHolder");
56+
//Log.i(LOGTAG,"onCreateViewHolder");
5657
View rowItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_file_entry_item, parent, false);
5758
return new BaseViewHolder(rowItem);
5859
}
5960

6061
@Override
6162
public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
62-
Log.i(LOGTAG,"onCreateViewHolder @ " + posIndex);
63+
//Log.i(LOGTAG,"onCreateViewHolder @ " + posIndex);
6364
bvHolder.getDisplayText().setText(fileListData.get(posIndex));
64-
Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s", posIndex, bvHolder.getDisplayText().getText()));
65+
//Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s", posIndex, bvHolder.getDisplayText().getText()));
6566
if(!fileItemsData.isEmpty()) {
6667
DisplayTypes.FileType fileItem = fileItemsData.get(posIndex);
6768
bvHolder.setFileItemData(fileItem);
@@ -72,17 +73,17 @@ public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
7273

7374
@Override
7475
public void onViewRecycled(BaseViewHolder bvHolder){
75-
Log.i(LOGTAG,"onViewRecycled: " + bvHolder);
76+
//Log.i(LOGTAG,"onViewRecycled: " + bvHolder);
7677
}
7778

7879
@Override
7980
public void onViewDetachedFromWindow(BaseViewHolder bvHolder){
80-
Log.i(LOGTAG,"onViewDetachedFromWindow: " + bvHolder);
81+
//Log.i(LOGTAG,"onViewDetachedFromWindow: " + bvHolder);
8182
}
8283

8384
@Override
8485
public void onViewAttachedToWindow(BaseViewHolder bvHolder){
85-
Log.i(LOGTAG,"onViewAttachedToWindow: " + bvHolder);
86+
//Log.i(LOGTAG,"onViewAttachedToWindow: " + bvHolder);
8687
}
8788

8889
@Override
@@ -137,19 +138,22 @@ public DisplayTypes.FileType getFileItemReference() {
137138
public View getMainViewLayoutContainer() { return fileItemContainerView; }
138139

139140
public boolean performNewFileItemClick(DisplayTypes.FileType fileItem) {
140-
return performNewFileItemClick(fileItem.getLayoutContainer().findViewById(R.id.fileSelectCheckBox), fileItem);
141+
if(fileItem.getLayoutContainer() != null) {
142+
return performNewFileItemClick(fileItem.getLayoutContainer().findViewById(R.id.fileSelectCheckBox), fileItem);
143+
}
144+
return false;
141145
}
142146

143147
public static boolean performNewFileItemClick(CheckBox cbView, DisplayTypes.FileType fileItem) {
144148
if(fileItem == null) {
145149
return false;
146150
}
147151
boolean isDir = fileItem.isDirectory();
148-
if(!isDir && !DisplayFragments.allowSelectFiles) {
152+
if(!isDir && !DisplayFragments.getInstance().allowSelectFiles) {
149153
Log.i(LOGTAG, "Blocking file item selection I");
150154
return false;
151155
}
152-
else if(isDir && !DisplayFragments.allowSelectFolders) {
156+
else if(isDir && !DisplayFragments.getInstance().allowSelectFolders) {
153157
Log.i(LOGTAG, "Blocking file item selection II");
154158
return false;
155159
}
@@ -162,26 +166,27 @@ else if(isDir && !DisplayFragments.allowSelectFolders) {
162166
fileItem.setChecked(false);
163167
selectionMarker.setChecked(false);
164168
selectionMarker.setEnabled(true);
165-
DisplayFragments.activeSelectionsList.remove(fileItem);
166-
DisplayFragments.curSelectionCount--;
169+
DisplayFragments.getInstance().activeSelectionsList.remove(fileItem);
170+
DisplayFragments.getInstance().curSelectionCount--;
167171
Log.i(LOGTAG, "DE-Selected next checkbox (file item)");
168172
return true;
169173
}
170-
else if(DisplayFragments.curSelectionCount >= DisplayFragments.maxAllowedSelections) {
174+
else if(DisplayFragments.getInstance().curSelectionCount >= DisplayFragments.getInstance().maxAllowedSelections) {
171175
return false;
172176
}
173177
fileItem.setChecked(true);
174178
selectionMarker.setChecked(true);
175179
selectionMarker.setEnabled(true);
176-
DisplayFragments.activeSelectionsList.add(fileItem);
177-
DisplayFragments.curSelectionCount++;
180+
DisplayFragments.getInstance().activeSelectionsList.add(fileItem);
181+
DisplayFragments.getInstance().curSelectionCount++;
178182
Log.i(LOGTAG, "Selected next checkbox (file item)");
179183
return true;
180184
}
181185

182186
@Override
183187
public void onClick(View v) {
184-
if(fileItem != null && (!fileItem.isDirectory() || DisplayFragments.allowSelectFolders)) {
188+
Log.i(LOGTAG, "onClick");
189+
if(fileItem != null && (!fileItem.isDirectory() || DisplayFragments.getInstance().allowSelectFolders)) {
185190
if(performNewFileItemClick(fileItem)) {
186191
String filePathType = fileItem.isDirectory() ? "DIR" : "FILE";
187192
String displaySelectMsg = String.format(Locale.getDefault(), "Selected %s \"%s\".", filePathType, fileItem.getBaseName());
@@ -192,6 +197,7 @@ public void onClick(View v) {
192197

193198
@Override
194199
public boolean onLongClick(View v) {
200+
Log.i(LOGTAG, "onLongClick");
195201
if(fileItem != null && !fileItem.isDirectory()) {
196202
if(performNewFileItemClick(fileItem)) {
197203
String displaySelectMsg = String.format(Locale.getDefault(), "Selected FILE \"%s\".", fileItem.getBaseName());
@@ -206,15 +212,16 @@ public boolean onLongClick(View v) {
206212
if(nextFolder == null) {
207213
return false;
208214
}
209-
DisplayTypes.DirectoryResultContext workingFolder = DisplayTypes.DirectoryResultContext.pathHistoryStack.peek();
210-
DisplayTypes.DirectoryResultContext.pathHistoryStack.push(nextFolder);
215+
DisplayTypes.DirectoryResultContext workingFolder = DisplayFragments.getInstance().pathHistoryStack.peek();
216+
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
217+
int fileItemPosIndex = DisplayFragments.getInstance().activeFileItemsDataList.lastIndexOf(fileItem);
211218
if(workingFolder == null) {
212-
workingFolder.loadNextFolderAtIndex(true);
213-
DisplayFragments.descendIntoNextDirectory(true);
219+
nextFolder.loadNextFolderAtIndex(fileItemPosIndex, true);
220+
DisplayFragments.getInstance().descendIntoNextDirectory(true);
214221
}
215222
else {
216-
workingFolder.loadNextFolderAtIndex(fileItem.getRelativeCursorPosition(), false);
217-
DisplayFragments.descendIntoNextDirectory(false);
223+
nextFolder.loadNextFolderAtIndex(fileItemPosIndex, false);
224+
DisplayFragments.getInstance().descendIntoNextDirectory(false);
218225
}
219226
String displayRecurseMsg = String.format(Locale.getDefault(), "Descending recursively into DIR \"%s\".", fileItem.getBaseName());
220227
DisplayUtils.displayToastMessageShort(displayRecurseMsg);

0 commit comments

Comments
 (0)