@@ -156,6 +156,9 @@ public boolean accept(File fileItem) {
156156 public void run () {
157157 notifyDataSetChanged ();
158158 progressBarDialog .hideDialog ();
159+ if (selectionChangedListener != null ) {
160+ selectionChangedListener .onSelectionChanged (selectedFiles .size ());
161+ }
159162 }
160163 });
161164 }).start ();
@@ -220,6 +223,51 @@ private void toggleSelection(File file) {
220223 }
221224 }
222225
226+ // Một tệp/thư mục có phải là đối tượng "có thể chọn" (hiện checkbox) trong danh sách hiện tại không.
227+ // Ở chế độ chọn thư mục: mọi mục trong fileArray đều là thư mục -> có thể chọn.
228+ // Ở chế độ chọn tệp: chỉ tệp mới có thể chọn, thư mục chỉ dùng để điều hướng.
229+ private boolean isSelectable (File file ) {
230+ return folderChooserMode || !file .isDirectory ();
231+ }
232+
233+ // Thư mục hiện tại đã được chọn hết (mọi mục có thể chọn) hay chưa - dùng để đồng bộ checkbox "Chọn tất cả".
234+ public boolean isAllCurrentDirSelected () {
235+ if (fileArray == null || fileArray .length == 0 ) {
236+ return false ;
237+ }
238+ boolean hasSelectable = false ;
239+ for (File file : fileArray ) {
240+ if (isSelectable (file )) {
241+ hasSelectable = true ;
242+ if (!selectedFiles .contains (file )) {
243+ return false ;
244+ }
245+ }
246+ }
247+ return hasSelectable ;
248+ }
249+
250+ // Chọn/bỏ chọn tất cả các mục có thể chọn trong thư mục đang hiển thị.
251+ public void setSelectAllState (boolean selectAll ) {
252+ if (fileArray == null ) {
253+ return ;
254+ }
255+ for (File file : fileArray ) {
256+ if (!isSelectable (file )) {
257+ continue ;
258+ }
259+ if (selectAll ) {
260+ selectedFiles .add (file );
261+ } else {
262+ selectedFiles .remove (file );
263+ }
264+ }
265+ notifyDataSetChanged ();
266+ if (selectionChangedListener != null ) {
267+ selectionChangedListener .onSelectionChanged (selectedFiles .size ());
268+ }
269+ }
270+
223271 @ Override
224272 public View getView (int position , View convertView , ViewGroup parent ) {
225273 final View view ;
0 commit comments