77import android .graphics .Color ;
88import android .os .Build ;
99import android .os .Bundle ;
10+ import android .util .Log ;
1011import android .view .View ;
1112import android .view .Window ;
1213import android .widget .AdapterView ;
3839@ SuppressWarnings ("unused" )
3940public class FilePickerDialog extends Dialog implements AdapterView .OnItemClickListener {
4041
42+ private static final String TAG = FilePickerDialog .class .getSimpleName ();
43+
4144 private final Context context ;
45+ private Activity activity ;
4246 private ListView listView ;
4347 private TextView dname , dir_path , title ;
4448 private DialogProperties properties ;
@@ -53,6 +57,7 @@ public class FilePickerDialog extends Dialog implements AdapterView.OnItemClickL
5357
5458 public static final int EXTERNAL_READ_PERMISSION_GRANT = 112 ;
5559
60+ @ Deprecated
5661 public FilePickerDialog (Context context ) {
5762 super (context );
5863 this .context = context ;
@@ -61,6 +66,16 @@ public FilePickerDialog(Context context) {
6166 internalList = new ArrayList <>();
6267 }
6368
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
6479 public FilePickerDialog (Context context , DialogProperties properties , int themeResId ) {
6580 super (context , themeResId );
6681 this .context = context ;
@@ -69,6 +84,16 @@ public FilePickerDialog(Context context, DialogProperties properties, int themeR
6984 internalList = new ArrayList <>();
7085 }
7186
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
7297 public FilePickerDialog (Context context , DialogProperties properties ) {
7398 super (context );
7499 this .context = context ;
@@ -77,6 +102,15 @@ public FilePickerDialog(Context context, DialogProperties properties) {
77102 internalList = new ArrayList <>();
78103 }
79104
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+
80114 @ Override
81115 protected void onCreate (Bundle savedInstanceState ) {
82116 super .onCreate (savedInstanceState );
@@ -197,33 +231,50 @@ protected void onStart() {
197231 positiveBtnNameStr
198232 );
199233 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 ();
214238 } 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" );
216248 }
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 );
224249 }
225250 }
226251
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+
227278 private boolean validateOffsetPath () {
228279 String offset_path = properties .offset .getAbsolutePath ();
229280 String root_path = properties .root .getAbsolutePath ();
@@ -393,24 +444,49 @@ public void markFiles(List<String> paths) {
393444
394445 @ Override
395446 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" );
400464 }
401465 } 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+ }
409471 } 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+ }
412483 }
413484 }
485+ if (!Utility .checkStorageAccessPermissions (context )) {
486+
487+ } else {
488+
489+ }
414490 }
415491
416492 @ Override
0 commit comments