7
7
import android .graphics .Color ;
8
8
import android .os .Build ;
9
9
import android .os .Bundle ;
10
+ import android .util .Log ;
10
11
import android .view .View ;
11
12
import android .view .Window ;
12
13
import android .widget .AdapterView ;
38
39
@ SuppressWarnings ("unused" )
39
40
public class FilePickerDialog extends Dialog implements AdapterView .OnItemClickListener {
40
41
42
+ private static final String TAG = FilePickerDialog .class .getSimpleName ();
43
+
41
44
private final Context context ;
45
+ private Activity activity ;
42
46
private ListView listView ;
43
47
private TextView dname , dir_path , title ;
44
48
private DialogProperties properties ;
@@ -53,6 +57,7 @@ public class FilePickerDialog extends Dialog implements AdapterView.OnItemClickL
53
57
54
58
public static final int EXTERNAL_READ_PERMISSION_GRANT = 112 ;
55
59
60
+ @ Deprecated
56
61
public FilePickerDialog (Context context ) {
57
62
super (context );
58
63
this .context = context ;
@@ -61,6 +66,16 @@ public FilePickerDialog(Context context) {
61
66
internalList = new ArrayList <>();
62
67
}
63
68
69
+ public FilePickerDialog (Activity activity , Context context ) {
70
+ super (context );
71
+ this .activity = activity ;
72
+ this .context = context ;
73
+ properties = new DialogProperties ();
74
+ filter = new ExtensionFilter (properties );
75
+ internalList = new ArrayList <>();
76
+ }
77
+
78
+ @ Deprecated
64
79
public FilePickerDialog (Context context , DialogProperties properties , int themeResId ) {
65
80
super (context , themeResId );
66
81
this .context = context ;
@@ -69,6 +84,16 @@ public FilePickerDialog(Context context, DialogProperties properties, int themeR
69
84
internalList = new ArrayList <>();
70
85
}
71
86
87
+ public FilePickerDialog (Activity activity , Context context , DialogProperties properties , int themeResId ) {
88
+ super (context , themeResId );
89
+ this .activity = activity ;
90
+ this .context = context ;
91
+ this .properties = properties ;
92
+ filter = new ExtensionFilter (properties );
93
+ internalList = new ArrayList <>();
94
+ }
95
+
96
+ @ Deprecated
72
97
public FilePickerDialog (Context context , DialogProperties properties ) {
73
98
super (context );
74
99
this .context = context ;
@@ -77,6 +102,15 @@ public FilePickerDialog(Context context, DialogProperties properties) {
77
102
internalList = new ArrayList <>();
78
103
}
79
104
105
+ public FilePickerDialog (Activity activity , Context context , DialogProperties properties ) {
106
+ super (context );
107
+ this .activity = activity ;
108
+ this .context = context ;
109
+ this .properties = properties ;
110
+ filter = new ExtensionFilter (properties );
111
+ internalList = new ArrayList <>();
112
+ }
113
+
80
114
@ Override
81
115
protected void onCreate (Bundle savedInstanceState ) {
82
116
super .onCreate (savedInstanceState );
@@ -197,33 +231,50 @@ protected void onStart() {
197
231
positiveBtnNameStr
198
232
);
199
233
select .setText (positiveBtnNameStr );
200
- if (Utility .checkStorageAccessPermissions (context )) {
201
- File currLoc ;
202
- internalList .clear ();
203
- if (properties .offset .isDirectory () && validateOffsetPath ()) {
204
- currLoc = new File (properties .offset .getAbsolutePath ());
205
- FileListItem parent = new FileListItem ();
206
- parent .setFilename (context .getString (R .string .label_parent_dir ));
207
- parent .setDirectory (true );
208
- parent .setLocation (Objects .requireNonNull (currLoc .getParentFile ())
209
- .getAbsolutePath ());
210
- parent .setTime (currLoc .lastModified ());
211
- internalList .add (parent );
212
- } else if (properties .root .exists () && properties .root .isDirectory ()) {
213
- currLoc = new File (properties .root .getAbsolutePath ());
234
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
235
+ if (Utility .checkMediaAccessPermissions (context )) {
236
+ //Permission granted...
237
+ dir ();
214
238
} else {
215
- currLoc = new File (properties .error_dir .getAbsolutePath ());
239
+ //Permissions are not granted...
240
+ Log .d (TAG , "Permissions are not granted" );
241
+ }
242
+ } else {
243
+ if (Utility .checkStorageAccessPermissions (context )) {
244
+ Log .d (TAG , "Permission granted" );
245
+ dir ();
246
+ } else {
247
+ Log .d (TAG , "Permission not granted" );
216
248
}
217
- dname .setText (currLoc .getName ());
218
- dir_path .setText (currLoc .getAbsolutePath ());
219
- setTitle ();
220
- internalList = Utility .prepareFileListEntries (internalList , currLoc , filter ,
221
- properties .show_hidden_files );
222
- mFileListAdapter .notifyDataSetChanged ();
223
- listView .setOnItemClickListener (this );
224
249
}
225
250
}
226
251
252
+ private void dir () {
253
+ File currLoc ;
254
+ internalList .clear ();
255
+ if (properties .offset .isDirectory () && validateOffsetPath ()) {
256
+ currLoc = new File (properties .offset .getAbsolutePath ());
257
+ FileListItem parent = new FileListItem ();
258
+ parent .setFilename (context .getString (R .string .label_parent_dir ));
259
+ parent .setDirectory (true );
260
+ parent .setLocation (Objects .requireNonNull (currLoc .getParentFile ())
261
+ .getAbsolutePath ());
262
+ parent .setTime (currLoc .lastModified ());
263
+ internalList .add (parent );
264
+ } else if (properties .root .exists () && properties .root .isDirectory ()) {
265
+ currLoc = new File (properties .root .getAbsolutePath ());
266
+ } else {
267
+ currLoc = new File (properties .error_dir .getAbsolutePath ());
268
+ }
269
+ dname .setText (currLoc .getName ());
270
+ dir_path .setText (currLoc .getAbsolutePath ());
271
+ setTitle ();
272
+ internalList = Utility .prepareFileListEntries (internalList , currLoc , filter ,
273
+ properties .show_hidden_files );
274
+ mFileListAdapter .notifyDataSetChanged ();
275
+ listView .setOnItemClickListener (this );
276
+ }
277
+
227
278
private boolean validateOffsetPath () {
228
279
String offset_path = properties .offset .getAbsolutePath ();
229
280
String root_path = properties .root .getAbsolutePath ();
@@ -393,24 +444,49 @@ public void markFiles(List<String> paths) {
393
444
394
445
@ Override
395
446
public void show () {
396
- if (!Utility .checkStorageAccessPermissions (context )) {
397
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
398
- ((Activity ) context ).requestPermissions (new String []{Manifest .permission
399
- .READ_EXTERNAL_STORAGE }, EXTERNAL_READ_PERMISSION_GRANT );
447
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
448
+ if (Utility .checkMediaAccessPermissions (context )) {
449
+ //Permission granted...
450
+ super .show ();
451
+ positiveBtnNameStr = positiveBtnNameStr == null ?
452
+ context .getResources ().getString (R .string .choose_button_label ) : positiveBtnNameStr ;
453
+ select .setText (positiveBtnNameStr );
454
+ int size = MarkedItemList .getFileCount ();
455
+ if (size == 0 ) {
456
+ select .setText (positiveBtnNameStr );
457
+ } else {
458
+ String button_label = positiveBtnNameStr + " (" + size + ") " ;
459
+ select .setText (button_label );
460
+ }
461
+ } else {
462
+ //Permissions are not granted...
463
+ Log .d (TAG , "Permissions are not granted" );
400
464
}
401
465
} else {
402
- super .show ();
403
- positiveBtnNameStr = positiveBtnNameStr == null ?
404
- context .getResources ().getString (R .string .choose_button_label ) : positiveBtnNameStr ;
405
- select .setText (positiveBtnNameStr );
406
- int size = MarkedItemList .getFileCount ();
407
- if (size == 0 ) {
408
- select .setText (positiveBtnNameStr );
466
+ if (!Utility .checkStorageAccessPermissions (context )) {
467
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
468
+ ((Activity ) context ).requestPermissions (new String []{Manifest .permission
469
+ .READ_EXTERNAL_STORAGE }, EXTERNAL_READ_PERMISSION_GRANT );
470
+ }
409
471
} else {
410
- String button_label = positiveBtnNameStr + " (" + size + ") " ;
411
- select .setText (button_label );
472
+ super .show ();
473
+ positiveBtnNameStr = positiveBtnNameStr == null ?
474
+ context .getResources ().getString (R .string .choose_button_label ) : positiveBtnNameStr ;
475
+ select .setText (positiveBtnNameStr );
476
+ int size = MarkedItemList .getFileCount ();
477
+ if (size == 0 ) {
478
+ select .setText (positiveBtnNameStr );
479
+ } else {
480
+ String button_label = positiveBtnNameStr + " (" + size + ") " ;
481
+ select .setText (button_label );
482
+ }
412
483
}
413
484
}
485
+ if (!Utility .checkStorageAccessPermissions (context )) {
486
+
487
+ } else {
488
+
489
+ }
414
490
}
415
491
416
492
@ Override
0 commit comments