Skip to content

Commit

Permalink
Merge pull request #1500 from EmmanuelMess/fix-back
Browse files Browse the repository at this point in the history
Fix back item in list when headers are active
  • Loading branch information
EmmanuelMess committed Nov 12, 2018
1 parent 5b0b7d3 commit 81fd594
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -50,6 +51,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.amaze.filemanager.adapters.RecyclerAdapter.ListElemType.*;
import static com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_COLORIZE_ICONS;
import static com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_FILE_SIZE;
import static com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_GOBACK_BUTTON;
Expand All @@ -61,7 +63,7 @@

/**
* This class is the information that serves to load the files into a "list" (a RecyclerView).
* There are 3 types of item TYPE_ITEM, TYPE_HEADER_FOLDERS and TYPE_HEADER_FILES and EMPTY_LAST_ITEM
* There are 3 types of item TYPE_ITEM, TYPE_HEADER_FOLDERS and TYPE_HEADER_FILES, EMPTY_LAST_ITEM and TYPE_BACK
* represeted by ItemViewHolder, SpecialViewHolder and EmptyViewHolder respectively.
* The showPopup shows the file's popup menu.
* The 'go to parent' aka '..' button (go to settings to activate it) is just a folder.
Expand All @@ -72,7 +74,10 @@
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
implements RecyclerPreloadSizeProvider.RecyclerPreloadSizeProviderCallback {

public static final int TYPE_ITEM = 0, TYPE_HEADER_FOLDERS = 1, TYPE_HEADER_FILES = 2, EMPTY_LAST_ITEM = 3;
public static final int TYPE_ITEM = 0, TYPE_HEADER_FOLDERS = 1, TYPE_HEADER_FILES = 2, EMPTY_LAST_ITEM = 3, TYPE_BACK = 4;

@IntDef({TYPE_ITEM, TYPE_HEADER_FOLDERS, TYPE_HEADER_FILES, EMPTY_LAST_ITEM, TYPE_BACK})
public @interface ListElemType {}

private static final int VIEW_GENERIC = 0, VIEW_PICTURE = 1, VIEW_APK = 2, VIEW_THUMB = 3;

Expand Down Expand Up @@ -336,8 +341,8 @@ private void setItems(RecyclerView recyclerView, ArrayList<LayoutElementParcelab
ArrayList<IconDataParcelable> uris = new ArrayList<>(itemsDigested.size());

for (LayoutElementParcelable e : arrayList) {
itemsDigested.add(new ListItem(e));
uris.add(e != null? e.iconData:null);
itemsDigested.add(new ListItem(e.isBack, e));
uris.add(e != null ? e.iconData : null);
}

if (mainFrag.IS_LIST && itemsDigested.size() > 0) {
Expand Down Expand Up @@ -431,6 +436,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType

return new SpecialViewHolder(context, view, utilsProvider, type);
case TYPE_ITEM:
case TYPE_BACK:
if (mainFrag.IS_LIST) {
view = mInflater.inflate(R.layout.rowlayout, parent, false);
sizeProvider.addView(VIEW_GENERIC, view.findViewById(R.id.generic_icon));
Expand Down Expand Up @@ -459,7 +465,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
public void onBindViewHolder(final RecyclerView.ViewHolder vholder, int p) {
if (vholder instanceof ItemViewHolder) {
final ItemViewHolder holder = (ItemViewHolder) vholder;
final boolean isBackButton = getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) && p == 0;
final boolean isBackButton = itemsDigested.get(p).specialType == TYPE_BACK;
if(isBackButton){
holder.about.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -946,16 +952,20 @@ private static class ListItem {
public static final int CHECKED = 0, NOT_CHECKED = 1, UNCHECKABLE = 2;

private LayoutElementParcelable elem;
private int specialType;
private @ListElemType int specialType;
private boolean checked;
private boolean animate;

ListItem(LayoutElementParcelable elem) {
this(false, elem);
}

ListItem(boolean isBack, LayoutElementParcelable elem) {
this.elem = elem;
specialType = TYPE_ITEM;
specialType = isBack? TYPE_BACK:TYPE_ITEM;
}

ListItem(int specialType) {
ListItem(@ListElemType int specialType) {
this.specialType = specialType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class LayoutElementParcelable implements Parcelable {

private static final String CURRENT_YEAR = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));

public final boolean isBack;
public final int filetype;
public final IconDataParcelable iconData;
public final String title;
Expand All @@ -51,18 +52,27 @@ public class LayoutElementParcelable implements Parcelable {
//same as hfile.modes but different than openmode in Main.java
private OpenMode mode = OpenMode.FILE;

public LayoutElementParcelable(boolean isBack, String goback, boolean showThumbs) {
this(true, new File("..").getName(), "..", "", "", goback, 0,
false, "", true, showThumbs, OpenMode.UNKNOWN);
}

public LayoutElementParcelable(String path, String permissions, String symlink,
String size, long longSize,boolean header, String date,
boolean isDirectory, boolean useThumbs, OpenMode openMode) {
this(new File(path).getName(), path, permissions, symlink, size, longSize, header,
date, isDirectory, useThumbs, openMode);

}


public LayoutElementParcelable(String title, String path, String permissions,
String symlink, String size, long longSize, boolean header,
String date, boolean isDirectory, boolean useThumbs, OpenMode openMode) {
this(false, title, path, permissions, symlink, size, longSize, header, date, isDirectory, useThumbs, openMode);
}

public LayoutElementParcelable(boolean isBack, String title, String path, String permissions,
String symlink, String size, long longSize, boolean header,
String date, boolean isDirectory, boolean useThumbs, OpenMode openMode) {
filetype = Icons.getTypeOfFile(path, isDirectory);
@DrawableRes int fallbackIcon = Icons.loadMimeIcon(path, isDirectory);
this.mode = openMode;
Expand Down Expand Up @@ -106,6 +116,7 @@ public LayoutElementParcelable(String title, String path, String permissions,
this.date = 0;
this.date1 = "";
}
this.isBack = isBack;
}

public OpenMode getMode() {
Expand Down Expand Up @@ -147,6 +158,7 @@ public LayoutElementParcelable(Parcel im) {
date1 = im.readString();
size = im.readString();
longSize=im.readLong();
isBack = im.readInt() != 0;
}

@Override
Expand All @@ -169,6 +181,7 @@ public void writeToParcel(Parcel p1, int p2) {
p1.writeString(date1);
p1.writeString(size);
p1.writeLong(longSize);
p1.writeInt(isBack? 1:0);
}

public static final Parcelable.Creator<LayoutElementParcelable> CREATOR =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,7 @@ public void reloadListElements(boolean back, boolean results, boolean grid) {

private LayoutElementParcelable getBackElement() {
if (back == null) {
back = new LayoutElementParcelable("..", "", "",
getString(R.string.goback), 0, false, "",
true, getBoolean(PREFERENCE_SHOW_THUMB), OpenMode.UNKNOWN);
back = new LayoutElementParcelable(true, getString(R.string.goback), getBoolean(PREFERENCE_SHOW_THUMB));
}

return back;
Expand Down

0 comments on commit 81fd594

Please sign in to comment.