@@ -20,18 +20,16 @@ This program (the AndroidFilePickerLight library) is free software written by
2020import android .graphics .drawable .Drawable ;
2121import android .util .Log ;
2222import android .view .View ;
23- import android .widget .Button ;
2423import android .widget .CheckBox ;
25- import android .widget .ImageButton ;
2624import android .widget .ImageView ;
2725import android .widget .LinearLayout ;
2826import android .widget .TextView ;
2927
30- import androidx .recyclerview .widget .LinearLayoutManager ;
3128import androidx .recyclerview .widget .RecyclerView ;
3229
3330import java .util .ArrayList ;
3431import java .util .List ;
32+ import java .util .Locale ;
3533import java .util .Stack ;
3634
3735public class DisplayFragments {
@@ -115,24 +113,6 @@ public boolean resetViewportMaxFilesCount(View parentViewContainer) {
115113 return true ;
116114 }
117115
118- private static final String EMPTY_FOLDER_HISTORY_PATH = "<NONE>" ;
119- private static String folderHistoryOneBackPath = EMPTY_FOLDER_HISTORY_PATH ;
120- private static String folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH ;
121-
122- public static void updateFolderHistoryPaths (String nextFolderEntryPointPath , boolean initNewFileTree ) {
123- if (nextFolderEntryPointPath == null || nextFolderEntryPointPath .equals ("" )) {
124- nextFolderEntryPointPath = EMPTY_FOLDER_HISTORY_PATH ;
125- }
126- if (initNewFileTree ) {
127- folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH ;
128- folderHistoryOneBackPath = nextFolderEntryPointPath ;
129- }
130- else {
131- folderHistoryTwoBackPath = folderHistoryOneBackPath ;
132- folderHistoryOneBackPath = nextFolderEntryPointPath ;
133- }
134- }
135-
136116 public void initializeRecyclerViewLayout (FileChooserRecyclerView rview ) {
137117 if (!recyclerViewAdapterInit ) {
138118 rview .setupRecyclerViewLayout ();
@@ -163,6 +143,19 @@ public void resetRecyclerViewLayoutContext() {
163143 }
164144 }
165145
146+ public void clearExistingRecyclerViewLayout () {
147+ // Completely clear out the previously displayed contents:
148+ FileChooserRecyclerView mainRV = getMainRecyclerView ();
149+ mainRV .invalidate ();
150+ DisplayAdapters .FileListAdapter rvAdapter = (DisplayAdapters .FileListAdapter ) mainRV .getAdapter ();
151+ int priorAdapterCount = rvAdapter .getItemCount ();
152+ rvAdapter .reloadDataSets (new ArrayList <String >(), new ArrayList <DisplayTypes .FileType >(), false );
153+ rvAdapter .notifyItemRangeRemoved (0 , priorAdapterCount );
154+ rvAdapter .notifyDataSetChanged ();
155+ mainRV .removeAllViews ();
156+ mainRV .removeAllViewsInLayout ();
157+ }
158+
166159 public void descendIntoNextDirectory (boolean initNewFileTree ) {
167160
168161 if (pathHistoryStack .empty ()) {
@@ -175,17 +168,10 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
175168
176169 // Stop the prefetch thread for the current directory:
177170 FileChooserActivity .getInstance ().stopPrefetchFileUpdatesThread ();
178-
179- // Completely clear out the previously displayed contents:
180- FileChooserRecyclerView mainRV = getMainRecyclerView ();
181- mainRV .invalidate ();
182- DisplayAdapters .FileListAdapter rvAdapter = (DisplayAdapters .FileListAdapter ) mainRV .getAdapter ();
183- int priorAdapterCount = rvAdapter .getItemCount ();
184- rvAdapter .reloadDataSets (new ArrayList <String >(), new ArrayList <DisplayTypes .FileType >(), false );
185- rvAdapter .notifyItemRangeRemoved (0 , priorAdapterCount );
186- rvAdapter .notifyDataSetChanged ();
187- mainRV .removeAllViews ();
188- mainRV .removeAllViewsInLayout ();
171+ clearExistingRecyclerViewLayout ();
172+ updateFolderHistoryPaths (FileUtils .getFileBaseNameFromPath (nextFolder .getCWDBasePath ()), initNewFileTree );
173+ DisplayFragments .FolderNavigationFragment .dirsOneBackText .setText (folderHistoryOneBackPath );
174+ DisplayFragments .FolderNavigationFragment .dirsTwoBackText .setText (folderHistoryTwoBackPath );
189175
190176 // ??? TODO: Later, may want to display a loading notice if initializing a new directory is sluggish ???
191177
@@ -195,8 +181,6 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
195181 setCwdFolderContext (nextFolder );
196182 getCwdFolderContext ().computeDirectoryContents (lastFileDataStartIndex , lastFileDataEndIndex );
197183 displayNextDirectoryFilesList (getCwdFolderContext ().getWorkingDirectoryContents ());
198- DisplayFragments .FolderNavigationFragment .dirsOneBackText .setText (folderHistoryOneBackPath );
199- DisplayFragments .FolderNavigationFragment .dirsTwoBackText .setText (folderHistoryTwoBackPath );
200184
201185 // Restart the prefetch thread for the current directory:
202186 FileChooserActivity .getInstance ().startPrefetchFileUpdatesThread ();
@@ -213,15 +197,16 @@ public void descendIntoNextDirectory(boolean initNewFileTree) {
213197 * RecyclerView pattern making compendia on a whole new dataset):
214198 */
215199 public void initiateNewFolderLoad (FileChooserBuilder .BaseFolderPathType initBaseFolder ) {
200+ clearExistingRecyclerViewLayout ();
216201 FileChooserActivity .getInstance ().setTopLevelBaseFolder (initBaseFolder );
217202 DisplayTypes .DirectoryResultContext cwdFolderContext = DisplayTypes .DirectoryResultContext .probeAtCursoryFolderQuery (initBaseFolder );
218203 setCwdFolderContext (cwdFolderContext );
219204 pathHistoryStack .clear ();
220- pathHistoryStack .push (cwdFolderContext );
221205 lastFileDataStartIndex = 0 ;
222- lastFileDataEndIndex = lastFileDataStartIndex + getViewportMaxFilesCount () - 1 ;
206+ lastFileDataEndIndex = Math . min ( Math . max ( 0 , cwdFolderContext . getFolderChildCount () - 1 ), lastFileDataStartIndex + getViewportMaxFilesCount () - 1 ) ;
223207 getCwdFolderContext ().computeDirectoryContents (lastFileDataStartIndex , lastFileDataEndIndex );
224208 displayNextDirectoryFilesList (getCwdFolderContext ().getWorkingDirectoryContents ());
209+ updateFolderHistoryPaths (FileUtils .getFileBaseNameFromPath (getCwdFolderContext ().getCWDBasePath ()), true );
225210 DisplayFragments .FolderNavigationFragment .dirsOneBackText .setText (folderHistoryOneBackPath );
226211 DisplayFragments .FolderNavigationFragment .dirsTwoBackText .setText (folderHistoryTwoBackPath );
227212 }
@@ -257,9 +242,9 @@ public void displayNextDirectoryFilesList(List<DisplayTypes.FileType> workingDir
257242 displayNextDirectoryFilesList (workingDirContentsList , true );
258243 }
259244
260- public static class FileListItemFragment {
245+ public static class FileItemFragment {
261246
262- private static String LOGTAG = FileListItemFragment .class .getSimpleName ();
247+ private static String LOGTAG = FileItemFragment .class .getSimpleName ();
263248
264249 public static void resetLayout (View layoutContainer , DisplayTypes .FileType fileItem , int displayPosition ) {
265250
@@ -296,6 +281,10 @@ public static void resetLayout(View layoutContainer, DisplayTypes.FileType fileI
296281
297282 }
298283
284+ private static final String EMPTY_FOLDER_HISTORY_PATH = "➤ ---- " ;
285+ private static String folderHistoryOneBackPath = EMPTY_FOLDER_HISTORY_PATH ;
286+ private static String folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH ;
287+
299288 public static FolderNavigationFragment mainFolderNavFragment = null ;
300289
301290 public static class FolderNavigationFragment {
@@ -312,6 +301,20 @@ public static FolderNavigationFragment createNewFolderNavFragment(View navBtnsCo
312301 }
313302 }
314303
304+ public static void updateFolderHistoryPaths (String nextFolderEntryPointPath , boolean initNewFileTree ) {
305+ if (nextFolderEntryPointPath == null || nextFolderEntryPointPath .equals ("" )) {
306+ nextFolderEntryPointPath = EMPTY_FOLDER_HISTORY_PATH ;
307+ }
308+ if (initNewFileTree ) {
309+ folderHistoryTwoBackPath = EMPTY_FOLDER_HISTORY_PATH ;
310+ folderHistoryOneBackPath = String .format (Locale .getDefault (), "➤ %s" , nextFolderEntryPointPath );
311+ }
312+ else {
313+ folderHistoryTwoBackPath = folderHistoryOneBackPath ;
314+ folderHistoryOneBackPath = String .format (Locale .getDefault (), "➤ %s" , nextFolderEntryPointPath );
315+ }
316+ }
317+
315318 public void cancelAllOperationsInProgress () {
316319 FileChooserActivity .getInstance ().stopPrefetchFileUpdatesThread ();
317320 pathHistoryStack .clear ();
0 commit comments