mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	fix #231, add helper function for un/hiding items
This commit is contained in:
		| @@ -45,7 +45,7 @@ ext { | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     implementation 'com.simplemobiletools:commons:4.4.9' | ||||
|     implementation 'com.simplemobiletools:commons:4.4.10' | ||||
|  | ||||
|     implementation files('../libs/RootTools.jar') | ||||
|  | ||||
|   | ||||
| @@ -66,6 +66,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|             findItem(R.id.cab_copy_path).isVisible = isOneItemSelected() | ||||
|             findItem(R.id.cab_open_with).isVisible = isOneFileSelected() | ||||
|             findItem(R.id.cab_set_as).isVisible = isOneFileSelected() | ||||
|  | ||||
|             checkHideBtnVisibility(this) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -85,6 +87,8 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|             R.id.cab_rename -> displayRenameDialog() | ||||
|             R.id.cab_properties -> showProperties() | ||||
|             R.id.cab_share -> shareFiles() | ||||
|             R.id.cab_hide -> toggleFileVisibility(true) | ||||
|             R.id.cab_unhide -> toggleFileVisibility(false) | ||||
|             R.id.cab_copy_path -> copyPath() | ||||
|             R.id.cab_set_as -> setAs() | ||||
|             R.id.cab_open_with -> openWith() | ||||
| @@ -123,6 +127,21 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|  | ||||
|     private fun isOneFileSelected() = isOneItemSelected() && !fileDirItems[selectedPositions.first()].isDirectory | ||||
|  | ||||
|     private fun checkHideBtnVisibility(menu: Menu) { | ||||
|         var hiddenCnt = 0 | ||||
|         var unhiddenCnt = 0 | ||||
|         selectedPositions.mapNotNull { fileDirItems.getOrNull(it)?.name }.forEach { | ||||
|             if (it.startsWith(".")) { | ||||
|                 hiddenCnt++ | ||||
|             } else { | ||||
|                 unhiddenCnt++ | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 | ||||
|         menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 | ||||
|     } | ||||
|  | ||||
|     private fun confirmSelection() { | ||||
|         if (selectedPositions.isNotEmpty()) { | ||||
|             val paths = getSelectedMedia().filter { !it.isDirectory }.map { it.path } as ArrayList<String> | ||||
| @@ -160,6 +179,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD | ||||
|         activity.sharePaths(paths) | ||||
|     } | ||||
|  | ||||
|     private fun toggleFileVisibility(hide: Boolean) { | ||||
|         Thread { | ||||
|             getSelectedMedia().forEach { | ||||
|                 activity.toggleItemVisibility(it.path, hide) | ||||
|             } | ||||
|             activity.runOnUiThread { | ||||
|                 listener?.refreshItems() | ||||
|                 finishActMode() | ||||
|             } | ||||
|         }.start() | ||||
|     } | ||||
|  | ||||
|     private fun addFileUris(path: String, paths: ArrayList<String>) { | ||||
|         if (activity.getIsPathDirectory(path)) { | ||||
|             val shouldShowHidden = activity.config.shouldShowHidden | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import android.content.Intent | ||||
| import android.net.Uri | ||||
| import android.support.v4.content.FileProvider | ||||
| import com.simplemobiletools.commons.R | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.isNougatPlus | ||||
| import com.simplemobiletools.filemanager.BuildConfig | ||||
| @@ -46,3 +47,25 @@ fun Activity.openPath(path: String, forceChooser: Boolean, openAsText: Boolean = | ||||
| fun Activity.setAs(path: String) { | ||||
|     setAsIntent(path, BuildConfig.APPLICATION_ID) | ||||
| } | ||||
|  | ||||
| fun BaseSimpleActivity.toggleItemVisibility(oldPath: String, hide: Boolean, callback: ((newPath: String) -> Unit)? = null) { | ||||
|     val path = oldPath.getParentPath() | ||||
|     var filename = oldPath.getFilenameFromPath() | ||||
|     if ((hide && filename.startsWith('.')) || (!hide && !filename.startsWith('.'))) { | ||||
|         callback?.invoke(oldPath) | ||||
|         return | ||||
|     } | ||||
|  | ||||
|     filename = if (hide) { | ||||
|         ".${filename.trimStart('.')}" | ||||
|     } else { | ||||
|         filename.substring(1, filename.length) | ||||
|     } | ||||
|  | ||||
|     val newPath = "$path/$filename" | ||||
|     if (oldPath != newPath) { | ||||
|         renameFile(oldPath, newPath) { | ||||
|             callback?.invoke(newPath) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -21,6 +21,16 @@ | ||||
|         android:icon="@drawable/ic_share" | ||||
|         android:title="@string/share" | ||||
|         app:showAsAction="ifRoom"/> | ||||
|     <item | ||||
|         android:id="@+id/cab_hide" | ||||
|         android:icon="@drawable/ic_hide" | ||||
|         android:title="@string/hide" | ||||
|         app:showAsAction="ifRoom"/> | ||||
|     <item | ||||
|         android:id="@+id/cab_unhide" | ||||
|         android:icon="@drawable/ic_unhide" | ||||
|         android:title="@string/unhide" | ||||
|         app:showAsAction="ifRoom"/> | ||||
|     <item | ||||
|         android:id="@+id/cab_copy_path" | ||||
|         android:title="@string/copy_path" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user