From 933558caf8266677dc26497d7c7b930254f4fb07 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 9 Dec 2021 08:11:44 +0530 Subject: [PATCH] Prevent Git files from turning up in search and listing (#1582) * Prevent Git files from turning up in search and listing * Update changelog --- CHANGELOG.md | 1 + .../aps/util/viewmodel/SearchableRepositoryViewModel.kt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3edf1d7ed..0af19d85a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ All notable changes to this project will be documented in this file. - Changing password generator parameters now automatically updates the password without needing to press the 'Generate' button again - The app UI was reskinned to match Google's Material You guidelines - Using HTTPS without authentication is now fully supported, and no longer asks for a username +- Enabling 'Show hidden files and folders' no longer shows Git-related files and folders ## [1.13.5] - 2021-07-28 diff --git a/app/src/main/java/dev/msfjarvis/aps/util/viewmodel/SearchableRepositoryViewModel.kt b/app/src/main/java/dev/msfjarvis/aps/util/viewmodel/SearchableRepositoryViewModel.kt index 1c1b6aeee..a8af961a8 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/viewmodel/SearchableRepositoryViewModel.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/viewmodel/SearchableRepositoryViewModel.kt @@ -242,7 +242,9 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel private fun shouldTake(file: File) = with(file) { - if (showHiddenContents) return true + if (showHiddenContents) { + return !file.name.startsWith(".git") + } if (isDirectory) { !isHidden } else { @@ -251,7 +253,7 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel } private fun listFiles(dir: File): Flow { - return dir.listFiles { file -> shouldTake(file) }?.asFlow() ?: emptyFlow() + return dir.listFiles(::shouldTake)?.asFlow() ?: emptyFlow() } private fun listFilesRecursively(dir: File): Flow { @@ -266,7 +268,7 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel yield() it } - .filter { file -> shouldTake(file) } + .filter(::shouldTake) } private val _currentDir = MutableLiveData(root)