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

View file

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