Skip to content

Commit 76e8d44

Browse files
committed
Backup point -- File selections are now correctly registering, still needs fine tuning with the directory files scroller
1 parent 2de26c9 commit 76e8d44

10 files changed

Lines changed: 233 additions & 97 deletions

File tree

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class DisplayAdapters {
3939

4040
public static class FileListAdapter extends RecyclerView.Adapter<BaseViewHolder> {
4141

42+
private static String LOGTAG = FileListAdapter.class.getSimpleName();
43+
4244
private List<String> fileListData;
4345
private List<DisplayTypes.FileType> fileItemsData;
4446

@@ -92,8 +94,8 @@ public void onBindViewHolder(BaseViewHolder bvHolder, int posIndex) {
9294
View viewItemContainer = bvHolder.getMainViewLayoutContainer();
9395
DisplayFragments.FileListItemFragment.resetLayout(viewItemContainer, fileItem, posIndex);
9496
}
95-
//Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- %s (ADAPTER -> %s) [DATA ITEMS SIZE = %d]", posIndex,
96-
// bvHolder.getDisplayText().getText(), fileListData.get(posIndex), fileItemsData.size()));
97+
Log.i(LOGTAG, String.format(Locale.getDefault(), "onBindViewHolder @ %d -- (ADAPTER -> %s) [DATA ITEMS SIZE = %d]", posIndex,
98+
fileListData.get(posIndex), fileItemsData.size()));
9799
}
98100

99101
@Override
@@ -130,8 +132,9 @@ public int getItemViewType(int posIndex) {
130132

131133
public static class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener, RecyclerView.OnItemTouchListener {
132134

135+
private static String LOGTAG = BaseViewHolder.class.getSimpleName();
136+
133137
private View fileItemContainerView;
134-
public TextView displayText;
135138
private int initIndexPos;
136139

137140
private GestureDetector gestureDetector = new GestureDetector(FileChooserActivity.getInstance(), new GestureDetector.SimpleOnGestureListener() {
@@ -141,11 +144,10 @@ public boolean onSingleTapUp(MotionEvent e) {
141144
}
142145
@Override
143146
public void onLongPress(MotionEvent e) {
144-
Log.i(LOGTAG, "onLongPress::onLongPress");
147+
Log.i(LOGTAG, "BaseViewHolder::GestureDetector::onLongPress");
145148
RecyclerView mainFileListRecyclerView = DisplayFragments.getMainRecyclerView();
146149
View childView = mainFileListRecyclerView.findChildViewUnder(e.getX(), e.getY());
147150
if(childView != null) {
148-
////clickListener.onLongClick(child, DisplayFragments.mainFileListRecyclerView, DisplayFragments.mainFileListRecyclerView.getChildPosition(child));
149151
onLongClick(childView);
150152
}
151153
}
@@ -158,14 +160,10 @@ public BaseViewHolder(View v) {
158160
v.setFocusable(true);
159161
v.setOnClickListener(this);
160162
v.setOnLongClickListener(this);
161-
displayText = (TextView) v.findViewById(R.id.fileEntryBaseName);
162163
initIndexPos = -1;
163164

164165
}
165166

166-
public TextView getDisplayText() { return displayText; }
167-
public void setDisplayText(TextView nextDisplayText) { displayText = nextDisplayText; }
168-
169167
public int getInitialIndexPosition() { return initIndexPos; }
170168
public void setInitialIndexPosition(int initIdx) { initIndexPos = initIdx; }
171169

@@ -190,7 +188,8 @@ public static DisplayTypes.FileType getFileItemForView(View v) {
190188

191189
@Override
192190
public void onClick(View v) {
193-
Log.i(LOGTAG, "BaseViewHolder::onClick [RETURNING, DOING NOTHING] ... ");
191+
Log.i(LOGTAG, "BaseViewHolder::onClick");
192+
onLongClick(v);
194193
}
195194

196195
@Override
@@ -218,14 +217,25 @@ public boolean onLongClick(View v) {
218217
DisplayUtils.displayToastMessageShort(displayRecurseMsg);
219218
return true;
220219
}
220+
/*else if(fileItem != null && !fileItem.isDirectory()) {
221+
View cbView = v.findViewById(R.id.fileSelectCheckBox);
222+
if(cbView == null) {
223+
return false;
224+
}
225+
CheckBox selectionBox = (CheckBox) cbView;
226+
if(!selectionBox.isEnabled()) {
227+
return false;
228+
}
229+
boolean isPrevSelected = selectionBox.isSelected();
230+
return (isPrevSelected == !selectionBox.performClick()); // if the click performed changed the selection, then success
231+
}*/
221232
return false;
222233
}
223234

224235
@Override
225236
public boolean onInterceptTouchEvent(RecyclerView rview, MotionEvent mevt) {
226237
View childView = rview.findChildViewUnder(mevt.getX(), mevt.getY());
227238
if(childView != null && gestureDetector.onTouchEvent(mevt)) {
228-
////clickListener.onClick(child, rview.getChildPosition(child));
229239
onClick(childView);
230240
}
231241
return false;

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,36 @@ public void resetRecyclerViewLayoutContext() {
162162
}
163163

164164
public void descendIntoNextDirectory(boolean initNewFileTree) {
165+
165166
if(pathHistoryStack.empty()) {
166167
cancelAllOperationsInProgress();
167168
FileChooserException.GenericRuntimeErrorException rte = new FileChooserException.GenericRuntimeErrorException("Empty context for folder history ( no more history ??? )");
168169
FileChooserActivity.getInstance().postSelectedFilesActivityResult(rte);
169170
}
170171
DisplayTypes.DirectoryResultContext nextFolder = pathHistoryStack.peek();
171172
if(nextFolder != null) {
172-
setCwdFolderContext(nextFolder);
173+
174+
// Completely clear out the previously displayed contents:
175+
FileChooserRecyclerView mainRV = getMainRecyclerView();
176+
mainRV.removeAllViews();
177+
mainRV.removeAllViewsInLayout();
178+
// ??? Need to also clear out the adapter contents ???
179+
180+
// Descend into the next directory:
173181
lastFileDataStartIndex = 0;
174182
lastFileDataEndIndex = lastFileDataStartIndex + getViewportMaxFilesCount() - 1;
183+
setCwdFolderContext(nextFolder);
184+
// ??? TODO: Later, may want to display a loading notice if initializing a new directory is sluggish ???
175185
getCwdFolderContext().computeDirectoryContents(lastFileDataStartIndex, lastFileDataEndIndex);
176186
displayNextDirectoryFilesList(getCwdFolderContext().getWorkingDirectoryContents());
177187
DisplayFragments.FolderNavigationFragment.dirsOneBackText.setText(folderHistoryOneBackPath);
178188
DisplayFragments.FolderNavigationFragment.dirsTwoBackText.setText(folderHistoryTwoBackPath);
189+
179190
}
180191
else {
181192
Log.i(LOGTAG, "descendIntoNextDirectory: CWD Ctx is NULL!");
182193
}
194+
183195
}
184196

185197
/* Re-initiate the inquisition: Static reusable wrapper function to invoke loading a new directory
@@ -306,7 +318,6 @@ public void onClick(View btnView) {
306318
}
307319

308320
public void cancelAllOperationsInProgress() {
309-
FileChooserActivity.getInstance().stopPrefetchFileUpdatesThread();
310321
FileChooserActivity.getInstance().stopPrefetchFileUpdatesThread();
311322
pathHistoryStack.clear();
312323
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ private static void displayToastMessage(Activity activityInst, String toastMsg,
105105
);
106106
toastDisplay.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 25);
107107
toastDisplay.getView().setPadding(10, 10, 10, 10);
108-
int toastBackgroundColor = getColorVariantFromTheme(R.attr.colorAccent);
109-
int toastTextColor = getColorVariantFromTheme(R.attr.colorPrimaryDark);
108+
int toastBackgroundColor = getColorVariantFromTheme(R.attr.__colorAccent);
109+
int toastTextColor = getColorVariantFromTheme(R.attr.__colorPrimaryDark);
110110
toastDisplay.getView().getBackground().setColorFilter(toastBackgroundColor, PorterDuff.Mode.SRC_IN);
111111
TextView toastTextMsg = toastDisplay.getView().findViewById(android.R.id.message);
112112
if(toastTextMsg != null) {
@@ -134,6 +134,28 @@ public static void displayToastMessageLong(String toastMsg) {
134134
displayToastMessageLong(FileChooserActivity.getInstance(), toastMsg);
135135
}
136136

137+
public static void displayFolderScrollContents(int scrolledToPosSoFar, int maxScrollPos) {
138+
int percentage = (int) scrolledToPosSoFar / maxScrollPos;
139+
Toast toastDisplay = Toast.makeText(
140+
FileChooserActivity.getInstance(),
141+
String.format(Locale.getDefault(), "%d %%", percentage),
142+
Toast.LENGTH_SHORT
143+
);
144+
toastDisplay.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
145+
toastDisplay.getView().setPadding(2, 2, 2, 2);
146+
int toastBackgroundColor = getColorVariantFromTheme(R.attr.__colorPrimaryDark);
147+
int toastTextColor = getColorVariantFromTheme(R.attr.__colorAccentLight);
148+
toastDisplay.getView().getBackground().setColorFilter(toastBackgroundColor, PorterDuff.Mode.SRC_IN);
149+
TextView toastTextMsg = toastDisplay.getView().findViewById(android.R.id.message);
150+
if(toastTextMsg != null) {
151+
toastTextMsg.setTextColor(toastTextColor);
152+
toastTextMsg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8f);
153+
toastTextMsg.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
154+
}
155+
toastDisplay.getView().setAlpha(0.65f);
156+
toastDisplay.show();
157+
}
158+
137159
private static int[] PROGRESS_BAR_VISUAL_MARKERS = new int[] {
138160
R.drawable.progressbar_0,
139161
R.drawable.progressbar_1,

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,20 @@ public void onClick(View btnView) {
196196
getInstance().postSelectedFilesActivityResult(new FileChooserException.CommunicateNoDataException());
197197
}
198198
};
199-
doneActionBtn.setOnClickListener(quitActivityBtnClickListener);
200199
cancelActionBtn.setOnClickListener(quitActivityBtnClickListener);
200+
Button.OnClickListener doneActivityBtnClickListener = new Button.OnClickListener() {
201+
@Override
202+
public void onClick(View btnView) {
203+
getDisplayFragmentsInstance().cancelAllOperationsInProgress();
204+
if(DisplayFragments.getInstance().activeSelectionsList.size() == 0) {
205+
getInstance().postSelectedFilesActivityResult(new FileChooserException.CommunicateNoDataException());
206+
}
207+
else {
208+
getInstance().postSelectedFilesActivityResult();
209+
}
210+
}
211+
};
212+
doneActionBtn.setOnClickListener(doneActivityBtnClickListener);
201213

202214
/*
203215
* Last, there is the global back button and previous directory history display.
@@ -216,6 +228,22 @@ public void onClick(View btnView) {
216228

217229
}
218230

231+
@Override
232+
public void onPause() {
233+
super.onPause();
234+
//if(prefetchFilesUpdaterInst.isAlive()) {
235+
// stopPrefetchFileUpdatesThread();
236+
//}
237+
}
238+
239+
@Override
240+
public void onResume() {
241+
super.onResume();
242+
//if(prefetchFilesUpdaterInst.isInterrupted()) {
243+
// startPrefetchFileUpdatesThread();
244+
//}
245+
}
246+
219247
@Override
220248
public void onNewIntent(Intent broadcastIntent) {
221249
super.onNewIntent(broadcastIntent);
@@ -288,21 +316,16 @@ public void postSelectedFilesActivityResult() {
288316
Intent filesResultIntent = getSelectedFilesActivityResultIntent();
289317
setResult(Activity.RESULT_OK, filesResultIntent);
290318
finish();
291-
//System.exit(0); // ??? TODO ???
292319
}
293320

294321
public void postSelectedFilesActivityResult(Exception runtimeExcpt) {
295322
runtimeExcpt.printStackTrace();
296323
Intent filesResultIntent = getSelectedFilesActivityResultIntent();
297-
if(runtimeExcpt instanceof FileChooserException.AndroidFilePickerLightException) {
298-
FileChooserException.AndroidFilePickerLightException rteLocal = (FileChooserException.AndroidFilePickerLightException) runtimeExcpt;
299-
filesResultIntent.putExtra(FileChooserBuilder.FILE_PICKER_EXCEPTION_MESSAGE_KEY, rteLocal.getMessage());
300-
filesResultIntent.putExtra(FileChooserBuilder.FILE_PICKER_EXCEPTION_CAUSE_KEY, rteLocal.getCauseAsString());
301-
}
324+
FileChooserException.AndroidFilePickerLightException rteLocal = (FileChooserException.AndroidFilePickerLightException) runtimeExcpt;
325+
filesResultIntent.putExtra(FileChooserBuilder.FILE_PICKER_EXCEPTION_MESSAGE_KEY, rteLocal.getMessage());
326+
filesResultIntent.putExtra(FileChooserBuilder.FILE_PICKER_EXCEPTION_CAUSE_KEY, rteLocal.getCauseAsString());
302327
setResult(Activity.RESULT_CANCELED, filesResultIntent);
303328
finish();
304-
//ActivityCompat.finishAffinity(this);
305-
//System.exit(0); // ??? TODO ???
306329
}
307330

308331
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This program (the AndroidFilePickerLight library) is free software written by
3131
import java.util.List;
3232
import java.util.Map;
3333

34+
import static android.app.Activity.RESULT_CANCELED;
3435
import static android.app.Activity.RESULT_OK;
3536

3637
public class FileChooserBuilder implements Serializable {
@@ -422,15 +423,22 @@ public static List<String> handleActivityResult(Activity activityInst, int reque
422423
case ACTIVITY_CODE_SELECT_DIRECTORY_ONLY:
423424
case ACTIVITY_CODE_SELECT_MULTIPLE_FILES:
424425
if(resultCode == RESULT_OK) {
425-
List<String> selectedDataItems = Arrays.asList(data.getStringArrayExtra(FileChooserBuilder.FILE_PICKER_INTENT_DATA_PAYLOAD_KEY));
426+
List<String> selectedDataItems = data.getStringArrayListExtra(FileChooserBuilder.FILE_PICKER_INTENT_DATA_PAYLOAD_KEY);
426427
finishActivityResultHandler(activityInst);
428+
try { // A short pause to give the calling Activity time to resume form at the top of the display:
429+
Thread.sleep(250);
430+
} catch(InterruptedException ie) {}
427431
return selectedDataItems;
428432
}
429-
try {
430-
String getExitErrorMsg = data.getStringExtra(FILE_PICKER_EXCEPTION_MESSAGE_KEY);
431-
finishActivityResultHandler(activityInst);
432-
throw FileChooserException.getExceptionForExitCause(data.getStringExtra(FILE_PICKER_EXCEPTION_CAUSE_KEY), getExitErrorMsg);
433-
} catch(NullPointerException npe) {}
433+
else if(resultCode == RESULT_CANCELED) {
434+
try {
435+
String getExitErrorMsg = data.getStringExtra(FILE_PICKER_EXCEPTION_MESSAGE_KEY);
436+
finishActivityResultHandler(activityInst);
437+
throw FileChooserException.getExceptionForExitCause(data.getStringExtra(FILE_PICKER_EXCEPTION_CAUSE_KEY), getExitErrorMsg);
438+
} catch (NullPointerException npe) {
439+
npe.printStackTrace();
440+
}
441+
}
434442
break;
435443
default:
436444
break;
@@ -450,6 +458,7 @@ public static void finishActivityResultHandler(Activity activityInst) {
450458
Intent bringToFrontIntent = new Intent(activityInst, activityInst.getClass());
451459
bringToFrontIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
452460
activityInst.startActivity(bringToFrontIntent);
461+
//ActivityCompat.finishAffinity(this);
453462
}
454463

455464
public StringBuilder readFileContentsAsString() {

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static <DataTypeT extends Object> List<DataTypeT> recoverDataItemsList(by
6060

6161
}
6262

63-
abstract public static class AndroidFilePickerLightException extends RuntimeException {
63+
public static class AndroidFilePickerLightException extends RuntimeException {
6464

6565
private boolean isError;
6666
private int errorCode;
@@ -81,7 +81,7 @@ public AndroidFilePickerLightException() {
8181
}
8282

8383
protected static AndroidFilePickerLightException getNewInstance() {
84-
return null;
84+
return new AndroidFilePickerLightException();
8585
}
8686

8787
public AndroidFilePickerLightException newExceptionInstance(Exception javaBaseExcpt) {
@@ -104,13 +104,21 @@ public AndroidFilePickerLightException newExceptionInstance(String errorMsg, Exc
104104
}
105105

106106
protected void configureExceptionParams(int errorCode, String baseExcptDesc, boolean defaultIsError,
107-
Object defaultDataTypeT, ExceptionDataFieldFormatter dataFmtObjType) {}
107+
Object defaultDataTypeT, ExceptionDataFieldFormatter dataFmtObjType) {
108+
this.errorCode = errorCode;
109+
this.errorMsg = baseExcptDesc;
110+
this.isError = defaultIsError;
111+
}
112+
113+
@Override
114+
public String getMessage() {
115+
return getErrorMessage();
116+
}
108117

109118
/* Standard-ish Exception class handling and methods: */
110119
public String getExceptionMessage() { return null; }
111120
public String[] getStackTraceAsStringArray() { return null; }
112-
public void printStackTrace() {}
113-
public String toString() { return null; }
121+
public String toString() { return getMessage(); }
114122

115123
/* For uses of communicating other information by exception: */
116124
public boolean isError() { return isError; }
@@ -119,9 +127,9 @@ public void printStackTrace() {}
119127
public String getCauseAsString() { return this.getClass().getName(); }
120128

121129
/* Custom error messages and printing methods: */
122-
public String getExceptionName() { return null; }
130+
public String getExceptionName() { return this.getClass().getName(); }
123131
public String getExceptionBaseDesc() { return null; }
124-
public String getErrorMessage() { return null; }
132+
public String getErrorMessage() { return errorMsg; }
125133
public String getErrorMessageFull() { return null; }
126134
public String getInvokingSourceFile() { return null; }
127135
public int getInvokingLineNumber() { return -1; }
@@ -254,7 +262,7 @@ protected static AndroidFilePickerLightException getNewInstance() {
254262

255263
public CommunicateSelectionDataException() {
256264
configureExceptionParams(UNIQUE_ERROR_CODE,
257-
"Wrapper for exception type to throw to return normal data on success",
265+
"No selections by the user",
258266
false, DEFAULT_DATA_ITEMS_TYPE, null);
259267
}
260268

0 commit comments

Comments
 (0)