@@ -86,7 +86,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8686 });
8787
8888 mRecycleViewAdapter .setOnItemClickListener ((position , v ) -> {
89- if (isDirectory (mData .get (position ))) {
89+ if (new File (mData .get (position )). isDirectory ( )) {
9090 mPath = mData .get (position );
9191 reload ();
9292 } else {
@@ -120,8 +120,8 @@ private int getSpanCount(Activity activity) {
120120 }
121121
122122 private File [] getFilesList () {
123- if (!mPath .endsWith ("/" )) {
124- mPath = mPath + "/" ;
123+ if (!mPath .endsWith (File . separator )) {
124+ mPath = mPath + File . separator ;
125125 }
126126 if (!new File (mPath ).exists ()) {
127127 mPath = Environment .getExternalStorageDirectory ().toString ();
@@ -131,32 +131,25 @@ private File[] getFilesList() {
131131
132132 private List <String > getData () {
133133 try {
134+ mData .clear ();
134135 // Add directories
135136 for (File mFile : getFilesList ()) {
136- if (isDirectory ( mPath + mFile .getName () )) {
137- mData .add (mPath + mFile .getName ());
137+ if (mFile .isDirectory ( )) {
138+ mData .add (mFile .getAbsolutePath ());
138139 }
139140 }
140141 // Add files
141142 for (File mFile : getFilesList ()) {
142- if (isFile ( mPath + mFile .getName () )) {
143- mData .add (mPath + mFile .getName ());
143+ if (mFile .isFile ( )) {
144+ mData .add (mFile .getAbsolutePath ());
144145 }
145146 }
146- } catch (RuntimeException e ) {
147- Utils .snackbar (findViewById (android .R .id .content ), e . getMessage ( ));
147+ } catch (NullPointerException ignored ) {
148+ Utils .snackbar (findViewById (android .R .id .content ), getString ( R . string . file_picker_failed_message ));
148149 }
149150 return mData ;
150151 }
151152
152- private static boolean isDirectory (String path ) {
153- return new File (path ).isDirectory ();
154- }
155-
156- private static boolean isFile (String path ) {
157- return new File (path ).isFile ();
158- }
159-
160153 private static String getSize (File file ) {
161154 long size = file .length () / 1024 ;
162155 String timeCreated = DateFormat .getDateTimeInstance ().format (System .currentTimeMillis ());
@@ -240,9 +233,10 @@ public RecycleViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int vi
240233 @ SuppressLint ("UseCompatLoadingForDrawables" )
241234 @ Override
242235 public void onBindViewHolder (@ NonNull RecycleViewAdapter .ViewHolder holder , int position ) {
243- if (isDirectory (this .data .get (position ))) {
236+ if (new File (this .data .get (position )). isDirectory ( )) {
244237 holder .mIcon .setImageDrawable (holder .mTitle .getContext ().getResources ().getDrawable (R .drawable .ic_folder ));
245238 holder .mIcon .setColorFilter (Utils .getThemeAccentColor (holder .mTitle .getContext ()));
239+ holder .mDescription .setVisibility (View .GONE );
246240 } else {
247241 if (Utils .getExtension (this .data .get (position )).equals ("sh" )) {
248242 holder .mDescription .setVisibility (View .VISIBLE );
0 commit comments