Skip to content

Commit cd1cdd1

Browse files
committed
Adding recent documents navigation path and optional labels on the navigation buttons for clarity
1 parent cc2213e commit cd1cdd1

24 files changed

Lines changed: 267 additions & 118 deletions

AndroidFilePickerLightLibrary/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ android {
3131
defaultConfig {
3232
minSdkVersion 29
3333
targetSdkVersion 30
34-
versionCode 4
35-
versionName "1.0.3"
34+
versionCode 5
35+
versionName "1.0.4"
3636
}
3737

3838
compileOptions {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public int setFilesListLength(int nextLength) {
120120
private boolean setLegacyBaseFolderByName(String namedSubFolder) {
121121
String userPathSep = FileUtils.FILE_PATH_SEPARATOR;
122122
String storageRelPath = "/storage/self/primary" + (namedSubFolder.length() > 0 ? userPathSep : "");
123-
//String storageRelPath = Environment.getExternalStorageDirectory() + userPathSep;
124123
String absFullFolderPath = String.format(Locale.getDefault(), "%s%s", storageRelPath, namedSubFolder);
125124
File nextFileByPath = new File(absFullFolderPath);
126125
if(nextFileByPath == null || !nextFileByPath.exists()) {
@@ -179,6 +178,13 @@ public void selectBaseDirectoryByType(FileChooserBuilder.BaseFolderPathType base
179178
}
180179
}
181180

181+
public String getCWD() {
182+
if(baseDirPath == null) {
183+
return "";
184+
}
185+
return baseDirPath.getAbsolutePath();
186+
}
187+
182188
public boolean enterNextSubfolder(String subfolderPath) {
183189
File nextSubfolder = new File(baseDirPath, subfolderPath);
184190
boolean status = nextSubfolder.exists() && nextSubfolder.isDirectory();

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static int[] GenerateThemeColorsList(Activity activityCtxRef, @ColorRes i
196196
DisplayUtils.darkenColor(resolvedColor, 0.65f), /* COLOR_PRIMARY_DARK */
197197
DisplayUtils.darkenColor(resolvedColor, 0.80f), /* COLOR_PRIMARY_VERY_DARK */
198198
DisplayUtils.lightenColor(resolvedColor, 0.72f), /* COLOR_ACCENT */
199-
DisplayUtils.lightenColor(resolvedColor, 0.50f), /* COLOR_ACCENT_MEDIUM */
199+
DisplayUtils.lightenColor(resolvedColor, 0.15f), /* COLOR_ACCENT_MEDIUM */
200200
DisplayUtils.lightenColor(resolvedColor, 0.85f), /* COLOR_ACCENT_LIGHT */
201201
DisplayUtils.darkenColor(resolvedColor, 0.88f), /* COLOR_TOOLBAR_BG */
202202
DisplayUtils.lightenColor(resolvedColor, 0.85f), /* COLOR_TOOLBAR_FG */
@@ -258,6 +258,7 @@ public interface FileChooserActivityMainLayoutStylizer {
258258
boolean styleNavigationByPathsBaseDisplay(TextView tvNavBtnsDirective);
259259
boolean styleDefaultPathNavigationButton(ImageButton dirNavBtn, FileChooserBuilder.DefaultNavFoldersType baseFolderBtnType) throws RuntimeException;
260260
boolean styleBottomNavigationActionButtons(Button doneActionBtn, Button cancelActionBtn);
261+
boolean styleDefaultPathNavigationButtonLongText(TextView navBtnLongDesc);
261262
boolean styleMainActivityLayout(View parentContainerLayoutView) throws RuntimeException;
262263
boolean styleMainActivityWindow(Window mainActivityWin) throws RuntimeException;
263264
}
@@ -362,6 +363,15 @@ public boolean styleDefaultPathNavigationButton(ImageButton dirNavBtn, FileChoos
362363
}
363364
}
364365

366+
@Override
367+
public boolean styleDefaultPathNavigationButtonLongText(TextView navBtnLongDesc) {
368+
if(navBtnLongDesc == null) {
369+
return false;
370+
}
371+
navBtnLongDesc.setTextColor(_themeColorScheme.getColorPrimaryDark());
372+
return true;
373+
}
374+
365375
@Override
366376
public boolean styleNavigationByPathsBaseDisplay(TextView tvNavBtnsDirective) {
367377
if(tvNavBtnsDirective == null) {
@@ -504,6 +514,7 @@ public static int getFileItemEntryIconDimension() {
504514
}
505515

506516
public interface FileItemLayoutStylizer {
517+
FileChooserColorScheme getThemeColorizer();
507518
boolean setFileTypeIcon(ImageView imgBtn, DisplayTypes.FileType fileItemEntry);
508519
boolean styleSelectionBox(CompoundButton selectBox);
509520
boolean applyStyleToLayout(View parentViewContainer, DisplayTypes.FileType fileItemEntry) throws RuntimeException;
@@ -530,6 +541,9 @@ public FileItemLayoutStylizer createFileItemLayoutStylizer() {
530541
private final Drawable _folderIcon = folderIconFinal;
531542
private final FileChooserColorScheme _themeColorScheme = themeColorScheme;
532543

544+
@Override
545+
public FileChooserColorScheme getThemeColorizer() { return _themeColorScheme; }
546+
533547
@Override
534548
public boolean setFileTypeIcon(ImageView fileTypeIcon, DisplayTypes.FileType fileItemEntry) {
535549
if(fileTypeIcon == null || fileItemEntry == null) {

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public DisplayTypes.FileType getFileItemByIndex(int indexPos) {
7979

8080
@Override
8181
public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
82-
//Log.i(LOGTAG,"onCreateViewHolder");
8382
View rowItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_file_entry_item, parent, false);
8483
return new BaseViewHolder(rowItem);
8584
}
@@ -98,19 +97,13 @@ public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
9897
}
9998

10099
@Override
101-
public void onViewRecycled(BaseViewHolder bvHolder) {
102-
//Log.i(LOGTAG,"onViewRecycled: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition());
103-
}
100+
public void onViewRecycled(BaseViewHolder bvHolder) {}
104101

105102
@Override
106-
public void onViewDetachedFromWindow(BaseViewHolder bvHolder) {
107-
//Log.i(LOGTAG,"onViewDetachedFromWindow: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition());
108-
}
103+
public void onViewDetachedFromWindow(BaseViewHolder bvHolder) {}
109104

110105
@Override
111-
public void onViewAttachedToWindow(BaseViewHolder bvHolder) {
112-
//Log.i(LOGTAG,"onViewAttachedToWindow: " + bvHolder + " AT initial INDEX " + bvHolder.getInitialIndexPosition());
113-
}
106+
public void onViewAttachedToWindow(BaseViewHolder bvHolder) {}
114107

115108
@Override
116109
public int getItemCount() {
@@ -146,7 +139,7 @@ public boolean onSingleTapUp(MotionEvent e) {
146139
}
147140
@Override
148141
public void onLongPress(MotionEvent e) {
149-
Log.i(LOGTAG, "BaseViewHolder::GestureDetector::onLongPress");
142+
//Log.i(LOGTAG, "BaseViewHolder::GestureDetector::onLongPress");
150143
RecyclerView mainFileListRecyclerView = DisplayFragments.getMainRecyclerView();
151144
View childView = mainFileListRecyclerView.findChildViewUnder(e.getX(), e.getY());
152145
if(childView != null) {
@@ -190,13 +183,11 @@ public static DisplayTypes.FileType getFileItemForView(View v) {
190183

191184
@Override
192185
public void onClick(View v) {
193-
Log.i(LOGTAG, "BaseViewHolder::onClick");
194186
onLongClick(v);
195187
}
196188

197189
@Override
198190
public boolean onLongClick(View v) {
199-
Log.i(LOGTAG, "BaseViewHolder::onLongClick");
200191
DisplayTypes.FileType fileItem = getFileItemForView(v);
201192
if(fileItem != null && fileItem.isDirectory()) {
202193
// Recursively descend into the clicked directory location:
@@ -205,8 +196,6 @@ public boolean onLongClick(View v) {
205196
return false;
206197
}
207198
int fileItemPosIndex = getPositionForView(v);
208-
DisplayTypes.DirectoryResultContext workingFolder;
209-
nextFolderParent.clearDirectoryContentsList();
210199
DisplayFragments.getInstance().pathHistoryStack.push(nextFolderParent);
211200
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, true);
212201
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
@@ -215,18 +204,6 @@ public boolean onLongClick(View v) {
215204
DisplayUtils.displayToastMessageShort(displayRecurseMsg);
216205
return true;
217206
}
218-
/*else if(fileItem != null && !fileItem.isDirectory()) {
219-
View cbView = v.findViewById(R.id.fileSelectCheckBox);
220-
if(cbView == null) {
221-
return false;
222-
}
223-
CheckBox selectionBox = (CheckBox) cbView;
224-
if(!selectionBox.isEnabled()) {
225-
return false;
226-
}
227-
boolean isPrevSelected = selectionBox.isSelected();
228-
return (isPrevSelected == !selectionBox.performClick()); // if the click performed changed the selection, then success
229-
}*/
230207
return false;
231208
}
232209

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
191191
lastFileDataStartIndex = 0;
192192
lastFileDataEndIndex = Math.min(Math.max(0, nextFolder.getFolderChildCount() - 1), lastFileDataStartIndex + getViewportMaxFilesCount() - 1);
193193
setCwdFolderContext(nextFolder);
194-
getCwdFolderContext().computeDirectoryContents(lastFileDataStartIndex, lastFileDataEndIndex);
194+
if(!nextFolder.isRecentDocuments()) {
195+
getCwdFolderContext().computeDirectoryContents(lastFileDataStartIndex, lastFileDataEndIndex);
196+
}
195197
displayNextDirectoryFilesList(getCwdFolderContext().getWorkingDirectoryContents());
196198

197199
// Restart the prefetch thread for the current directory:
@@ -299,7 +301,6 @@ public static void resetLayout(View layoutContainer, DisplayTypes.FileType fileI
299301

300302
private static final String EMPTY_FOLDER_HISTORY_PATH = "";
301303
private static String folderHistoryOneBackPath = EMPTY_FOLDER_HISTORY_PATH;
302-
private static String folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
303304

304305
public static FolderNavigationFragment mainFolderNavFragment = null;
305306

@@ -322,20 +323,7 @@ public static void updateFolderHistoryPaths(String nextFolderEntryPointPath, boo
322323
else {
323324
nextFolderEntryPointPath = String.format(Locale.getDefault(), "➤ %s", nextFolderEntryPointPath);
324325
}
325-
if(initNewFileTree) {
326-
folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
327-
folderHistoryOneBackPath = nextFolderEntryPointPath;
328-
}
329-
else {
330-
folderHistoryTwoBackPath = folderHistoryOneBackPath;
331-
folderHistoryOneBackPath = nextFolderEntryPointPath;
332-
}
333-
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
334-
}
335-
336-
public static void backupFolderHistoryPaths() {
337-
folderHistoryOneBackPath = folderHistoryTwoBackPath;
338-
folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH;
326+
folderHistoryOneBackPath = nextFolderEntryPointPath;
339327
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
340328
}
341329

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static class DirectoryResultContext {
4545
private String activeCWDAbsPath;
4646
private int folderMaxChildCount;
4747
private boolean isTopLevelFolder;
48+
private boolean isRecentDocsFolder;
4849

4950
public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, String parentFolderAbsPath) {
5051
directoryContentsList = new ArrayList<FileType>();
@@ -55,13 +56,19 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
5556
BasicFileProvider fpInst = BasicFileProvider.getInstance();
5657
fpInst.noUpdateQueryFilesList();
5758
try {
58-
folderMaxChildCount = fpInst.getFolderChildCount(parentDocId);
59+
if(isRecentDocuments()) {
60+
folderMaxChildCount = mcResult.getCount();
61+
}
62+
else {
63+
folderMaxChildCount = fpInst.getFolderChildCount(parentDocId);
64+
}
5965
} catch(FileNotFoundException nfe) {
6066
nfe.printStackTrace();
6167
folderMaxChildCount = 0;
6268
}
6369
isTopLevelFolder = false;
64-
Log.i(LOGTAG, String.format(Locale.getDefault(), "Initializing new folder at path: \"%s\" ... ", activeCWDAbsPath));
70+
isRecentDocsFolder = false;
71+
Log.d(LOGTAG, String.format(Locale.getDefault(), "Initializing new folder at path: \"%s\" ... ", activeCWDAbsPath));
6572
}
6673

6774
public List<FileType> getWorkingDirectoryContents() { return directoryContentsList; }
@@ -73,6 +80,14 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
7380
public boolean isTopLevelFolder() { return isTopLevelFolder; }
7481
public void setTopLevelFolder(boolean topLevel) { isTopLevelFolder = topLevel; }
7582

83+
public boolean isRecentDocuments() {
84+
return isRecentDocsFolder;
85+
}
86+
public void setIsRecentDocuments(boolean isRecentDocs) {
87+
isRecentDocsFolder = isRecentDocs;
88+
setTopLevelFolder(isRecentDocs);
89+
}
90+
7691
public String getCWDBasePath() {
7792
return FileUtils.getFileBaseNameFromPath(activeCWDAbsPath);
7893
}
@@ -165,16 +180,42 @@ public DirectoryResultContext loadNextFolderAtIndex(int posIndex, boolean initNe
165180
DisplayFragments.updateFolderHistoryPaths(FileUtils.getFileBaseNameFromPath(activeCWDAbsPath), initNewFileTree);
166181
try {
167182
// Load the document ID for the current position in case it is out of range:
168-
computeDirectoryContents(posIndex, posIndex);
169-
FileType selectedFileItem = directoryContentsList.get(0);
170-
return probeAtCursoryFolderQuery(selectedFileItem.getBaseName());
183+
if(!isRecentDocuments()) {
184+
computeDirectoryContents(posIndex, posIndex);
185+
FileType selectedFileItem = directoryContentsList.get(0);
186+
return probeAtCursoryFolderQuery(selectedFileItem.getBaseName());
187+
}
188+
else {
189+
FileType selectedFileItem = directoryContentsList.get(posIndex);
190+
return probeAtCursoryFolderQuery(selectedFileItem.getAbsolutePath().replaceAll(fpInst.getCWD(), ""));
191+
}
171192
} catch(Exception ioe) {
172193
ioe.printStackTrace();
173194
DisplayFragments.getInstance().pathHistoryStack.pop();
174195
return null;
175196
}
176197
}
177198

199+
private static DirectoryResultContext probeAtCursoryFolderQueryGetNextRecents() {
200+
BasicFileProvider fpInst = BasicFileProvider.getInstance();
201+
try {
202+
MatrixCursor cursoryProbe = (MatrixCursor) fpInst.queryRoots(BasicFileProvider.DEFAULT_ROOT_PROJECTION);
203+
cursoryProbe.moveToFirst();
204+
String initDirBaseName = fpInst.getBaseNameAtCurrentRow(cursoryProbe, BasicFileProvider.CURSOR_TYPE_IS_ROOT);
205+
String cursoryProbeFolderCwd = "Recent Documents";
206+
DisplayFragments.updateFolderHistoryPaths(cursoryProbeFolderCwd, true);
207+
String parentDocsId = cursoryProbe.getString(BasicFileProvider.ROOT_PROJ_ROOTID_COLUMN_INDEX);
208+
MatrixCursor expandedFolderContents = (MatrixCursor) fpInst.queryRecentDocuments(parentDocsId, BasicFileProvider.DEFAULT_DOCUMENT_PROJECTION);
209+
DirectoryResultContext exploredFolderCtx = new DirectoryResultContext(expandedFolderContents, parentDocsId, cursoryProbeFolderCwd);
210+
exploredFolderCtx.setIsRecentDocuments(true);
211+
return exploredFolderCtx;
212+
}
213+
catch(IOException ioe) {
214+
ioe.printStackTrace();
215+
return null;
216+
}
217+
}
218+
178219
private static DirectoryResultContext probeAtCursoryFolderQueryGetNext() {
179220
BasicFileProvider fpInst = BasicFileProvider.getInstance();
180221
try {
@@ -203,8 +244,14 @@ public static DirectoryResultContext probeAtCursoryFolderQuery(FileChooserBuilde
203244
fpInst.setCustomFileFilter(DisplayFragments.getInstance().localFilesListFilter);
204245
fpInst.setCustomFolderSort(DisplayFragments.getInstance().localFilesListSortFunc);
205246
}
206-
fpInst.selectBaseDirectoryByType(baseFolderChoice);
207-
return probeAtCursoryFolderQueryGetNext();
247+
if(baseFolderChoice.ordinal() != FileChooserBuilder.BaseFolderPathType.BASE_PATH_TYPE_RECENT_DOCUMENTS.ordinal()) {
248+
fpInst.selectBaseDirectoryByType(baseFolderChoice);
249+
return probeAtCursoryFolderQueryGetNext();
250+
}
251+
else {
252+
fpInst.selectBaseDirectoryByType(FileChooserBuilder.BaseFolderPathType.BASE_PATH_DEFAULT);
253+
return probeAtCursoryFolderQueryGetNextRecents();
254+
}
208255
}
209256

210257
public static DirectoryResultContext probeAtCursoryFolderQuery(String nextSubfolderPath) {
@@ -287,6 +334,10 @@ public String getBaseName() {
287334
return FileUtils.getFileBaseNameFromPath(getAbsolutePath());
288335
}
289336

337+
public String getBasePath() {
338+
return FileUtils.getFileBasePath(getAbsolutePath());
339+
}
340+
290341
public boolean isDirectory() {
291342
return isDir;
292343
}

0 commit comments

Comments
 (0)