use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.
the class ZipHelperTask method addElements.
@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
try {
ArrayList<CompressedObjectParcelable> wholelist = new ArrayList<>();
if (new File(fileLocation.getPath()).canRead()) {
ZipFile zipfile = new ZipFile(fileLocation.getPath());
for (Enumeration e = zipfile.entries(); e.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) e.nextElement();
wholelist.add(new CompressedObjectParcelable(entry.getName(), entry.getTime(), entry.getSize(), entry.isDirectory()));
}
} else {
ZipInputStream zipfile1 = new ZipInputStream(context.get().getContentResolver().openInputStream(fileLocation));
for (ZipEntry entry = zipfile1.getNextEntry(); entry != null; entry = zipfile1.getNextEntry()) {
wholelist.add(new CompressedObjectParcelable(entry.getName(), entry.getTime(), entry.getSize(), entry.isDirectory()));
}
}
ArrayList<String> strings = new ArrayList<>();
for (CompressedObjectParcelable entry : wholelist) {
File file = new File(entry.name);
if (relativeDirectory == null || relativeDirectory.trim().length() == 0) {
String y = entry.name;
if (y.startsWith("/"))
y = y.substring(1, y.length());
if (file.getParent() == null || file.getParent().length() == 0 || file.getParent().equals("/")) {
if (!strings.contains(y)) {
elements.add(new CompressedObjectParcelable(y, entry.date, entry.size, entry.directory));
strings.add(y);
}
} else {
String path = y.substring(0, y.indexOf("/") + 1);
if (!strings.contains(path)) {
CompressedObjectParcelable zipObj = new CompressedObjectParcelable(path, entry.date, entry.size, true);
strings.add(path);
elements.add(zipObj);
}
}
} else {
String y = entry.name;
if (entry.name.startsWith("/"))
y = y.substring(1, y.length());
if (file.getParent() != null && (file.getParent().equals(relativeDirectory) || file.getParent().equals("/" + relativeDirectory))) {
if (!strings.contains(y)) {
elements.add(new CompressedObjectParcelable(y, entry.date, entry.size, entry.directory));
strings.add(y);
}
} else {
if (y.startsWith(relativeDirectory + "/") && y.length() > relativeDirectory.length() + 1) {
String path1 = y.substring(relativeDirectory.length() + 1, y.length());
int index = relativeDirectory.length() + 1 + path1.indexOf("/");
String path = y.substring(0, index + 1);
if (!strings.contains(path)) {
CompressedObjectParcelable zipObj = new CompressedObjectParcelable(y.substring(0, index + 1), entry.date, entry.size, true);
strings.add(path);
elements.add(zipObj);
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations