Skip to content

Commit

Permalink
FileManager: Remove top submenu to open special folders, load storage…
Browse files Browse the repository at this point in the history
… overview in filemanager instead (PR gsantner#2440 by @gsantner)

* Remove top menu submenu  to open special folders, go to virtual storage directory folder instead
* There all special folders/devices/lists are available too, and only needs to be maintained at one location then
* this way less duplication of those options, and all of them are available outside mainactivity too
  • Loading branch information
gsantner authored Oct 13, 2024
1 parent 6ae8ea3 commit b282167
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 100 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 @@ -211,6 +211,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 +233,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 @@ -708,6 +711,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 @@ -738,11 +742,7 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl
final boolean modSumChanged = modSum != _prevModSum;

if (canGoUp(folder)) {
if (
isVirtualFolder(folder) ||
_virtualMapping.containsValue(folder) ||
!GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, folder)
) {
if (isVirtualFolder(folder) || _virtualMapping.containsValue(folder) || !GsFileUtils.isChild(VIRTUAL_STORAGE_ROOT, folder)) {
newData.add(0, VIRTUAL_STORAGE_ROOT);
} else {
newData.add(0, folder.getParentFile());
Expand Down Expand Up @@ -891,10 +891,10 @@ 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);
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) {
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
1 change: 1 addition & 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

0 comments on commit b282167

Please sign in to comment.