mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 08:58:30 +03:00
Merge pull request #328 from apicellaj/master
add preference to show hidden files
This commit is contained in:
commit
8ace0d0d11
6 changed files with 71 additions and 1 deletions
|
@ -28,6 +28,7 @@
|
|||
<string name="prefs_accounts">Accounts</string>
|
||||
<string name="prefs_manage_accounts">Manage accounts</string>
|
||||
<string name="prefs_passcode">Passcode lock</string>
|
||||
<string name="prefs_show_hidden_files">Show hidden files</string>
|
||||
<string name="prefs_instant_upload">Instant picture uploads</string>
|
||||
<string name="prefs_instant_upload_summary">Instantly upload pictures taken by camera</string>
|
||||
<string name="prefs_instant_video_upload">Instant video uploads</string>
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
|
||||
<PreferenceCategory android:title="@string/prefs_category_details">
|
||||
<android.preference.CheckBoxPreference android:title="@string/prefs_passcode" android:key="set_pincode" />
|
||||
<android.preference.CheckBoxPreference android:title="@string/prefs_show_hidden_files" android:key="show_hidden_files" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
|
||||
|
|
|
@ -74,6 +74,10 @@ public abstract class PreferenceManager {
|
|||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false);
|
||||
}
|
||||
|
||||
public static boolean showHiddenFilesEnabled(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_hidden_files_pref", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path where the user selected to do the last upload of a file shared from other app.
|
||||
*
|
||||
|
|
|
@ -86,6 +86,7 @@ public class Preferences extends PreferenceActivity {
|
|||
private Uri mUri;
|
||||
|
||||
private CheckBoxPreference pCode;
|
||||
private CheckBoxPreference mShowHiddenFiles;
|
||||
private Preference pAboutApp;
|
||||
private AppCompatDelegate mDelegate;
|
||||
|
||||
|
@ -164,6 +165,19 @@ public class Preferences extends PreferenceActivity {
|
|||
});
|
||||
}
|
||||
|
||||
mShowHiddenFiles = (CheckBoxPreference) findPreference("show_hidden_files");
|
||||
mShowHiddenFiles.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
SharedPreferences appPrefs =
|
||||
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
SharedPreferences.Editor editor = appPrefs.edit();
|
||||
editor.putBoolean("show_hidden_files_pref", mShowHiddenFiles.isChecked());
|
||||
editor.commit();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
|
||||
|
||||
boolean calendarContactsEnabled = getResources().getBoolean(R.bool.calendar_contacts_enabled);
|
||||
|
|
|
@ -66,6 +66,7 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
private Vector<OCFile> mFilesAll = new Vector<OCFile>();
|
||||
private Vector<OCFile> mFiles = null;
|
||||
private boolean mJustFolders;
|
||||
private boolean mShowHiddenFiles;
|
||||
|
||||
private FileDataStorageManager mStorageManager;
|
||||
private Account mAccount;
|
||||
|
@ -87,6 +88,9 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(mContext);
|
||||
FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(mContext);
|
||||
|
||||
// Fetch preferences for showing hidden files
|
||||
mShowHiddenFiles = PreferenceManager.showHiddenFilesEnabled(mContext);
|
||||
|
||||
// initialise thumbnails cache on background thread
|
||||
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
|
||||
}
|
||||
|
@ -390,6 +394,10 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
if (mJustFolders) {
|
||||
mFiles = getFolders(mFiles);
|
||||
}
|
||||
|
||||
if (!mShowHiddenFiles) {
|
||||
mFiles = filterHiddenFiles(mFiles);
|
||||
}
|
||||
} else {
|
||||
mFiles = null;
|
||||
}
|
||||
|
@ -466,4 +474,23 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for hidden files
|
||||
*
|
||||
* @param files Collection of files to filter
|
||||
* @return Non-hidden files
|
||||
*/
|
||||
public Vector<OCFile> filterHiddenFiles(Vector<OCFile> files) {
|
||||
Vector<OCFile> ret = new Vector<>();
|
||||
OCFile current;
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
current = files.get(i);
|
||||
if (!current.isHidden()) {
|
||||
ret.add(current);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
|
@ -290,6 +291,12 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
|||
|
||||
mFiles = FileStorageUtils.sortLocalFolder(mFiles);
|
||||
|
||||
// Fetch preferences for showing hidden files
|
||||
boolean showHiddenFiles = PreferenceManager.showHiddenFilesEnabled(mContext);
|
||||
if (!showHiddenFiles) {
|
||||
mFiles = filterHiddenFiles(mFiles);
|
||||
}
|
||||
|
||||
mFilesAll.clear();
|
||||
|
||||
for (File mFile : mFiles) {
|
||||
|
@ -325,4 +332,20 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA
|
|||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for hidden files
|
||||
*
|
||||
* @param files Array of files to filter
|
||||
* @return Non-hidden files as an array
|
||||
*/
|
||||
public File[] filterHiddenFiles(File[] files) {
|
||||
List<File> ret = new ArrayList<>();
|
||||
for (File file: files) {
|
||||
if (!file.isHidden()) {
|
||||
ret.add(file);
|
||||
}
|
||||
}
|
||||
return ret.toArray(new File[ret.size()]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue