Skip to content
This repository was archived by the owner on Mar 18, 2023. It is now read-only.

Commit ea5699d

Browse files
committed
Fixing back button bug and permissions errors
1 parent 3027550 commit ea5699d

File tree

9 files changed

+37
-10
lines changed

9 files changed

+37
-10
lines changed

AndroidFilePickerLightLibrary/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
defaultConfig {
3131
minSdkVersion 29
3232
targetSdkVersion 30
33-
versionCode 13
34-
versionName "1.1.2"
33+
versionCode 14
34+
versionName "1.1.3"
3535
}
3636

3737
compileOptions {

AndroidFilePickerLightLibrary/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />
2323
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:required="true" />
24-
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" android:required="false" />
24+
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" android:required="true" />
25+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" android:required="true" />
2526
<uses-permission android:name="android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION" android:required="false" />
2627
<uses-permission android:name="android.permission.INTERNET" android:required="false" />
2728

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,12 @@ public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
452452
int lastFileIndex = startFileIndex + getFilesListLength();
453453
if(lastFileIndex >= docsQueryFilesList.length) {
454454
lastFileIndex = docsQueryFilesList.length - 1;
455-
startFileIndex = Math.max(0, lastFileIndex - getFilesListLength());
455+
startFileIndex = Math.max(0, lastFileIndex + 1 - getFilesListLength());
456456
}
457457
int curFileIndex = 0;
458458
for(File file : docsQueryFilesList) {
459-
if(curFileIndex++ < startFileIndex) {
459+
if(curFileIndex < startFileIndex) {
460+
curFileIndex++;
460461
continue;
461462
}
462463
else if(curFileIndex > lastFileIndex) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void computeDirectoryContents(int startIndexPos, int maxIndexPos,
106106
return;
107107
}
108108
if(newItemsCount > 0) {
109-
fpInst.setFilesStartIndex(maxIndexPos + 1 - Math.abs(newItemsCount));
109+
fpInst.setFilesStartIndex(Math.max(0, maxIndexPos + 1 - Math.abs(newItemsCount)));
110110
fpInst.setFilesListLength(Math.abs(newItemsCount));
111111
Log.d(LOGTAG, "REQUESTING start index = " + (maxIndexPos + 1 - Math.abs(newItemsCount)) + ", LEN = " + Math.abs(newItemsCount));
112112
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,13 @@ public void onNewIntent(Intent broadcastIntent) {
325325
public static final String[] ACTIVITY_REQUIRED_PERMISSIONS = {
326326
"android.permission.READ_EXTERNAL_STORAGE",
327327
"android.permission.WRITE_EXTERNAL_STORAGE",
328+
"android.permission.ACCESS_MEDIA_LOCATION",
328329
};
329330

330331
public static final String[] ACTIVITY_OPTIONAL_PERMISSIONS = {
331-
"android.permission.MANAGE_EXTERNAL_STORAGE",
332+
"android.permission.INTERNET",
332333
"android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION",
333-
"android.permission.INTERNET"
334+
"android.permission.MANAGE_EXTERNAL_STORAGE",
334335
};
335336

336337
@Override
@@ -403,4 +404,7 @@ public void postSelectedFilesActivityResult(Exception runtimeExcpt) {
403404
finish();
404405
}
405406

407+
@Override
408+
public void onBackPressed() {}
409+
406410
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ public void launchFilePicker() throws FileChooserException.AndroidFilePickerLigh
471471
Intent launchPickerIntent = new Intent(activityContextRef.get().getApplicationContext(), FileChooserActivity.class);
472472
launchPickerIntent.setAction(Intent.ACTION_PICK_ACTIVITY);
473473
launchPickerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
474+
launchPickerIntent.setType("*/*");
474475
activityContextRef.get().startActivityForResult(launchPickerIntent, activityActionCode);
475476
}
476477

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This program (the AndroidFilePickerLight library) is free software written by
2222

2323
import androidx.core.content.ContextCompat;
2424

25+
import pub.devrel.easypermissions.EasyPermissions;
26+
import pub.devrel.easypermissions.PermissionRequest;
27+
2528
public class PermissionsHandler {
2629

2730
protected static boolean hasAccessPermission(Activity activityCtx, String permName) {
@@ -34,11 +37,18 @@ protected static boolean hasAccessPermission(Activity activityCtx, String permNa
3437
public static boolean obtainRequiredPermissions(Activity activityCtx, String[] permsList) {
3538
if(android.os.Build.VERSION.SDK_INT >= 23) {
3639
activityCtx.requestPermissions(permsList, REQUEST_REQUIRED_PERMISSIONS_CODE);
40+
EasyPermissions.requestPermissions(
41+
new PermissionRequest.Builder(activityCtx, REQUEST_REQUIRED_PERMISSIONS_CODE, permsList)
42+
.setRationale(R.string.grantPermsDialogRationaleText)
43+
.setPositiveButtonText(R.string.grantPermsDialogOkBtnText)
44+
.setNegativeButtonText(R.string.grantPermsDialogCancelBtnText)
45+
.setTheme(R.style.LibraryDefaultTheme)
46+
.build());
3747
}
3848
for(int pidx = 0; pidx < permsList.length; pidx++) {
3949
if(!hasAccessPermission(activityCtx, permsList[pidx])) {
40-
//throw new FileChooserException.PermissionsErrorException();
41-
return false;
50+
throw new FileChooserException.PermissionsErrorException();
51+
//return false;
4252
}
4353
}
4454
return true;

AndroidFilePickerLightLibrary/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@
3636
<string name="filePickerDoneActionButtonText">Done</string>
3737
<string name="filePickerCancelActionButtonText">Cancel</string>
3838

39+
<string name="grantPermsDialogOkBtnText">Grant Permissions</string>
40+
<string name="grantPermsDialogCancelBtnText">Deny Permissions</string>
41+
<string name="grantPermsDialogRationaleText">
42+
We require several file storage permissions to list and access the local device file system,
43+
e.g., to choose a file or directory path to load. You will not be able to select files with
44+
this application unless these permissions are granted.
45+
</string>
46+
3947
</resources>

AndroidFilePickerLightLibrary/src/main/res/xml/file_provider_paths_base.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<external-files name="/storage/self/primary" path="."/>
3333
<external-files name="Download" path="Download/" />
34+
<external-files name="Downloads" path="Downloads/" />
3435
<external-files name="Movies" path="./Movies/" />
3536
<external-files name="Music" path="./Music" />
3637
<external-files name="Pictures" path="./Pictures/" />
@@ -40,6 +41,7 @@
4041

4142
<external-files-path name="/storage/self/primary" path="."/>
4243
<external-files-path name="Download" path="Download/" />
44+
<external-files-path name="Downloads" path="Downloads/" />
4345
<external-files-path name="Movies" path="Movies/" />
4446
<external-files-path name="Music" path="Music" />
4547
<external-files-path name="Pictures" path="Pictures/" />

0 commit comments

Comments
 (0)