Skip to content

Commit

Permalink
FileManager: Remove top menu options to open special folders, go to v…
Browse files Browse the repository at this point in the history
…irtual storage directory folder instead that have them too

this way less duplication of those options, and all of them are available outside mainactivity too
  • Loading branch information
gsantner committed Oct 13, 2024
1 parent b492872 commit a4dd5c2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ 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("/storage", cu.rstr(context, R.string.notebook)), appSettings.getNotebookDirectory());
opts.storageMaps.put(new File("/storage/Download"), new File("/storage/emulated/0/Download"));
};
opts.refresh.callback();

Expand Down
42 changes: 15 additions & 27 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -746,59 +746,47 @@ public String getNavigationBarColor() {
return getString(R.string.pref_key__navigationbar_color, "#000000");
}

public @IdRes
Integer getAppStartupFolderMenuId() {
switch (getString(R.string.pref_key__app_start_folder, "notebook")) {
case "favourites":
return R.id.action_go_to_favourite_files;
case "internal_storage":
return R.id.action_go_to_storage;
case "appdata_public":
return R.id.action_go_to_appdata_public;
case "appdata_private":
return R.id.action_go_to_appdata_private;
case "popular_documents":
return R.id.action_go_to_popular_files;
case "recently_viewed_documents":
return R.id.action_go_to_recent_files;
}
return R.id.action_go_to_home;
public String getAppStartupFolderMenuId() {
return getString(R.string.pref_key__app_start_folder, "notebook");
}

public File getFolderToLoadByMenuId(int itemId) {
public File getFolderToLoadByMenuId(String itemId) {
List<Pair<File, String>> appDataPublicDirs = _cu.getAppDataPublicDirs(_context, false, true, false);
switch (itemId) {
case R.id.action_go_to_home: {
case "storage": {
return new File("/storage");
}
case "notebook": {
return getNotebookDirectory();
}
case R.id.action_go_to_popular_files: {
case "popular_documents": {
return GsFileBrowserListAdapter.VIRTUAL_STORAGE_POPULAR;
}
case R.id.action_go_to_recent_files: {
case "recently_viewed_documents": {
return GsFileBrowserListAdapter.VIRTUAL_STORAGE_RECENTS;
}
case R.id.action_go_to_favourite_files: {
case "favourites": {
return GsFileBrowserListAdapter.VIRTUAL_STORAGE_FAVOURITE;
}
case R.id.action_go_to_appdata_private: {
case "appdata_private": {
return _cu.getAppDataPrivateDir(_context);
}
case R.id.action_go_to_storage: {
case "internal_storage": {
return Environment.getExternalStorageDirectory();
}
case R.id.action_go_to_appdata_sdcard_1: {
case "appdata_sdcard_1": {
if (appDataPublicDirs.size() > 0) {
return appDataPublicDirs.get(0).first;
}
return Environment.getExternalStorageDirectory();
}
case R.id.action_go_to_appdata_sdcard_2: {
case "appdata_sdcard_2": {
if (appDataPublicDirs.size() > 1) {
return appDataPublicDirs.get(1).first;
}
return Environment.getExternalStorageDirectory();
}
case R.id.action_go_to_appdata_public: {
case "appdata_public": {
appDataPublicDirs = _cu.getAppDataPublicDirs(_context, true, false, false);
if (appDataPublicDirs.size() > 0) {
return appDataPublicDirs.get(0).first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
}

List<Pair<File, String>> sdcardFolders = _cu.getAppDataPublicDirs(getContext(), false, true, true);
int[] sdcardResIds = {R.id.action_go_to_appdata_sdcard_1, R.id.action_go_to_appdata_sdcard_2};
int[] sdcardResIds = {};
for (int i = 0; i < sdcardResIds.length && i < sdcardFolders.size(); i++) {
item = menu.findItem(sdcardResIds[i]);
item.setTitle(item.getTitle().toString().replaceFirst("[)]\\s*$", " " + sdcardFolders.get(i).second) + ")");
Expand Down Expand Up @@ -432,16 +432,8 @@ public boolean onOptionsItemSelected(final MenuItem item) {
reloadCurrentFolder();
return true;
}
case R.id.action_go_to_home:
case R.id.action_go_to_popular_files:
case R.id.action_go_to_recent_files:
case R.id.action_go_to_favourite_files:
case R.id.action_go_to_appdata_private:
case R.id.action_go_to_storage:
case R.id.action_go_to_appdata_sdcard_1:
case R.id.action_go_to_appdata_sdcard_2:
case R.id.action_go_to_appdata_public: {
final File folder = _appSettings.getFolderToLoadByMenuId(_id);
case R.id.action_go_to: {
final File folder = new File("/storage");
_filesystemViewerAdapter.setCurrentFolder(folder);
Toast.makeText(getContext(), folder.getAbsolutePath(), Toast.LENGTH_SHORT).show();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ 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-private");
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 @@ -211,6 +212,9 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos
if (isCurrentFolderVirtual() && "index.html".equals(filename)) {
titleText += " [" + currentFolderName + "]";
}
if (currentFolderName.equals("storage") && _dopt.storageMaps.containsValue(displayFile)){
titleText = GsCollectionUtils.reverse(_dopt.storageMaps).get(displayFile).getName();
}

holder.title.setText(isGoUp ? ".." : titleText, TextView.BufferType.SPANNABLE);
holder.title.setTextColor(ContextCompat.getColor(_context, _dopt.primaryTextColor));
Expand All @@ -230,7 +234,7 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos

holder.image.setImageResource(isSelected ? _dopt.selectedItemImage : isFile ? _dopt.fileImage : _dopt.folderImage);
holder.image.setColorFilter(ContextCompat.getColor(_context,
isSelected ? _dopt.accentColor : isFile? _dopt.fileColor : _dopt.folderColor),
isSelected ? _dopt.accentColor : isFile ? _dopt.fileColor : _dopt.folderColor),
android.graphics.PorterDuff.Mode.SRC_ATOP);

if (!isSelected && isFavourite) {
Expand Down Expand Up @@ -264,15 +268,6 @@ public void onAttachedToRecyclerView(@NonNull final RecyclerView view) {
_layoutManager = (LinearLayoutManager) view.getLayoutManager();
}

public String formatFileDescription(final File file, String format) {
if (TextUtils.isEmpty(format)) {
return DateUtils.formatDateTime(_context, file.lastModified(), (DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE));
} else {
format = format.replaceAll("FS(?=([^']*'[^']*')*[^']*$)", '\'' + GsFileUtils.getHumanReadableByteCountSI(file.length()) + '\'');
return new SimpleDateFormat(format, Locale.getDefault()).format(file.lastModified());
}
}

public void saveInstanceState(final @NonNull Bundle outState) {
if (_currentFolder != null) {
outState.putSerializable(EXTRA_CURRENT_FOLDER, _currentFolder.getAbsolutePath());
Expand All @@ -285,6 +280,15 @@ public void saveInstanceState(final @NonNull Bundle outState) {
}
}

public String formatFileDescription(final File file, String format) {
if (TextUtils.isEmpty(format)) {
return DateUtils.formatDateTime(_context, file.lastModified(), (DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE));
} else {
format = format.replaceAll("FS(?=([^']*'[^']*')*[^']*$)", '\'' + GsFileUtils.getHumanReadableByteCountSI(file.length()) + '\'');
return new SimpleDateFormat(format, Locale.getDefault()).format(file.lastModified());
}
}

public void restoreSavedInstanceState(final Bundle savedInstanceState) {
if (savedInstanceState == null) {
return;
Expand Down Expand Up @@ -401,7 +405,7 @@ public void onClick(View view) {
case R.id.opoc_filesystem_item__root: {
// A own item was clicked
if (data.file != null) {
final File file = GsCollectionUtils.getOrDefault(_virtualMapping, data.file, data.file);
File file = GsCollectionUtils.getOrDefault(_virtualMapping, data.file, data.file);

if (areItemsSelected()) {
// There are 1 or more items selected yet
Expand Down Expand Up @@ -708,6 +712,7 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl
}

if (folder.equals(VIRTUAL_STORAGE_ROOT)) {
newData.addAll(_dopt.storageMaps.values());
newData.addAll(_virtualMapping.keySet());
}

Expand Down Expand Up @@ -739,9 +744,9 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl

if (canGoUp(folder)) {
if (
isVirtualFolder(folder) ||
_virtualMapping.containsValue(folder) ||
!GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, folder)
isVirtualFolder(folder) ||
_virtualMapping.containsValue(folder) ||
!GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, folder)
) {
newData.add(0, VIRTUAL_STORAGE_ROOT);
} else {
Expand Down Expand Up @@ -889,18 +894,18 @@ public static class FilesystemViewerViewHolder extends RecyclerView.ViewHolder {
}
}

public static boolean isVirtualFolder(final File file) {
return VIRTUAL_STORAGE_RECENTS.equals(file) ||
VIRTUAL_STORAGE_FAVOURITE.equals(file) ||
VIRTUAL_STORAGE_POPULAR.equals(file) ||
VIRTUAL_STORAGE_APP_DATA_PRIVATE.equals(file) ||
VIRTUAL_STORAGE_EMULATED.equals(file);
}

private boolean isParent(File parent, File child) {
return (VIRTUAL_STORAGE_ROOT.equals(parent) && _virtualMapping.containsKey(child)) || GsFileUtils.isChild(parent, child);
}

public static boolean isVirtualFolder(final File file) {
return VIRTUAL_STORAGE_RECENTS.equals(file) ||
VIRTUAL_STORAGE_FAVOURITE.equals(file) ||
VIRTUAL_STORAGE_POPULAR.equals(file) ||
VIRTUAL_STORAGE_APP_DATA_PRIVATE.equals(file) ||
VIRTUAL_STORAGE_EMULATED.equals(file);
}

public void showFileAfterNextLoad(final File file) {
_fileToShowAfterNextLoad = file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;

@SuppressWarnings({"unused", "WeakerAccess"})
public class GsFileBrowserOptions {
Expand Down Expand Up @@ -122,6 +123,7 @@ public static class Options {
@ColorRes
public int folderColor = 0;

public final HashMap<File, File> storageMaps = new HashMap<>();
public Collection<File> favouriteFiles, recentFiles, popularFiles = null;
public GsCallback.a1<CharSequence> setTitle = null, setSubtitle = null;

Expand Down
54 changes: 2 additions & 52 deletions app/src/main/res/menu/filesystem__menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,63 +72,13 @@
android:title="@string/share"
android:visible="false"
app:showAsAction="never" />

<item
android:id="@+id/action_go_to"
android:layout_width="match_parent"
android:icon="@drawable/ic_folder_white_24dp"
android:title="@string/go_to"
app:showAsAction="always">

<menu>
<item
android:id="@+id/action_go_to_appdata_sdcard_1"
android:icon="@drawable/ic_sd_card_black_24dp"
android:title="@string/appdata_sdcard"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_appdata_sdcard_2"
android:icon="@drawable/ic_sd_card_black_24dp"
android:title="@string/appdata_sdcard"
android:visible="false"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_appdata_private"
android:icon="@drawable/ic_lock_outline_black_24dp"
android:title="@string/appdata_private"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_appdata_public"
android:icon="@drawable/ic_lock_outline_black_24dp"
android:title="@string/appdata_public"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_storage"
android:icon="@drawable/ic_storage_black_24dp"
android:title="@string/internal_storage"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_recent_files"
android:icon="@drawable/ic_history_black_24dp"
android:title="@string/recently_viewed_documents"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_popular_files"
android:icon="@drawable/ic_favorite_black_24dp"
android:title="@string/popular_documents"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_favourite_files"
android:icon="@drawable/ic_star_black_24dp"
android:title="@string/favourites"
app:showAsAction="never" />
<item
android:id="@+id/action_go_to_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/notebook"
app:showAsAction="never" />
</menu>
</item>
app:showAsAction="always" />

<item
android:id="@+id/action_sort"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<item translatable="false">@string/appdata_private</item>
<item translatable="false">@string/popular_documents</item>
<item translatable="false">@string/recently_viewed_documents</item>
<item translatable="false">@string/storage</item>
</string-array>

<string-array name="pref_arrkeys__files_startup_folder" translatable="false">
Expand All @@ -116,6 +117,7 @@
<item translatable="false">appdata_private</item>
<item translatable="false">popular_documents</item>
<item translatable="false">recently_viewed_documents</item>
<item translatable="false">storage</item>
</string-array>

<string-array name="pref_arrdisp__unordered_list_character" translatable="false">
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="quicknote" translatable="false">QuickNote</string>
<string name="todo" translatable="false">To-Do</string>
<string name="todo_txt" translatable="false">todo.txt</string>
<string name="storage" translatable="false">Storage</string>
<string name="quicknote_default_filename" translatable="false">QuickNote.md</string>
<string name="todo_default_filename" translatable="false">todo.txt</string>
<string name="web_browser" translatable="false">Web browser</string>
Expand Down Expand Up @@ -182,6 +183,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__editor_markdown_bigger_headings_2" translatable="false">pref_key__editor_markdown_bigger_headings_2</string>
<string name="pref_key__editor_unordered_list_character" translatable="false">pref_key__editor_unordered_list_character</string>
<string name="pref_key__recent_documents" translatable="false">pref_key__recent_documents</string>
<string name="pref_key__storage" translatable="false">pref_key__recent_documents</string>
<string name="pref_key__popular_documents" translatable="false">pref_key__popular_documents</string>
<string name="pref_key__favourite_files" translatable="false">pref_key__favourite_files</string>
<string name="pref_key__select_create_document" translatable="false">pref_key__select_create_document</string>
Expand Down Expand Up @@ -422,6 +424,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__template_title_format_map" translatable="false">pref_key__template_title_format_map</string>
<string name="pref_key__title_format_list" translatable="false">pref_key__title_format_list</string>
<string name="pref_key__format_share_as_link" translatable="false">pref_key__format_share_as_link</string>
<string name="action_go_to_storage" translatable="false">action_go_to_storage</string>
<string name="squarebrackets" translatable="false">Square Brackets</string>
<string name="csv" translatable="false">CSV</string>
<string name="orgmode" translatable="false">OrgMode</string>
Expand Down

0 comments on commit a4dd5c2

Please sign in to comment.