1818
1919import android .os .Parcel ;
2020import android .os .Parcelable ;
21- import androidx .annotation .Nullable ;
2221
2322import com .jaiselrahman .filepicker .model .MediaFile ;
2423
2524import java .util .ArrayList ;
25+ import java .util .regex .Matcher ;
26+ import java .util .regex .Pattern ;
27+
28+ import androidx .annotation .Nullable ;
2629
2730public class Configurations implements Parcelable {
2831 public static final Creator <Configurations > CREATOR = new Creator <Configurations >() {
@@ -51,7 +54,7 @@ public Configurations[] newArray(int size) {
5154 private final String rootPath ;
5255 private final String [] suffixes ;
5356 private final ArrayList <MediaFile > selectedMediaFiles ;
54- private final String [] ignorePaths ;
57+ private Matcher [] ignorePathMatchers ;
5558 private final boolean ignoreNoMedia ;
5659 private final boolean ignoreHiddenFile ;
5760
@@ -73,7 +76,7 @@ private Configurations(Builder builder) {
7376 this .rootPath = builder .rootPath ;
7477 this .suffixes = builder .suffixes ;
7578 this .selectedMediaFiles = builder .selectedMediaFiles ;
76- this . ignorePaths = builder .ignorePaths ;
79+ setIgnorePathMatchers ( builder .ignorePaths ) ;
7780 this .ignoreNoMedia = builder .ignoreNoMedia ;
7881 this .ignoreHiddenFile = builder .ignoreHiddenFile ;
7982 }
@@ -96,7 +99,7 @@ protected Configurations(Parcel in) {
9699 rootPath = in .readString ();
97100 suffixes = in .createStringArray ();
98101 selectedMediaFiles = in .createTypedArrayList (MediaFile .CREATOR );
99- ignorePaths = in .createStringArray ();
102+ setIgnorePathMatchers ( in .createStringArray () );
100103 ignoreNoMedia = in .readByte () != 0 ;
101104 ignoreHiddenFile = in .readByte () != 0 ;
102105 }
@@ -144,7 +147,7 @@ public void writeToParcel(Parcel dest, int flags) {
144147 dest .writeString (rootPath );
145148 dest .writeStringArray (suffixes );
146149 dest .writeTypedList (selectedMediaFiles );
147- dest .writeStringArray (ignorePaths );
150+ dest .writeStringArray (getIgnorePaths () );
148151 dest .writeByte ((byte ) (ignoreNoMedia ? 1 : 0 ));
149152 dest .writeByte ((byte ) (ignoreHiddenFile ? 1 : 0 ));
150153 }
@@ -198,8 +201,8 @@ public String[] getSuffixes() {
198201 return suffixes ;
199202 }
200203
201- public String [] getIgnorePaths () {
202- return ignorePaths ;
204+ public Matcher [] getIgnorePathMatchers () {
205+ return ignorePathMatchers ;
203206 }
204207
205208 public boolean isIgnoreNoMediaDir () {
@@ -210,6 +213,27 @@ public boolean isIgnoreHiddenFile() {
210213 return ignoreHiddenFile ;
211214 }
212215
216+ private void setIgnorePathMatchers (String ignorePaths []) {
217+ if (ignorePaths != null && ignorePaths .length > 0 ) {
218+ ignorePathMatchers = new Matcher [ignorePaths .length ];
219+ for (int i = 0 ; i < ignorePaths .length ; i ++) {
220+ ignorePathMatchers [i ] = Pattern .compile (ignorePaths [i ]).matcher ("" );
221+ }
222+ }
223+ }
224+
225+ @ Nullable
226+ private String [] getIgnorePaths () {
227+ if (ignorePathMatchers != null && ignorePathMatchers .length > 0 ) {
228+ String ignorePaths [] = new String [ignorePathMatchers .length ];
229+ for (int i = 0 ; i < ignorePaths .length ; i ++) {
230+ ignorePaths [i ] = ignorePathMatchers [i ].pattern ().pattern ();
231+ }
232+ return ignorePaths ;
233+ }
234+ return null ;
235+ }
236+
213237 public static class Builder {
214238 private boolean imageCapture = false , videoCapture = false ,
215239 checkPermission = false , showImages = true , showVideos = true ,
0 commit comments