Search in sources :

Example 1 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class CompressedExplorerFragment method createViews.

private void createViews(ArrayList<CompressedObjectParcelable> items, String dir) {
    if (compressedExplorerAdapter == null) {
        compressedExplorerAdapter = new CompressedExplorerAdapter(getActivity(), utilsProvider, items, this, decompressor);
        listView.setAdapter(compressedExplorerAdapter);
    } else {
        compressedExplorerAdapter.generateZip(items);
    }
    folder = 0;
    file = 0;
    for (CompressedObjectParcelable item : items) {
        if (item.type == CompressedObjectParcelable.TYPE_GOBACK)
            continue;
        if (item.directory)
            folder++;
        else
            file++;
    }
    stopAnims = true;
    if (!addheader) {
        listView.removeItemDecoration(dividerItemDecoration);
        // listView.removeItemDecoration(headersDecor);
        addheader = true;
    } else {
        dividerItemDecoration = new DividerItemDecoration(getActivity(), true, showDividers);
        listView.addItemDecoration(dividerItemDecoration);
        // headersDecor = new StickyRecyclerHeadersDecoration(compressedExplorerAdapter);
        // listView.addItemDecoration(headersDecor);
        addheader = false;
    }
    final FastScroller fastScroller = (FastScroller) rootView.findViewById(R.id.fastscroll);
    fastScroller.setRecyclerView(listView, 1);
    fastScroller.setPressedHandleColor(mainActivity.getColorPreference().getColor(ColorUsage.ACCENT));
    ((AppBarLayout) mToolbarContainer).addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
        fastScroller.updateHandlePosition(verticalOffset, 112);
    });
    listView.stopScroll();
    relativeDirectory = dir;
    updateBottomBar();
    swipeRefreshLayout.setRefreshing(false);
}
Also used : CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) FastScroller(com.amaze.filemanager.ui.views.FastScroller) AppBarLayout(android.support.design.widget.AppBarLayout) DividerItemDecoration(com.amaze.filemanager.ui.views.DividerItemDecoration) CompressedExplorerAdapter(com.amaze.filemanager.adapters.CompressedExplorerAdapter)

Example 2 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class GzipHelperTask method addElements.

@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
    TarArchiveInputStream tarInputStream = null;
    try {
        tarInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(filePath)));
        TarArchiveEntry entry;
        while ((entry = tarInputStream.getNextTarEntry()) != null) {
            String name = entry.getName();
            if (name.endsWith(SEPARATOR))
                name = name.substring(0, name.length() - 1);
            boolean isInBaseDir = relativePath.equals("") && !name.contains(SEPARATOR);
            boolean isInRelativeDir = name.contains(SEPARATOR) && name.substring(0, name.lastIndexOf(SEPARATOR)).equals(relativePath);
            if (isInBaseDir || isInRelativeDir) {
                elements.add(new CompressedObjectParcelable(entry.getName(), entry.getLastModifiedDate().getTime(), entry.getSize(), entry.isDirectory()));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 3 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class TarHelperTask method addElements.

@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
    TarArchiveInputStream tarInputStream = null;
    try {
        tarInputStream = new TarArchiveInputStream(new FileInputStream(filePath));
        TarArchiveEntry entry;
        while ((entry = tarInputStream.getNextTarEntry()) != null) {
            String name = entry.getName();
            if (name.endsWith(SEPARATOR))
                name = name.substring(0, name.length() - 1);
            boolean isInBaseDir = relativePath.equals("") && !name.contains(SEPARATOR);
            boolean isInRelativeDir = name.contains(SEPARATOR) && name.substring(0, name.lastIndexOf(SEPARATOR)).equals(relativePath);
            if (isInBaseDir || isInRelativeDir) {
                elements.add(new CompressedObjectParcelable(entry.getName(), entry.getLastModifiedDate().getTime(), entry.getSize(), entry.isDirectory()));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 4 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class CompressedExplorerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final CompressedItemViewHolder holder, int position) {
    if (!stoppedAnimation) {
        animate(holder);
    }
    final CompressedObjectParcelable rowItem = items.get(position);
    GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        holder.checkImageView.setBackground(new CircleGradientDrawable(compressedExplorerFragment.accentColor, utilsProvider.getAppTheme(), compressedExplorerFragment.getResources().getDisplayMetrics()));
    } else
        holder.checkImageView.setBackgroundDrawable(new CircleGradientDrawable(compressedExplorerFragment.accentColor, utilsProvider.getAppTheme(), compressedExplorerFragment.getResources().getDisplayMetrics()));
    if (rowItem.type == CompressedObjectParcelable.TYPE_GOBACK) {
        GlideApp.with(compressedExplorerFragment).load(R.drawable.ic_arrow_left_white_24dp).into(holder.genericIcon);
        gradientDrawable.setColor(Utils.getColor(context, R.color.goback_item));
        holder.txtTitle.setText("..");
        holder.txtDesc.setText("");
        holder.date.setText(R.string.goback);
    } else {
        GlideApp.with(compressedExplorerFragment).load(rowItem.iconData.image).into(holder.genericIcon);
        final StringBuilder stringBuilder = new StringBuilder(rowItem.name);
        if (compressedExplorerFragment.showLastModified)
            holder.date.setText(Utils.getDate(rowItem.date, compressedExplorerFragment.year));
        if (rowItem.directory) {
            holder.genericIcon.setImageDrawable(folder);
            gradientDrawable.setColor(Color.parseColor(compressedExplorerFragment.iconskin));
            if (stringBuilder.toString().length() > 0) {
                stringBuilder.deleteCharAt(rowItem.name.length() - 1);
                try {
                    holder.txtTitle.setText(stringBuilder.toString().substring(stringBuilder.toString().lastIndexOf("/") + 1));
                } catch (Exception e) {
                    holder.txtTitle.setText(rowItem.name.substring(0, rowItem.name.lastIndexOf("/")));
                }
            }
        } else {
            if (compressedExplorerFragment.showSize)
                holder.txtDesc.setText(Formatter.formatFileSize(context, rowItem.size));
            holder.txtTitle.setText(rowItem.name.substring(rowItem.name.lastIndexOf("/") + 1));
            if (compressedExplorerFragment.coloriseIcons) {
                ColorUtils.colorizeIcons(context, rowItem.filetype, gradientDrawable, Color.parseColor(compressedExplorerFragment.iconskin));
            } else
                gradientDrawable.setColor(Color.parseColor(compressedExplorerFragment.iconskin));
        }
    }
    holder.rl.setOnLongClickListener(view -> {
        if (rowItem.type != CompressedObjectParcelable.TYPE_GOBACK) {
            toggleChecked(position, holder.checkImageView);
        }
        return true;
    });
    holder.genericIcon.setOnClickListener(view -> {
        if (rowItem.type != CompressedObjectParcelable.TYPE_GOBACK) {
            toggleChecked(position, holder.checkImageView);
        } else {
            compressedExplorerFragment.goBack();
        }
    });
    if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT)) {
        holder.rl.setBackgroundResource(R.drawable.safr_ripple_white);
    } else {
        holder.rl.setBackgroundResource(R.drawable.safr_ripple_black);
    }
    holder.rl.setSelected(false);
    if (itemsChecked[position]) {
        // holder.genericIcon.setImageDrawable(compressedExplorerFragment.getResources().getDrawable(R.drawable.abc_ic_cab_done_holo_dark));
        holder.checkImageView.setVisibility(View.VISIBLE);
        gradientDrawable.setColor(Utils.getColor(context, R.color.goback_item));
        holder.rl.setSelected(true);
    } else
        holder.checkImageView.setVisibility(View.INVISIBLE);
    holder.rl.setOnClickListener(p1 -> {
        if (rowItem.type == CompressedObjectParcelable.TYPE_GOBACK)
            compressedExplorerFragment.goBack();
        else {
            if (compressedExplorerFragment.selection) {
                toggleChecked(position, holder.checkImageView);
            } else {
                final StringBuilder stringBuilder = new StringBuilder(rowItem.name);
                if (rowItem.directory)
                    stringBuilder.deleteCharAt(rowItem.name.length() - 1);
                if (rowItem.directory) {
                    compressedExplorerFragment.changePath(stringBuilder.toString());
                } else {
                    String fileName = compressedExplorerFragment.compressedFile.getName().substring(0, compressedExplorerFragment.compressedFile.getName().lastIndexOf("."));
                    String archiveCacheDirPath = compressedExplorerFragment.getActivity().getExternalCacheDir().getPath() + CompressedHelper.SEPARATOR + fileName;
                    HybridFileParcelable file = new HybridFileParcelable(archiveCacheDirPath + CompressedHelper.SEPARATOR + rowItem.name.replaceAll("\\\\", CompressedHelper.SEPARATOR));
                    file.setMode(OpenMode.FILE);
                    // this file will be opened once service finishes up it's extraction
                    compressedExplorerFragment.files.add(file);
                    // setting flag for binder to know
                    compressedExplorerFragment.isOpen = true;
                    Toast.makeText(compressedExplorerFragment.getContext(), compressedExplorerFragment.getContext().getResources().getString(R.string.please_wait), Toast.LENGTH_SHORT).show();
                    decompressor.decompress(compressedExplorerFragment.getActivity().getExternalCacheDir().getPath(), new String[] { rowItem.name });
                }
            }
        }
    });
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) CircleGradientDrawable(com.amaze.filemanager.ui.views.CircleGradientDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) CircleGradientDrawable(com.amaze.filemanager.ui.views.CircleGradientDrawable)

Example 5 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class RarHelperTask method addElements.

@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
    try {
        Archive zipfile = new Archive(new File(fileLocation));
        String relativeDirDiffSeparator = relativeDirectory.replace(CompressedHelper.SEPARATOR, "\\");
        for (FileHeader header : zipfile.getFileHeaders()) {
            // This uses \ as separator, not /
            String name = header.getFileNameString();
            boolean isInBaseDir = (relativeDirDiffSeparator == null || relativeDirDiffSeparator.equals("")) && !name.contains("\\");
            boolean isInRelativeDir = relativeDirDiffSeparator != null && name.contains("\\") && name.substring(0, name.lastIndexOf("\\")).equals(relativeDirDiffSeparator);
            if (isInBaseDir || isInRelativeDir) {
                elements.add(new CompressedObjectParcelable(RarDecompressor.convertName(header), 0, header.getDataSize(), header.isDirectory()));
            }
        }
    } catch (RarException | IOException e) {
        e.printStackTrace();
    }
}
Also used : CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) Archive(com.github.junrar.Archive) RarException(com.github.junrar.exception.RarException) IOException(java.io.IOException) File(java.io.File) FileHeader(com.github.junrar.rarfile.FileHeader)

Aggregations

CompressedObjectParcelable (com.amaze.filemanager.adapters.data.CompressedObjectParcelable)6 IOException (java.io.IOException)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 GradientDrawable (android.graphics.drawable.GradientDrawable)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 CompressedExplorerAdapter (com.amaze.filemanager.adapters.CompressedExplorerAdapter)1 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 CircleGradientDrawable (com.amaze.filemanager.ui.views.CircleGradientDrawable)1 DividerItemDecoration (com.amaze.filemanager.ui.views.DividerItemDecoration)1 FastScroller (com.amaze.filemanager.ui.views.FastScroller)1 Archive (com.github.junrar.Archive)1 RarException (com.github.junrar.exception.RarException)1 FileHeader (com.github.junrar.rarfile.FileHeader)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1