Skip to content

Commit b9a1355

Browse files
committed
Beginning work on the directory traversals (partially working)
1 parent 0159423 commit b9a1355

5 files changed

Lines changed: 63 additions & 35 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ public boolean enterNextSubfolder(String subfolderPath) {
188188
return status;
189189
}
190190

191+
public boolean backOneFolder() {
192+
if(baseDirPath == null) {
193+
return false;
194+
}
195+
File parentFolder = baseDirPath.getParentFile();
196+
if(parentFolder != null) {
197+
baseDirPath = parentFolder;
198+
return true;
199+
}
200+
return false;
201+
}
202+
191203
@Override
192204
public boolean onCreate() {
193205
if(fileProviderStaticInst == null) {

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,21 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
178178

179179
// Completely clear out the previously displayed contents:
180180
FileChooserRecyclerView mainRV = getMainRecyclerView();
181+
mainRV.invalidate();
181182
DisplayAdapters.FileListAdapter rvAdapter = (DisplayAdapters.FileListAdapter) mainRV.getAdapter();
182183
int priorAdapterCount = rvAdapter.getItemCount();
183184
rvAdapter.reloadDataSets(new ArrayList<String>(), new ArrayList<DisplayTypes.FileType>(), false);
184185
rvAdapter.notifyItemRangeRemoved(0, priorAdapterCount);
185186
rvAdapter.notifyDataSetChanged();
186187
mainRV.removeAllViews();
187188
mainRV.removeAllViewsInLayout();
188-
mainRV.invalidate();
189+
190+
// ??? TODO: Later, may want to display a loading notice if initializing a new directory is sluggish ???
189191

190192
// Descend into the next directory:
191193
lastFileDataStartIndex = 0;
192-
lastFileDataEndIndex = lastFileDataStartIndex + getViewportMaxFilesCount() - 1;
194+
lastFileDataEndIndex = Math.min(Math.max(0, nextFolder.getFolderChildCount() - 1), lastFileDataStartIndex + getViewportMaxFilesCount() - 1);
193195
setCwdFolderContext(nextFolder);
194-
// ??? TODO: Later, may want to display a loading notice if initializing a new directory is sluggish ???
195196
getCwdFolderContext().computeDirectoryContents(lastFileDataStartIndex, lastFileDataEndIndex);
196197
displayNextDirectoryFilesList(getCwdFolderContext().getWorkingDirectoryContents());
197198
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
@@ -299,32 +300,14 @@ public static void resetLayout(View layoutContainer, DisplayTypes.FileType fileI
299300

300301
public static class FolderNavigationFragment {
301302

302-
private static FolderNavigationFragment folderNavFragmentStaticInst = null;
303303
public static TextView dirsTwoBackText = null;
304304
public static TextView dirsOneBackText = null;
305-
public static ImageButton globalNavBackBtn = null;
306-
307-
public FolderNavigationFragment() {
308-
folderNavFragmentStaticInst = this;
309-
}
310305

311306
public static FolderNavigationFragment createNewFolderNavFragment(View navBtnsContainerView) {
312307
FolderNavigationFragment folderNavFragment = new FolderNavigationFragment();
313308
dirsTwoBackText = FileChooserActivity.getInstance().findViewById(R.id.mainDirNavBackTwoPathDisplayText);
314309
dirsOneBackText = FileChooserActivity.getInstance().findViewById(R.id.mainDirNavBackOnePathDisplayText);
315-
globalNavBackBtn = FileChooserActivity.getInstance().findViewById(R.id.mainDirNavGlobalBackBtn);
316310
updateFolderHistoryPaths(null, true);
317-
Button.OnClickListener backBtnClickListener = new Button.OnClickListener() {
318-
@Override
319-
public void onClick(View btnView) {
320-
ImageButton navBtn = (ImageButton) btnView;
321-
String baseFolderTypeName = btnView.getTag().toString();
322-
FileChooserBuilder.BaseFolderPathType baseFolderPathType = FileChooserBuilder.BaseFolderPathType.getInstanceByName(baseFolderTypeName);
323-
BasicFileProvider.getInstance().selectBaseDirectoryByType(baseFolderPathType);
324-
getInstance().initiateNewFolderLoad(baseFolderPathType);
325-
}
326-
};
327-
globalNavBackBtn.setOnClickListener(backBtnClickListener);
328311
return folderNavFragment;
329312
}
330313
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ public static DirectoryResultContext probeAtCursoryFolderQuery(String nextSubfol
235235
return probeAtCursoryFolderQueryGetNext();
236236
}
237237

238+
public static DirectoryResultContext probePreviousFolder(int howManyBackwards) {
239+
BasicFileProvider fpInst = BasicFileProvider.getInstance();
240+
if(fpInst == null) {
241+
return null;
242+
}
243+
else {
244+
fpInst.setCustomFileFilter(DisplayFragments.getInstance().localFilesListFilter);
245+
fpInst.setCustomFolderSort(DisplayFragments.getInstance().localFilesListSortFunc);
246+
}
247+
if(howManyBackwards <= 0) {
248+
return null;
249+
}
250+
while(--howManyBackwards >= 0) {
251+
if(!fpInst.backOneFolder()) {
252+
return null;
253+
}
254+
}
255+
return probeAtCursoryFolderQueryGetNext();
256+
}
257+
238258
}
239259

240260
public static class FileType {

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,29 @@ public void onClick(View btnView) {
184184
fileDirsNavButtonsContainer.addView(dirNavBtn);
185185
}
186186

187+
/*
188+
* Handle setting up the default graphical back button:
189+
* It should take the user (loading in the correct directory context) backwards on
190+
* folder into which they have traversed. If no folders have been entered, it returns
191+
* an empty selection back to the client application.
192+
*/
193+
ImageButton backBtn = findViewById(R.id.mainDirNavGlobalBackBtn);
194+
backBtn.setOnClickListener(new View.OnClickListener() {
195+
@Override
196+
public void onClick(View view) {
197+
DisplayFragments displayCtx = DisplayFragments.getInstance();
198+
if(displayCtx.pathHistoryStack.empty()) {
199+
getInstance().postSelectedFilesActivityResult(new FileChooserException.CommunicateNoDataException());
200+
}
201+
String displayAscendingPrecurseMsg = String.format(Locale.getDefault(), "Ascending back upwards into DIR \"%s\".",
202+
displayCtx.pathHistoryStack.peek().getCWDBasePath());
203+
DisplayUtils.displayToastMessageShort(displayAscendingPrecurseMsg);
204+
displayCtx.descendIntoNextDirectory(false);
205+
}
206+
});
207+
LinearLayout dirHistoryNavContainer = (LinearLayout) findViewById(R.id.mainDirPrevPathsNavContainer);
208+
DisplayFragments.mainFolderNavFragment = DisplayFragments.FolderNavigationFragment.createNewFolderNavFragment(dirHistoryNavContainer);
209+
187210
/* The next level of navigation in a top down order is the action buttons to finish or cancel
188211
* the user's file selection procedure. These need onClick handlers that are mostly separate
189212
* and less involved that the corresponding RecyclerView and files listing UI actions.
@@ -215,16 +238,6 @@ public void onClick(View btnView) {
215238
};
216239
doneActionBtn.setOnClickListener(doneActivityBtnClickListener);
217240

218-
/*
219-
* Last, there is the global back button and previous directory history display.
220-
* Note that unless a completely different path trajectory is selected by the user
221-
* (with the last level of directory select nav buttons), we keep a working
222-
* stack of the last paths for context. If the back button is pressed and the stack is
223-
* empty, this action is handled the same way as a cancel button press by the user.
224-
*/
225-
LinearLayout dirHistoryNavContainer = (LinearLayout) findViewById(R.id.mainDirPrevPathsNavContainer);
226-
DisplayFragments.mainFolderNavFragment = DisplayFragments.FolderNavigationFragment.createNewFolderNavFragment(dirHistoryNavContainer);
227-
228241
/* Setup some theme related styling on the main file list container: */
229242
FileChooserRecyclerView mainLayoutRecyclerView = findViewById(R.id.mainRecyclerView);
230243
getDisplayFragmentsInstance().initializeRecyclerViewLayout(mainLayoutRecyclerView);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ public void launchFilePicker() throws FileChooserException.AndroidFilePickerLigh
405405
activityContextRef.get().startActivityForResult(launchPickerIntent, activityActionCode);
406406
}
407407

408-
public static final int ACTIVITY_CODE_SELECT_FILE = 1;
409-
public static final int ACTIVITY_CODE_SELECT_DIRECTORY_ONLY = 2;
410-
public static final int ACTIVITY_CODE_SELECT_MULTIPLE_FILES = 3;
411-
public static final int ACTIVITY_CODE_BRING_TO_FRONT = 4;
408+
private static final int FILE_PICKER_SWIZZLED_BITS_OFFSET = (8080 << 3) + 2;
409+
public static final int ACTIVITY_CODE_SELECT_FILE = 1 + FILE_PICKER_SWIZZLED_BITS_OFFSET;
410+
public static final int ACTIVITY_CODE_SELECT_DIRECTORY_ONLY = 2 + FILE_PICKER_SWIZZLED_BITS_OFFSET;
411+
public static final int ACTIVITY_CODE_SELECT_MULTIPLE_FILES = 3 + FILE_PICKER_SWIZZLED_BITS_OFFSET;
412412

413413
/* Client code should call this method in their main Activity's onActivityResult function
414414
* to handle the logic there when the activity was created as a file picker instance:

0 commit comments

Comments
 (0)