android list ascending and descending order local file display

private void ascendingSort(List<File> list) {
    Collections.sort (list, new Comparator<File>() {
         @Override
 public int compare(File p1, File p2) {
             // <It is to sort the new files in descending order of time on the top instead>
 if (p1. lastModified()< p2.lastModified()) {
                 return 1 ;                    
            }
            if (p1.lastModified() == p2.lastModified()) {
                return 0;
            }
            return -1;
        }
    });
}

  // Get all mp4 files in the current directory
 public List<String> getVideoFileName() {    
        Vector<String> vecFile = new Vector<String>();
        File file = new File(FINALPATHVIDEO);
        File[] subFile = file.listFiles();
        //Note: local file data source
        ascendingSort(Arrays.asList(subFile));
        if (subFile == null || subFile.length == 0) {
            mLinearViewEmpty.setVisibility(View.VISIBLE);
        } else {
            mLinearViewEmpty.setVisibility(View.GONE);
            if (mListPath == null) {
                mListPath = new ArrayList<>();
            }
            mListPath .clear ();
            for ( int iFileLength = 0 ; iFileLength <subFile. length ; iFileLength ++) {
                 // 判断 是否 为 文件 夹
if (! subFile [iFileLength] .isDirectory ()) {                
                    String filename = subFile[iFileLength].getName();
                    String filenamepath = subFile[iFileLength].getPath();
//                    long filenamepathz = subFile[iFileLength].lastModified();
//                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String result = formatter.format(filenamepathz);
//                    Log.i("asdasd", "" + result + "---" + filenamepathz);
                    // 判断是否为MP4结尾
if (filename.trim().toLowerCase().endsWith(".mp4")) {                    
                        vecFile.add(filename);
                        mListPath.add(filenamepath);
                    }
                }
            }
        }

        return vecFile;
    }



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325598025&siteId=291194637