zip4j
zip4j copied to clipboard
Get the path of compressed files in Recycler View
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?
Zip files contains file names with paths. The real file name is the substring after the last '/'. Your code treats output entry list incorrectly.
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?
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.
When
fileNameends with/- this is a folder. I.e.zipEntryis not a zip file but a folder. WhenfileNamedoes not end with '/' and contain/- it means that thiszipEntryis a file with given path (including subfolders)
I did not understand, can you give a code example?
When
fileNameends with/- this is a folder. I.e.zipEntryis not a zip file but a folder. WhenfileNamedoes not end with '/' and contain/- it means that thiszipEntryis 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
When
fileNameends with/- this is a folder. I.e.zipEntryis not a zip file but a folder. WhenfileNamedoes not end with '/' and contain/- it means that thiszipEntryis 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