1818
1919import com .developer .filepicker .R ;
2020import com .developer .filepicker .controller .DialogSelectionListener ;
21- import com .developer .filepicker .controller .NotifyItemChecked ;
2221import com .developer .filepicker .controller .adapters .FileListAdapter ;
2322import com .developer .filepicker .model .DialogConfigs ;
2423import com .developer .filepicker .model .DialogProperties ;
3635/**
3736 * @author akshay sunil masram
3837 */
39- @ SuppressWarnings ("unused" )
4038public class FilePickerDialog extends Dialog implements AdapterView .OnItemClickListener {
41-
4239 private static final String TAG = FilePickerDialog .class .getSimpleName ();
43-
4440 private final Context context ;
4541 private Activity activity ;
4642 private ListView listView ;
@@ -57,7 +53,6 @@ public class FilePickerDialog extends Dialog implements AdapterView.OnItemClickL
5753
5854 public static final int EXTERNAL_READ_PERMISSION_GRANT = 112 ;
5955
60- @ Deprecated
6156 public FilePickerDialog (Context context ) {
6257 super (context );
6358 this .context = context ;
@@ -66,6 +61,7 @@ public FilePickerDialog(Context context) {
6661 internalList = new ArrayList <>();
6762 }
6863
64+ @ Deprecated
6965 public FilePickerDialog (Activity activity , Context context ) {
7066 super (context );
7167 this .activity = activity ;
@@ -75,7 +71,6 @@ public FilePickerDialog(Activity activity, Context context) {
7571 internalList = new ArrayList <>();
7672 }
7773
78- @ Deprecated
7974 public FilePickerDialog (Context context , DialogProperties properties , int themeResId ) {
8075 super (context , themeResId );
8176 this .context = context ;
@@ -84,6 +79,7 @@ public FilePickerDialog(Context context, DialogProperties properties, int themeR
8479 internalList = new ArrayList <>();
8580 }
8681
82+ @ Deprecated
8783 public FilePickerDialog (Activity activity , Context context , DialogProperties properties , int themeResId ) {
8884 super (context , themeResId );
8985 this .activity = activity ;
@@ -93,7 +89,6 @@ public FilePickerDialog(Activity activity, Context context, DialogProperties pro
9389 internalList = new ArrayList <>();
9490 }
9591
96- @ Deprecated
9792 public FilePickerDialog (Context context , DialogProperties properties ) {
9893 super (context );
9994 this .context = context ;
@@ -102,6 +97,7 @@ public FilePickerDialog(Context context, DialogProperties properties) {
10297 internalList = new ArrayList <>();
10398 }
10499
100+ @ Deprecated
105101 public FilePickerDialog (Activity activity , Context context , DialogProperties properties ) {
106102 super (context );
107103 this .activity = activity ;
@@ -138,60 +134,49 @@ protected void onCreate(Bundle savedInstanceState) {
138134 if (negativeBtnNameStr != null ) {
139135 cancel .setText (negativeBtnNameStr );
140136 }
141- select .setOnClickListener (new View .OnClickListener () {
142- @ Override
143- public void onClick (View view ) {
144- String [] paths = MarkedItemList .getSelectedPaths ();
145- if (callbacks != null ) {
146- callbacks .onSelectedFilePaths (paths );
147- }
148- dismiss ();
149- }
150- });
151- cancel .setOnClickListener (new View .OnClickListener () {
152- @ Override
153- public void onClick (View view ) {
154- cancel ();
137+ select .setOnClickListener (view -> {
138+ String [] paths = MarkedItemList .getSelectedPaths ();
139+ if (callbacks != null ) {
140+ callbacks .onSelectedFilePaths (paths );
155141 }
142+ dismiss ();
156143 });
144+ cancel .setOnClickListener (view -> cancel ());
157145 mFileListAdapter = new FileListAdapter (internalList , context , properties );
158- mFileListAdapter .setNotifyItemCheckedListener (new NotifyItemChecked () {
159- @ Override
160- public void notifyCheckBoxIsClicked () {
161- positiveBtnNameStr = positiveBtnNameStr == null ?
162- context .getResources ().getString (R .string .choose_button_label ) : positiveBtnNameStr ;
163- int size = MarkedItemList .getFileCount ();
164- if (size == 0 ) {
165- select .setEnabled (false );
166- int color ;
167- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .M ) {
168- color = context .getResources ().getColor (R .color .colorAccent ,
169- context .getTheme ());
170- } else {
171- color = context .getResources ().getColor (R .color .colorAccent );
172- }
173- select .setTextColor (Color .argb (128 , Color .red (color ), Color .green (color ),
174- Color .blue (color )));
175- select .setText (positiveBtnNameStr );
146+ mFileListAdapter .setNotifyItemCheckedListener (() -> {
147+ positiveBtnNameStr = positiveBtnNameStr == null ?
148+ context .getResources ().getString (R .string .choose_button_label ) : positiveBtnNameStr ;
149+ int size1 = MarkedItemList .getFileCount ();
150+ if (size1 == 0 ) {
151+ select .setEnabled (false );
152+ int color ;
153+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
154+ color = context .getResources ().getColor (R .color .colorAccent ,
155+ context .getTheme ());
176156 } else {
177- select .setEnabled (true );
178- int color ;
179- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .M ) {
180- color = context .getResources ().getColor (R .color .colorAccent ,
181- context .getTheme ());
182- } else {
183- color = context .getResources ().getColor (R .color .colorAccent );
184- }
185- select .setTextColor (color );
186- String button_label = positiveBtnNameStr + " (" + size + ") " ;
187- select .setText (button_label );
157+ color = context .getResources ().getColor (R .color .colorAccent );
188158 }
189- if (properties .selection_mode == DialogConfigs .SINGLE_MODE ) {
190- /* If a single file has to be selected, clear the previously checked
191- * checkbox from the list.
192- */
193- mFileListAdapter .notifyDataSetChanged ();
159+ select .setTextColor (Color .argb (128 , Color .red (color ), Color .green (color ),
160+ Color .blue (color )));
161+ select .setText (positiveBtnNameStr );
162+ } else {
163+ select .setEnabled (true );
164+ int color ;
165+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
166+ color = context .getResources ().getColor (R .color .colorAccent ,
167+ context .getTheme ());
168+ } else {
169+ color = context .getResources ().getColor (R .color .colorAccent );
194170 }
171+ select .setTextColor (color );
172+ String button_label = positiveBtnNameStr + " (" + size1 + ") " ;
173+ select .setText (button_label );
174+ }
175+ if (properties .selection_mode == DialogConfigs .SINGLE_MODE ) {
176+ /* If a single file has to be selected, clear the previously checked
177+ * checkbox from the list.
178+ */
179+ mFileListAdapter .notifyDataSetChanged ();
195180 }
196181 });
197182 listView .setAdapter (mFileListAdapter );
@@ -234,17 +219,18 @@ protected void onStart() {
234219 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
235220 if (Utility .checkMediaAccessPermissions (context )) {
236221 //Permission granted...
222+ Log .d (TAG , "Permission granted" );
237223 dir ();
238224 } else {
239225 //Permissions are not granted...
240- Log .d (TAG , "Permissions are not granted" );
226+ Log .d (TAG , "Permissions are not granted. You need to ask permission to user before accessing the storage and showing dialog. " );
241227 }
242228 } else {
243229 if (Utility .checkStorageAccessPermissions (context )) {
244230 Log .d (TAG , "Permission granted" );
245231 dir ();
246232 } else {
247- Log .d (TAG , "Permission not granted" );
233+ Log .d (TAG , "Permission not granted. You need to ask permission to user before accessing the storage and showing dialog. " );
248234 }
249235 }
250236 }
0 commit comments