public static List<FileItem> filterItems(List<FileItem> list, Context context) { List<FileItem> result = new ArrayList<FileItem>(); FileExploreHistoryManager fileExploreHistoryManager = new FileExploreHistoryManager(context); DeviceItem deviceItem = new DeviceItem(); deviceItem.setType(DeviceItem.DeviceType.XL_ROUTER_TDDOWNLOAD); if (list != null) { for (FileItem fileItem : list) { fileItem.isNew = fileExploreHistoryManager.isFileNew(fileItem, deviceItem); if (fileItem.category == FileCategory.VIDEO) { result.add(fileItem); } if (fileItem.category == FileCategory.DIR) { AppConfig.logRemote("router file.getpaht is: " + fileItem.filePath); List<FileItem> childrens = getChildFiles(fileItem.filePath + File.separator, context); if (childrens != null && childrens.size() > 0) { for (int i = 0; i < childrens.size(); i++) { FileItem childItem = childrens.get(i); if (childItem.category == FileCategory.VIDEO || childItem.category == FileCategory.DIR) { result.add(fileItem); break; } } } } } } AppConfig.logRemote("router tddownload after filter : " + result.size()); return result; }
public static List<FileItem> getChildFiles(String smbPath, Context context) { try { List<FileItem> list = new ArrayList<FileItem>(); SmbFile smbRootFile = new SmbFile(smbPath); if (!smbRootFile.exists()) { return null; } SmbFile[] fileList = smbRootFile.listFiles(); if (fileList == null || fileList.length == 0) { return null; } FileExploreHistoryManager fileExploreHistoryManager = new FileExploreHistoryManager(context); DeviceItem deviceItem = new DeviceItem(); deviceItem.setType(DeviceItem.DeviceType.XL_ROUTER_TDDOWNLOAD); for (SmbFile smbFile : fileList) { FileItem item = new FileItem(); String fileName = smbFile.getName(); String filePath = smbFile.getCanonicalPath(); item.filePath = filePath; item.lastModifyTime = smbFile.getLastModified(); item.canRead = smbFile.canRead(); item.canWrite = smbFile.canWrite(); try { BufferedInputStream bis = new BufferedInputStream(new SmbFileInputStream(smbFile)); String cid = CidUtil.queryCid(bis, smbFile.length()); if (!TextUtils.isEmpty(cid)) { item.cid = cid; } else { item.cid = ""; } } catch (SmbException e) { } catch (MalformedURLException e) { } catch (UnknownHostException e) { } if (smbFile.isDirectory()) { fileName = fileName.substring(0, fileName.length() - 1); item.fileName = fileName; item.category = FileCategory.DIR; item.fileSize = 0; item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem); list.add(item); } else if (smbFile.isFile()) { item.category = FileCategoryHelper.getFileCategoryByName(fileName); item.fileSize = smbFile.getContentLength(); item.fileName = fileName; if (item.category == FileCategory.VIDEO) { item.isNew = fileExploreHistoryManager.isFileNew(item, deviceItem); list.add(item); } } } return list; } catch (MalformedURLException e) { AppConfig.logRemote( "[[XlrounterDownloadMgr]] createFileItem MalformedURLException:" + e.getMessage()); } catch (SmbException e) { AppConfig.logRemote("[[XlrounterDownloadMgr]] createFileItem SmbException:" + e.getMessage()); } return null; }