Skip to content

Commit

Permalink
Before hork out
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Dec 16, 2024
1 parent ed98639 commit d958cf5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(
opts.fileImage = R.drawable.ic_file_white_24dp;
opts.folderImage = R.drawable.ic_folder_white_24dp;
opts.descriptionFormat = appSettings.getString(R.string.pref_key__file_description_format, "");

opts.titleText = R.string.select;

opts.mountedStorageFolder = cu.getStorageAccessFolder(context);

opts.virtualDirs.add(new GsFileBrowserOptions.VirtualDir())

opts.popularImage = R.drawable.ic_favorite_black_24dp;
opts.favouriteImage = R.drawable.ic_star_black_24dp;
opts.recentImage = R.drawable.ic_history_black_24dp;
opts.downloadImage = R.drawable.baseline_download_24;
opts.homeImage = R.drawable.ic_home_black_24dp;

opts.refresh = () -> {
opts.sortFolderFirst = appSettings.isFileBrowserSortFolderFirst();
opts.sortByType = appSettings.getFileBrowserSortByType();
Expand All @@ -81,8 +87,7 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(
opts.favouriteFiles = appSettings.getFavouriteFiles();
opts.recentFiles = appSettings.getRecentFiles();
opts.popularFiles = appSettings.getPopularFiles();
opts.storageMaps.clear();
opts.storageMaps.put(new File(cu.rstr(context, R.string.notebook)), appSettings.getNotebookDirectory());
opts.homeFolder = appSettings.getNotebookDirectory();
};
opts.refresh.callback();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class GsFileBrowserListAdapter extends RecyclerView.Adapter<GsFileBrowser
public static final File VIRTUAL_STORAGE_FAVOURITE = new File(VIRTUAL_STORAGE_ROOT, "Favourites");
public static final File VIRTUAL_STORAGE_POPULAR = new File(VIRTUAL_STORAGE_ROOT, "Popular");
public static final File VIRTUAL_STORAGE_APP_DATA_PRIVATE = new File(VIRTUAL_STORAGE_ROOT, "AppData (data partition)");
public static final File VIRTUAL_STORAGE_DOWNLOAD = new File(VIRTUAL_STORAGE_ROOT, "Download");
public static final File VIRTUAL_STORAGE_HOME = new File(VIRTUAL_STORAGE_ROOT, "Notebook");
private static final File GO_BACK_SIGNIFIER = new File("__GO_BACK__");
private static final StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan();
public static final String EXTRA_CURRENT_FOLDER = "EXTRA_CURRENT_FOLDER";
Expand Down Expand Up @@ -147,11 +149,6 @@ public void updateVirtualFolders() {
final GsContextUtils cu = GsContextUtils.instance;

_virtualMapping.clear();

if (_dopt.storageMaps != null) {
_virtualMapping.putAll(_dopt.storageMaps);
}

_virtualMapping.put(VIRTUAL_STORAGE_EMULATED, VIRTUAL_STORAGE_EMULATED);

final File appDataFolder = _context.getFilesDir();
Expand All @@ -160,21 +157,32 @@ public void updateVirtualFolders() {
}

for (final File file : ContextCompat.getExternalFilesDirs(_context, null)) {
if (file == null || (file != null && file.getParentFile() == null)) {
continue;
if (file != null) {
final File parent = file.getParentFile();
if (parent != null) {
final String name = parent.toString().replace("/", "-").substring(1);
final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + name + ")");
_virtualMapping.put(remap, file);
}
}
final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + file.getParentFile().toString().replace("/", "-").substring(1) + ")");
_virtualMapping.put(remap, file);
}

if (_dopt.virtualMaps != null) {
_virtualMapping.putAll(_dopt.virtualMaps);
}

final File download = getDownloadFolder();
if (download != null) {
_virtualMapping.put(new File(VIRTUAL_STORAGE_ROOT, "Download"), download);
_virtualMapping.put(VIRTUAL_STORAGE_DOWNLOAD, download);
}

_virtualMapping.put(VIRTUAL_STORAGE_RECENTS, VIRTUAL_STORAGE_RECENTS);
_virtualMapping.put(VIRTUAL_STORAGE_POPULAR, VIRTUAL_STORAGE_POPULAR);
_virtualMapping.put(VIRTUAL_STORAGE_FAVOURITE, VIRTUAL_STORAGE_FAVOURITE);

if (_dopt.homeFolder != null) {
_virtualMapping.put(VIRTUAL_STORAGE_HOME, _dopt.homeFolder);
}
}

@NonNull
Expand Down Expand Up @@ -221,7 +229,15 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos
titleText += " [" + currentFolderName + "]";
}

holder.title.setText(isGoUp ? ".." : titleText, TextView.BufferType.SPANNABLE);
if (isGoUp) {
holder.title.setText("..", TextView.BufferType.SPANNABLE);
} else if (VIRTUAL_STORAGE_HOME.equals(displayFile) && _dopt.homeDirTitle != 0) {
holder.title.setText(_context.getString(R.string.home), TextView.BufferType.SPANNABLE);
} else {
holder.title.setText(titleText, TextView.BufferType.SPANNABLE);
}

holder.title.setText(isGoUp ? ".." : titleText, );
holder.title.setTextColor(ContextCompat.getColor(_context, _dopt.primaryTextColor));

if (!isFileWriteable(displayFile, isGoUp) && !isVirtualFolder(displayFile) && holder.title.length() > 0) {
Expand All @@ -239,12 +255,16 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos

if (isSelected) {
holder.image.setImageResource(isSelected ? _dopt.selectedItemImage : isFile ? _dopt.fileImage : _dopt.folderImage);
} else if (VIRTUAL_STORAGE_FAVOURITE.equals(displayFile)) {
holder.image.setImageResource(R.drawable.ic_star_black_24dp);
} else if (VIRTUAL_STORAGE_POPULAR.equals(displayFile)) {
holder.image.setImageResource(R.drawable.ic_favorite_black_24dp);
} else if (VIRTUAL_STORAGE_RECENTS.equals(displayFile)) {
holder.image.setImageResource(R.drawable.ic_history_black_24dp);
} else if (VIRTUAL_STORAGE_FAVOURITE.equals(displayFile) && _dopt.favouriteImage != 0) {
holder.image.setImageResource(_dopt.favouriteImage);
} else if (VIRTUAL_STORAGE_POPULAR.equals(displayFile) && _dopt.popularImage != 0) {
holder.image.setImageResource(_dopt.popularImage);
} else if (VIRTUAL_STORAGE_RECENTS.equals(displayFile) && _dopt.recentImage != 0) {
holder.image.setImageResource(_dopt.recentImage);
} else if (VIRTUAL_STORAGE_DOWNLOAD.equals(displayFile) && _dopt.downloadImage != 0) {
holder.image.setImageResource(_dopt.downloadImage);
} else if (VIRTUAL_STORAGE_HOME.equals(displayFile) && _dopt.homeImage != 0) {
holder.image.setImageResource(_dopt.homeImage);
} else {
holder.image.setImageResource(isFile ? _dopt.fileImage : _dopt.folderImage);
}
Expand Down Expand Up @@ -535,7 +555,7 @@ public boolean toggleSelection(final TagContainer data) {
}

public boolean goBack() {
if (canGoBack()) {
if (!_backStack.isEmpty()) {
File show = _currentFolder;
if (VIRTUAL_STORAGE_ROOT.equals(_backStack.peek())) {
show = GsCollectionUtils.reverseSearch(_virtualMapping, _currentFolder);
Expand All @@ -546,35 +566,21 @@ public boolean goBack() {
return false;
}

public boolean canGoBack() {
return !_backStack.isEmpty();
}

public boolean goUp() {
if (_currentFolder != null && canGoUp()) {
final File parent = _currentFolder.getParentFile();
if (parent != null) {
loadFolder(_currentFolder.getParentFile(), _currentFolder);
return true;
} else if (_virtualMapping.containsValue(_currentFolder)) {
loadFolder(VIRTUAL_STORAGE_ROOT, GsCollectionUtils.reverseSearch(_virtualMapping, _currentFolder));
return true;
}
private @Nullable File getCurrentParent() {
if (_currentFolder == null) {
return null;
}
return false;
}

public boolean canGoUp() {
return canGoUp(_currentFolder);
}
final File parent = _currentFolder.getParentFile();
if ((parent != null && parent.canWrite()) || GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, parent)) {
return parent;
}

public boolean canGoUp(final File folder) {
try {
final File parent = folder != null ? folder.getParentFile() : null;
return (parent != null && parent.canWrite()) || GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, folder);
} catch (SecurityException ignored) {
return false;
if (VIRTUAL_STORAGE_ROOT.equals(parent) || _virtualMapping.containsValue(_currentFolder)) {
return VIRTUAL_STORAGE_ROOT;
}

return null;
}

@Override
Expand Down Expand Up @@ -760,12 +766,9 @@ private synchronized void _loadFolder(final boolean folderChanged, final @Nullab
final long modSum = GsCollectionUtils.accumulate(newData, (f, s) -> s + f.lastModified(), 0L);
final boolean modSumChanged = modSum != _prevModSum;

if (canGoUp(_currentFolder)) {
if (isVirtualFolder(_currentFolder) || _virtualMapping.containsValue(_currentFolder) || GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, _currentFolder)) {
newData.add(0, VIRTUAL_STORAGE_ROOT);
} else {
newData.add(0, _currentFolder.getParentFile());
}
final File parent = getCurrentParent();
if (parent != null) {
newData.add(0, parent);
}

if (folderChanged || modSumChanged || !newData.equals(_adapterData)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.wrapper.GsCallback;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings({"unused", "WeakerAccess"})
Expand All @@ -42,6 +45,13 @@ public interface SelectionListener {
void onFsViewerItemLongPressed(final File file, boolean doSelectMultiple);
}

public static class VirtualDir {
String title;
@Nullable File location;
@DrawableRes int icon;
@Nullable Collection<File> contents;
}

public static class Options {
public SelectionListener listener = new SelectionListenerAdapter();
public File
Expand Down Expand Up @@ -124,10 +134,8 @@ public static class Options {
@ColorRes
public int folderColor = 0;

public final Map<File, File> storageMaps = new LinkedHashMap<>();
public Collection<File> favouriteFiles, recentFiles, popularFiles = null;
public final List<VirtualDir> virtualDirs = new ArrayList<>();
public GsCallback.a1<CharSequence> setTitle = null, setSubtitle = null;

public GsCallback.a0 refresh = null;
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_download_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M5,20h14v-2H5V20zM19,9h-4V3H9v6H5l7,7L19,9z"/>

</vector>

0 comments on commit d958cf5

Please sign in to comment.