Skip to content

Commit 60d39bf

Browse files
committed
Directory descend, up, movement (back button) and nav buttons to load stock paths working
1 parent de328f9 commit 60d39bf

9 files changed

Lines changed: 42 additions & 46 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void selectBaseDirectoryByType(FileChooserBuilder.BaseFolderPathType base
143143
break;
144144
case BASE_PATH_TYPE_EXTERNAL_FILES_DOWNLOADS:
145145
baseDirPath = appCtx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
146-
setLegacyBaseFolderByName("Downloads");
146+
setLegacyBaseFolderByName("Download");
147147
break;
148148
case BASE_PATH_TYPE_EXTERNAL_FILES_MOVIES:
149149
baseDirPath = appCtx.getExternalFilesDir(Environment.DIRECTORY_MOVIES);

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,11 @@ public boolean onLongClick(View v) {
206206
}
207207
int fileItemPosIndex = getPositionForView(v);
208208
DisplayTypes.DirectoryResultContext workingFolder;
209-
if(DisplayFragments.getInstance().pathHistoryStack.empty()) {
210-
workingFolder = null;
211-
}
212-
else {
213-
workingFolder = DisplayFragments.getInstance().pathHistoryStack.peek();
214-
}
215209
nextFolderParent.clearDirectoryContentsList();
216210
DisplayFragments.getInstance().pathHistoryStack.push(nextFolderParent);
217-
if(workingFolder == null) {
218-
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, true);
219-
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
220-
Log.i(LOGTAG, "CASE I: next foldr cwd = " + nextFolder.getCWDBasePath());
221-
DisplayFragments.getInstance().descendIntoNextDirectory(true);
222-
}
223-
else {
224-
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, false);
225-
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
226-
Log.i(LOGTAG, "CASE II: next foldr cwd = " + nextFolder.getCWDBasePath());
227-
DisplayFragments.getInstance().descendIntoNextDirectory(false);
228-
}
211+
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, true);
212+
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
213+
DisplayFragments.getInstance().descendIntoNextDirectory(false);
229214
String displayRecurseMsg = String.format(Locale.getDefault(), "Descending recursively into DIR \"%s\".", fileItem.getBaseName());
230215
DisplayUtils.displayToastMessageShort(displayRecurseMsg);
231216
return true;

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,19 @@ private void setViewportMaxFilesCount(int viewportFilesCap) {
9898

9999
public boolean resetViewportMaxFilesCount(View parentViewContainer) {
100100
if(!viewportCapacityMesaured) {
101+
101102
int viewportDisplayHeight = parentViewContainer.getMeasuredHeight();
102103
if(fileItemDisplayHeight == 0 || viewportDisplayHeight == 0) {
103104
return false;
104105
}
105106
setViewportMaxFilesCount((int) Math.floor((double) viewportDisplayHeight / fileItemDisplayHeight));
106107
Log.i(LOGTAG, String.format("DELAYED RESPONSE: VP Height = %d, FItemDisp Height = %d ====> %d",
107108
viewportDisplayHeight, fileItemDisplayHeight, getViewportMaxFilesCount()));
108-
getMainRecyclerView().setItemViewCacheSize(2 * getViewportMaxFilesCount());
109+
getMainRecyclerView().setItemViewCacheSize(getViewportMaxFilesCount());
109110
getMainRecyclerView().setDrawingCacheEnabled(true);
110111
getMainRecyclerView().setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
111112
viewportCapacityMesaured = true;
113+
112114
}
113115
return true;
114116
}
@@ -170,10 +172,6 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
170172
FileChooserActivity.getInstance().stopPrefetchFileUpdatesThread();
171173
clearExistingRecyclerViewLayout();
172174
updateFolderHistoryPaths(FileUtils.getFileBaseNameFromPath(nextFolder.getCWDBasePath()), initNewFileTree);
173-
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
174-
DisplayFragments.FolderNavigationFragment.dirsTwoBackText.setText(folderHistoryTwoBackPath);
175-
176-
// ??? TODO: Later, may want to display a loading notice if initializing a new directory is sluggish ???
177175

178176
// Descend into the next directory:
179177
lastFileDataStartIndex = 0;
@@ -200,15 +198,14 @@ public void initiateNewFolderLoad(FileChooserBuilder.BaseFolderPathType initBase
200198
clearExistingRecyclerViewLayout();
201199
FileChooserActivity.getInstance().setTopLevelBaseFolder(initBaseFolder);
202200
DisplayTypes.DirectoryResultContext cwdFolderContext = DisplayTypes.DirectoryResultContext.probeAtCursoryFolderQuery(initBaseFolder);
201+
cwdFolderContext.setTopLevelFolder(true); // cannot go up higher in the filesystem from here
203202
setCwdFolderContext(cwdFolderContext);
204203
pathHistoryStack.clear();
205204
lastFileDataStartIndex = 0;
206205
lastFileDataEndIndex = Math.min(Math.max(0, cwdFolderContext.getFolderChildCount() - 1), lastFileDataStartIndex + getViewportMaxFilesCount() - 1);
207206
getCwdFolderContext().computeDirectoryContents(lastFileDataStartIndex, lastFileDataEndIndex);
208207
displayNextDirectoryFilesList(getCwdFolderContext().getWorkingDirectoryContents());
209208
updateFolderHistoryPaths(FileUtils.getFileBaseNameFromPath(getCwdFolderContext().getCWDBasePath()), true);
210-
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
211-
DisplayFragments.FolderNavigationFragment.dirsTwoBackText.setText(folderHistoryTwoBackPath);
212209
}
213210

214211
public void displayNextDirectoryFilesList(List<DisplayTypes.FileType> workingDirContentsList, boolean notifyAdapter) {
@@ -281,7 +278,7 @@ public static void resetLayout(View layoutContainer, DisplayTypes.FileType fileI
281278

282279
}
283280

284-
private static final String EMPTY_FOLDER_HISTORY_PATH = "➤ ---- ";
281+
private static final String EMPTY_FOLDER_HISTORY_PATH = "";
285282
private static String folderHistoryOneBackPath = EMPTY_FOLDER_HISTORY_PATH;
286283
private static String folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
287284

@@ -305,14 +302,26 @@ public static void updateFolderHistoryPaths(String nextFolderEntryPointPath, boo
305302
if(nextFolderEntryPointPath == null || nextFolderEntryPointPath.equals("")) {
306303
nextFolderEntryPointPath = EMPTY_FOLDER_HISTORY_PATH;
307304
}
305+
else {
306+
nextFolderEntryPointPath = String.format(Locale.getDefault(), "➤ %s", nextFolderEntryPointPath);
307+
}
308308
if(initNewFileTree) {
309309
folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
310-
folderHistoryOneBackPath = String.format(Locale.getDefault(), "➤ %s", nextFolderEntryPointPath);
310+
folderHistoryOneBackPath = nextFolderEntryPointPath;
311311
}
312312
else {
313313
folderHistoryTwoBackPath = folderHistoryOneBackPath;
314-
folderHistoryOneBackPath = String.format(Locale.getDefault(), "➤ %s", nextFolderEntryPointPath);
314+
folderHistoryOneBackPath = nextFolderEntryPointPath;
315315
}
316+
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
317+
//DisplayFragments.FolderNavigationFragment.dirsTwoBackText.setText(folderHistoryTwoBackPath);
318+
}
319+
320+
public static void backupFolderHistoryPaths() {
321+
folderHistoryOneBackPath = folderHistoryTwoBackPath;
322+
folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
323+
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
324+
//DisplayFragments.FolderNavigationFragment.dirsTwoBackText.setText(folderHistoryTwoBackPath);
316325
}
317326

318327
public void cancelAllOperationsInProgress() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static class DirectoryResultContext {
4444
private String parentDocId;
4545
private String activeCWDAbsPath;
4646
private int folderMaxChildCount;
47+
private boolean isTopLevelFolder;
4748

4849
public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, String parentFolderAbsPath) {
4950
directoryContentsList = new ArrayList<FileType>();
@@ -59,6 +60,7 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
5960
nfe.printStackTrace();
6061
folderMaxChildCount = 0;
6162
}
63+
isTopLevelFolder = false;
6264
Log.i(LOGTAG, String.format(Locale.getDefault(), "Initializing new folder at path: \"%s\" ... ", activeCWDAbsPath));
6365
}
6466

@@ -68,6 +70,9 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
6870

6971
public int getFolderChildCount() { return folderMaxChildCount; }
7072

73+
public boolean isTopLevelFolder() { return isTopLevelFolder; }
74+
public void setTopLevelFolder(boolean topLevel) { isTopLevelFolder = topLevel; }
75+
7176
public String getCWDBasePath() {
7277
return FileUtils.getFileBaseNameFromPath(activeCWDAbsPath);
7378
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,17 @@ public void onClick(View btnView) {
189189
@Override
190190
public void onClick(View view) {
191191
DisplayFragments displayCtx = DisplayFragments.getInstance();
192-
if(displayCtx.pathHistoryStack.empty()) {
192+
if(displayCtx.pathHistoryStack.empty() || displayCtx.getCwdFolderContext().isTopLevelFolder()) {
193193
getInstance().postSelectedFilesActivityResult(new FileChooserException.CommunicateNoDataException());
194194
return;
195195
}
196196
String displayAscendingPrecurseMsg = String.format(Locale.getDefault(), "Ascending back upwards into DIR \"%s\".",
197197
displayCtx.pathHistoryStack.peek().getCWDBasePath());
198198
DisplayUtils.displayToastMessageShort(displayAscendingPrecurseMsg);
199-
displayCtx.descendIntoNextDirectory(false);
199+
DisplayTypes.DirectoryResultContext priorFolder = DisplayTypes.DirectoryResultContext.probePreviousFolder(1);
200+
DisplayFragments.getInstance().pathHistoryStack.push(priorFolder);
201+
DisplayFragments.getInstance().descendIntoNextDirectory(displayCtx.pathHistoryStack.pop().isTopLevelFolder());
202+
DisplayFragments.backupFolderHistoryPaths();
200203
}
201204
});
202205
LinearLayout dirHistoryNavContainer = (LinearLayout) findViewById(R.id.mainDirPrevPathsNavContainer);

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This program (the AndroidFilePickerLight library) is free software written by
3030
* The logic in this class should be the reason the scolling action
3131
* in the RecyclerView used to display the files listings graphically works well.
3232
* The idea and problem is the following: In a large directory of image screenshots
33-
* (several GB worth, and spread across ~100 entries), it is infeasible to load all of the
33+
* (several GB worth, and spread across ~4x100 entries), it is infeasible to load all of the
3434
* files to list into the UI layout views at once. The standard solution for this on
3535
* Android is approximated by the use of a RecyclerView. The semi non-standard usage of this
3636
* functionality requires fast, fling-based scrolling through the large file list.
@@ -271,13 +271,6 @@ protected void onPreExecute() {
271271

272272
displayCtx = DisplayFragments.getInstance();
273273

274-
// In the meantime, display a quick positional status Toast message to the user since
275-
// scrollbars do not indicate the number of files left to view very well:
276-
//DisplayUtils.displayFolderScrollContents(
277-
// displayCtx.lastFileDataStartIndex + 1,
278-
// displayCtx.getCwdFolderContext().getFolderChildCount()
279-
//);
280-
281274
}
282275

283276
protected void onProgressUpdate(Integer... progress) {

AndroidFilePickerLightLibrary/src/main/res/layout/main_picker_activity_base_layout.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@
144144
android:gravity="left|center_vertical"
145145
android:layout_gravity="left|center_vertical"
146146
android:paddingBottom="2dp"
147-
android:text="---"
147+
android:text=""
148148
android:textColor="?__colorPrimaryDark"
149-
android:textSize="12sp"
149+
android:textSize="15sp"
150150
android:textStyle="normal|bold"
151151
android:typeface="serif"
152152
/>
@@ -157,11 +157,12 @@
157157
android:layout_height="wrap_content"
158158
android:gravity="left|center_vertical"
159159
android:layout_gravity="left|center_vertical"
160-
android:text="---"
160+
android:text=""
161161
android:textColor="?__colorPrimaryDark"
162-
android:textSize="12sp"
162+
android:textSize="14sp"
163163
android:textStyle="normal|bold"
164164
android:typeface="serif"
165+
android:visibility="gone"
165166
/>
166167

167168
</LinearLayout>
@@ -183,7 +184,7 @@
183184
android:layout_gravity="center_horizontal|top"
184185
android:gravity="center_horizontal|top"
185186
android:background="?__colorPrimary"
186-
android:orientation="horizontal"
187+
android:orientation="vertical"
187188
android:clickable="true"
188189
>
189190

AndroidFilePickerLightLibrary/src/main/res/xml/file_provider_paths_base.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<external-cache-path name="external_cache" path="." />
3131

3232
<external-files name="/storage/self/primary" path="."/>
33-
<external-files name="Downloads" path="Download/" />
33+
<external-files name="Download" path="Download/" />
3434
<external-files name="Movies" path="./Movies/" />
3535
<external-files name="Music" path="./Music" />
3636
<external-files name="Pictures" path="./Pictures/" />
@@ -39,7 +39,7 @@
3939
<external-files name="Camera" path="./DCIM/Camera/" />
4040

4141
<external-files-path name="/storage/self/primary" path="."/>
42-
<external-files-path name="Downloads" path="Download/" />
42+
<external-files-path name="Download" path="Download/" />
4343
<external-files-path name="Movies" path="Movies/" />
4444
<external-files-path name="Music" path="Music" />
4545
<external-files-path name="Pictures" path="Pictures/" />
96.5 KB
Loading

0 commit comments

Comments
 (0)