Skip to content

Commit de328f9

Browse files
committed
The top nav buttons work; Back button context needs testing
1 parent b9a1355 commit de328f9

7 files changed

Lines changed: 92 additions & 123 deletions

File tree

AndroidFilePickerLightLibrary/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<uses-permission android:name="android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION" android:required="false" />
2525
<uses-permission android:name="android.permission.INTERNET" android:required="false" />
2626

27+
<!-- tools:replace="android:theme" -->
28+
2729
<application
2830
android:launchMode="singleTop"
2931
android:noHistory="false"

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ This program (the AndroidFilePickerLight library) is free software written by
2525
import android.view.ViewGroup;
2626
import android.widget.CheckBox;
2727
import android.widget.CompoundButton;
28-
import android.widget.TextView;
2928

3029
import androidx.recyclerview.widget.RecyclerView;
3130

@@ -92,7 +91,7 @@ public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
9291
DisplayTypes.FileType fileItem = fileItemsData.get(posIndex);
9392
fileItem.setLayoutContainer(bvHolder.getMainViewLayoutContainer());
9493
View viewItemContainer = bvHolder.getMainViewLayoutContainer();
95-
DisplayFragments.FileListItemFragment.resetLayout(viewItemContainer, fileItem, posIndex);
94+
DisplayFragments.FileItemFragment.resetLayout(viewItemContainer, fileItem, posIndex);
9695
}
9796
//Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- (ADAPTER -> %s) [DATA ITEMS SIZE = %d]", posIndex,
9897
// fileListData.get(posIndex), fileItemsData.size()));
@@ -217,14 +216,14 @@ public boolean onLongClick(View v) {
217216
DisplayFragments.getInstance().pathHistoryStack.push(nextFolderParent);
218217
if(workingFolder == null) {
219218
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, true);
220-
nextFolder = DisplayTypes.DirectoryResultContext.probeAtCursoryFolderQuery(nextFolder.getCWDBasePath());
221219
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
220+
Log.i(LOGTAG, "CASE I: next foldr cwd = " + nextFolder.getCWDBasePath());
222221
DisplayFragments.getInstance().descendIntoNextDirectory(true);
223222
}
224223
else {
225224
DisplayTypes.DirectoryResultContext nextFolder = nextFolderParent.loadNextFolderAtIndex(fileItemPosIndex, false);
226-
nextFolder = DisplayTypes.DirectoryResultContext.probeAtCursoryFolderQuery(nextFolder.getCWDBasePath());
227225
DisplayFragments.getInstance().pathHistoryStack.push(nextFolder);
226+
Log.i(LOGTAG, "CASE II: next foldr cwd = " + nextFolder.getCWDBasePath());
228227
DisplayFragments.getInstance().descendIntoNextDirectory(false);
229228
}
230229
String displayRecurseMsg = String.format(Locale.getDefault(), "Descending recursively into DIR \"%s\".", fileItem.getBaseName());

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

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ This program (the AndroidFilePickerLight library) is free software written by
2020
import android.graphics.drawable.Drawable;
2121
import android.util.Log;
2222
import android.view.View;
23-
import android.widget.Button;
2423
import android.widget.CheckBox;
25-
import android.widget.ImageButton;
2624
import android.widget.ImageView;
2725
import android.widget.LinearLayout;
2826
import android.widget.TextView;
2927

30-
import androidx.recyclerview.widget.LinearLayoutManager;
3128
import androidx.recyclerview.widget.RecyclerView;
3229

3330
import java.util.ArrayList;
3431
import java.util.List;
32+
import java.util.Locale;
3533
import java.util.Stack;
3634

3735
public 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();

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,17 @@ This program (the AndroidFilePickerLight library) is free software written by
1919

2020
import android.database.MatrixCursor;
2121
import android.graphics.drawable.Drawable;
22-
import android.icu.util.LocaleData;
23-
import android.icu.util.Measure;
2422
import android.util.Log;
2523
import android.view.View;
2624
import android.widget.ImageView;
2725

2826
import org.apache.commons.lang3.ArrayUtils;
2927

30-
import java.io.File;
3128
import java.io.FileNotFoundException;
3229
import java.io.IOException;
3330
import java.util.ArrayList;
34-
import java.util.Arrays;
35-
import java.util.Collection;
36-
import java.util.Collections;
37-
import java.util.Iterator;
3831
import java.util.List;
3932
import java.util.Locale;
40-
import java.util.Stack;
41-
import java.util.concurrent.TimeUnit;
42-
import java.util.concurrent.locks.ReentrantLock;
4333

4434
public class DisplayTypes {
4535

@@ -72,8 +62,6 @@ public DirectoryResultContext(MatrixCursor mcResult, String parentFolderDocId, S
7262
Log.i(LOGTAG, String.format(Locale.getDefault(), "Initializing new folder at path: \"%s\" ... ", activeCWDAbsPath));
7363
}
7464

75-
public MatrixCursor getInitialMatrixCursor() { return initMatrixCursorListing; }
76-
7765
public List<FileType> getWorkingDirectoryContents() { return directoryContentsList; }
7866

7967
public void setNextDirectoryContents(List<FileType> nextFolderFiles) { directoryContentsList = nextFolderFiles; }
@@ -175,11 +163,6 @@ public DirectoryResultContext loadNextFolderAtIndex(int posIndex, boolean initNe
175163
computeDirectoryContents(posIndex, posIndex);
176164
FileType selectedFileItem = directoryContentsList.get(0);
177165
return probeAtCursoryFolderQuery(selectedFileItem.getBaseName());
178-
//String nextActiveDocId = selectedFileItem.getFileProviderDocumentId();
179-
//MatrixCursor nextDirCursor = (MatrixCursor) fpInst.queryChildDocuments(nextActiveDocId, BasicFileProvider.DEFAULT_DOCUMENT_PROJECTION, "");
180-
//clearDirectoryContentsList();
181-
//DirectoryResultContext nextFolderCtx = new DirectoryResultContext(nextDirCursor, selectedFileItem.getFileProviderDocumentId(), selectedFileItem.getAbsolutePath());
182-
//return nextFolderCtx;
183166
} catch(Exception ioe) {
184167
ioe.printStackTrace();
185168
DisplayFragments.getInstance().pathHistoryStack.pop();

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,13 @@ private void configureInitialMainLayout(FileChooserBuilder fpConfig) {
163163
public void onClick(View btnView) {
164164
getDisplayFragmentsInstance().cancelAllOperationsInProgress();
165165
getDisplayFragmentsInstance().pathHistoryStack.clear(); // reset the directory traversal history
166-
FileChooserBuilder.BaseFolderPathType navBtnInitFolder = (FileChooserBuilder.BaseFolderPathType) btnView.getTag();
167-
getDisplayFragmentsInstance().initiateNewFolderLoad(navBtnInitFolder);
168-
Button navBtn = (Button) btnView;
169-
navBtn.setEnabled(false);
170-
navBtn.setElevation(-1.0f);
171-
// Re-enable all of the other stock directory nav buttons:
172-
for(int btnIdx = 0; btnIdx < fileDirsNavButtonsContainer.getChildCount(); btnIdx++) {
173-
Button nextNavBtn = (Button) fileDirsNavButtonsContainer.getChildAt(btnIdx);
174-
if(!navBtn.equals(nextNavBtn)) {
175-
nextNavBtn.setEnabled(true);
176-
nextNavBtn.setElevation(0.0f);
177-
}
178-
}
166+
String navBtnInitFolderName = (String) btnView.getTag();
167+
Log.i(LOGTAG, "Next DIR TYPE NAME : " + navBtnInitFolderName);
168+
FileChooserBuilder.BaseFolderPathType navBtnInitFolderType =
169+
FileChooserBuilder.BaseFolderPathType.NAV_FOLDER_NAME_TO_INST_MAP.get(navBtnInitFolderName);
170+
getDisplayFragmentsInstance().initiateNewFolderLoad(navBtnInitFolderType);
171+
String displayIntoNextMsg = String.format(Locale.getDefault(), "Into NAV DIR \"%s\".", navBtnInitFolderName);
172+
DisplayUtils.displayToastMessageShort(displayIntoNextMsg);
179173
}
180174
};
181175
dirNavBtn.setOnClickListener(stockDirNavBtnClickHandler);
@@ -197,6 +191,7 @@ public void onClick(View view) {
197191
DisplayFragments displayCtx = DisplayFragments.getInstance();
198192
if(displayCtx.pathHistoryStack.empty()) {
199193
getInstance().postSelectedFilesActivityResult(new FileChooserException.CommunicateNoDataException());
194+
return;
200195
}
201196
String displayAscendingPrecurseMsg = String.format(Locale.getDefault(), "Ascending back upwards into DIR \"%s\".",
202197
displayCtx.pathHistoryStack.peek().getCWDBasePath());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public enum DefaultNavFoldersType {
101101
public static final Map<Integer, Integer> NAV_FOLDER_ICON_RESIDS_MAP = new HashMap<>();
102102
static {
103103
for (DefaultNavFoldersType navType : values()) {
104-
NAV_FOLDER_NAME_LOOKUP_MAP.put(navType.toString(), navType);
104+
NAV_FOLDER_NAME_LOOKUP_MAP.put(navType.name(), navType);
105105
NAV_FOLDER_DESC_MAP.put(navType, navType.getFolderLabel());
106106
NAV_FOLDER_PATHS_MAP.put(navType, navType.getBaseFolderPathType());
107107
NAV_FOLDER_ICON_RESIDS_MAP.put(navType.ordinal(), navType.getFolderIconResId());

0 commit comments

Comments
 (0)