add an extra check at creating .nomedia file on the SD card

This commit is contained in:
tibbi 2017-10-19 19:13:12 +02:00
parent 7132e09047
commit 2dbbc2bbdb
2 changed files with 10 additions and 8 deletions

View file

@ -123,11 +123,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (File(it).containsNoMedia()) if (File(it).containsNoMedia()) {
hiddenCnt++ hiddenCnt++
else } else {
unhiddenCnt++ unhiddenCnt++
} }
}
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
@ -138,11 +139,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
var pinnedCnt = 0 var pinnedCnt = 0
var unpinnedCnt = 0 var unpinnedCnt = 0
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (pinnedFolders.contains(it)) if (pinnedFolders.contains(it)) {
pinnedCnt++ pinnedCnt++
else } else {
unpinnedCnt++ unpinnedCnt++
} }
}
menu.findItem(R.id.cab_pin).isVisible = unpinnedCnt > 0 menu.findItem(R.id.cab_pin).isVisible = unpinnedCnt > 0
menu.findItem(R.id.cab_unpin).isVisible = pinnedCnt > 0 menu.findItem(R.id.cab_unpin).isVisible = pinnedCnt > 0

View file

@ -224,12 +224,12 @@ fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
if (needsStupidWritePermissions(path)) { if (needsStupidWritePermissions(path)) {
handleSAFDialog(file) { handleSAFDialog(file) {
try { val fileDocument = getFileDocument(path)
getFileDocument(path)?.createFile("", NOMEDIA) if (fileDocument?.exists() == true && fileDocument.isDirectory) {
} catch (e: Exception) { fileDocument.createFile("", NOMEDIA)
} else
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
}
} else { } else {
try { try {
file.createNewFile() file.createNewFile()