zip4j icon indicating copy to clipboard operation
zip4j copied to clipboard

Get the path of compressed files in Recycler View

Open appt2 opened this issue 1 year ago • 6 comments

Screenshot_2024-02-18-18-31-03-623_Ninja coder Ghostemane code


package Ninja.coder.Ghostemane.code.adapter;

import Ninja.coder.Ghostemane.code.R;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.view.LayoutInflater;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import net.lingala.zip4j.model.FileHeader;

public class ZipListFileShowAd extends RecyclerView.Adapter<ZipListFileShowAd.VH> {

  protected List<FileHeader> listModel;

  public ZipListFileShowAd(List<FileHeader> listModel) {
    this.listModel = listModel;
  }

  @Override
  public int getItemCount() {
    return listModel.size();
  }

  @Override
  public void onBindViewHolder(VH viewHolder, int pos) {

    View view = viewHolder.itemView;
    RecyclerView.LayoutParams _lp =
        new RecyclerView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    view.setLayoutParams(_lp);
    FileHeader fileM = listModel.get(pos);
    viewHolder.tvTools.setVisibility(View.GONE);
    viewHolder.folderName.setText(fileM.getFileName());
  }

  @Override
  public VH onCreateViewHolder(ViewGroup parnt, int pos) {
    View view =
        LayoutInflater.from(parnt.getContext()).inflate(R.layout.folder_remster, parnt, false);
    RecyclerView.LayoutParams _lp =
        new RecyclerView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    view.setLayoutParams(_lp);
    return new VH(view);
  }

  public class VH extends RecyclerView.ViewHolder {
    protected TextView folderName, tvTools;
    protected LinearLayout roots;
    protected ImageView icon;

    public VH(View view) {
      super(view);
      folderName = view.findViewById(R.id.folderName);
      tvTools = view.findViewById(R.id.tvTools);
      roots = view.findViewById(R.id.roots);
      icon = view.findViewById(R.id.icon);
    }
  }
}

Hello, I use your library to get the list of compressed files, but as you can see in the picture, the path of the files is displayed strangely, what is the solution?

appt2 avatar Feb 18 '24 15:02 appt2

Zip files contains file names with paths. The real file name is the substring after the last '/'. Your code treats output entry list incorrectly.

oleg-cherednik avatar Mar 15 '24 05:03 oleg-cherednik

Zip files contains file names with paths. The real file name is the substring after the last '/'. Your code treats output entry list incorrectly.

So how can I fix this problem?

appt2 avatar Mar 15 '24 06:03 appt2

When fileName ends with / - this is a folder. I.e. zipEntry is not a zip file but a folder. When fileName does not end with '/' and contain / - it means that this zipEntry is a file with given path (including subfolders). Just remember, that zip file contains a list of zipEntry. Each zipEntry can be either a file or a folder, i.e. a file with zero length.

oleg-cherednik avatar Mar 17 '24 16:03 oleg-cherednik

When fileName ends with / - this is a folder. I.e. zipEntry is not a zip file but a folder. When fileName does not end with '/' and contain / - it means that this zipEntry is a file with given path (including subfolders)

I did not understand, can you give a code example?

appt2 avatar Mar 17 '24 17:03 appt2

When fileName ends with / - this is a folder. I.e. zipEntry is not a zip file but a folder. When fileName does not end with '/' and contain / - it means that this zipEntry is a file with given path (including subfolders)

I did not understand, can you give a code example?

Give me a link to your zip file

oleg-cherednik avatar Mar 17 '24 17:03 oleg-cherednik

When fileName ends with / - this is a folder. I.e. zipEntry is not a zip file but a folder. When fileName does not end with '/' and contain / - it means that this zipEntry is a file with given path (including subfolders)

I did not understand, can you give a code example?

Give me a link to your zip file

I don't have a zip file right now

appt2 avatar Mar 17 '24 17:03 appt2