From 848fe154bea8ae17df7f1bdbe8c40d8f920c05b8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Oct 2016 14:09:05 +0200 Subject: [PATCH] allow hiding folders --- .../com/simplemobiletools/gallery/Config.java | 15 ++++++++++++- .../simplemobiletools/gallery/Constants.java | 1 + .../gallery/activities/MainActivity.java | 21 +++++++++++++++++-- .../gallery/activities/MediaActivity.java | 7 +++++++ app/src/main/res/menu/menu_media.xml | 5 +++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 12 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/Config.java b/app/src/main/java/com/simplemobiletools/gallery/Config.java index da9c2e794..6806cfd19 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Config.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Config.java @@ -3,6 +3,9 @@ package com.simplemobiletools.gallery; import android.content.Context; import android.content.SharedPreferences; +import java.util.HashSet; +import java.util.Set; + public class Config { private SharedPreferences mPrefs; @@ -10,7 +13,7 @@ public class Config { return new Config(context); } - public Config(Context context) { + private Config(Context context) { mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); } @@ -59,4 +62,14 @@ public class Config { public void setDirectorySorting(int order) { mPrefs.edit().putInt(Constants.DIRECTORY_SORT_ORDER, order).apply(); } + + public void addHiddenDirectory(String path) { + final Set hiddenFolders = getHiddenFolders(); + hiddenFolders.add(path); + mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); + } + + public Set getHiddenFolders() { + return mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, new HashSet()); + } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/Constants.java b/app/src/main/java/com/simplemobiletools/gallery/Constants.java index 7480cf5e8..eb18fb5a9 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Constants.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Constants.java @@ -15,6 +15,7 @@ public class Constants { public static final String IS_SAME_SORTING = "is_same_sorting"; public static final String SORT_ORDER = "sort_order"; public static final String DIRECTORY_SORT_ORDER = "directory_sort_order"; + public static final String HIDDEN_FOLDERS = "hidden_foldersy"; // sorting public static final int SORT_BY_NAME = 1; diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 2552f91ba..642b07f51 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -43,6 +43,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import butterknife.BindView; import butterknife.ButterKnife; @@ -228,7 +229,7 @@ public class MainActivity extends SimpleActivity } final List dirs = new ArrayList<>(directories.values()); - removeNoMediaDirs(dirs); + filderDirectories(dirs); Directory.mSorting = mConfig.getDirectorySorting(); Collections.sort(dirs); @@ -238,7 +239,23 @@ public class MainActivity extends SimpleActivity return dirs; } - private void removeNoMediaDirs(List dirs) { + private void filderDirectories(List dirs) { + removeHiddenFolders(dirs); + removeNoMediaFolders(dirs); + } + + private void removeHiddenFolders(List dirs) { + final Set hiddenDirs = mConfig.getHiddenFolders(); + final List ignoreDirs = new ArrayList<>(); + for (Directory d : dirs) { + if (hiddenDirs.contains(d.getPath())) + ignoreDirs.add(d); + } + + dirs.removeAll(ignoreDirs); + } + + private void removeNoMediaFolders(List dirs) { final List ignoreDirs = new ArrayList<>(); for (final Directory d : dirs) { final File dir = new File(d.getPath()); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index c596b4e05..cc54c8385 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -139,6 +139,9 @@ public class MediaActivity extends SimpleActivity case R.id.sort: showSortingDialog(); return true; + case R.id.hide_folder: + hideDirectory(); + return true; default: return super.onOptionsItemSelected(item); } @@ -161,6 +164,10 @@ public class MediaActivity extends SimpleActivity new ChangeSorting(this, false); } + private void hideDirectory() { + mConfig.addHiddenDirectory(mPath); + } + private void deleteDirectoryIfEmpty() { final File file = new File(mPath); if (file.isDirectory() && file.listFiles().length == 0) { diff --git a/app/src/main/res/menu/menu_media.xml b/app/src/main/res/menu/menu_media.xml index c9dc82c1a..d8f86cb36 100644 --- a/app/src/main/res/menu/menu_media.xml +++ b/app/src/main/res/menu/menu_media.xml @@ -6,4 +6,9 @@ android:icon="@mipmap/sort" android:title="@string/sort_by" app:showAsAction="ifRoom"/> + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index fa4a35b38..789d701d8 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -31,6 +31,7 @@ Abbrechen Open with No valid app found + Hide folder 1 Ordner gelöscht diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 58f3b27c4..59fd5d8e1 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -31,6 +31,7 @@ Cancelar Open with No valid app found + Hide folder 1 carpeta eliminada diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index f61902a46..5440dd3ed 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -31,6 +31,7 @@ Cancel Open with No valid app found + Hide folder 1 cartella eliminata diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index cbbe0b41e..cd8ffcde7 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -31,6 +31,7 @@ Cancel Open with No valid app found + Hide folder 1 フォルダーを削除しました diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index ccba34186..e060bd5b6 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -31,6 +31,7 @@ Cancelar Open with No valid app found + Hide folder 1 pasta eliminada diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index d8a61c6bb..dfd47bcba 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -31,6 +31,7 @@ Cancel Open with No valid app found + Hide folder 1 mapp borttagen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d516ddb3c..046e57f4a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -31,6 +31,7 @@ Cancel Open with No valid app found + Hide folder 1 folder deleted