adding some helper extensions for checking if folders contain .nomedia
This commit is contained in:
parent
66567476ce
commit
88f977f3ed
4 changed files with 23 additions and 5 deletions
|
@ -7,7 +7,7 @@ buildscript {
|
||||||
propMinSdkVersion = 21
|
propMinSdkVersion = 21
|
||||||
propTargetSdkVersion = propCompileSdkVersion
|
propTargetSdkVersion = propCompileSdkVersion
|
||||||
propVersionCode = 1
|
propVersionCode = 1
|
||||||
propVersionName = '5.15.7'
|
propVersionName = '5.15.9'
|
||||||
kotlin_version = '1.3.41'
|
kotlin_version = '1.3.41'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package com.simplemobiletools.commons.extensions
|
package com.simplemobiletools.commons.extensions
|
||||||
|
|
||||||
import com.simplemobiletools.commons.helpers.audioExtensions
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.helpers.photoExtensions
|
|
||||||
import com.simplemobiletools.commons.helpers.rawExtensions
|
|
||||||
import com.simplemobiletools.commons.helpers.videoExtensions
|
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -77,3 +74,19 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int {
|
||||||
fun File.getDirectChildrenCount(countHiddenItems: Boolean) = listFiles()?.filter { if (countHiddenItems) true else !it.isHidden }?.size ?: 0
|
fun File.getDirectChildrenCount(countHiddenItems: Boolean) = listFiles()?.filter { if (countHiddenItems) true else !it.isHidden }?.size ?: 0
|
||||||
|
|
||||||
fun File.toFileDirItem() = FileDirItem(absolutePath, name, File(absolutePath).isDirectory, 0, length(), lastModified())
|
fun File.toFileDirItem() = FileDirItem(absolutePath, name, File(absolutePath).isDirectory, 0, length(), lastModified())
|
||||||
|
|
||||||
|
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
|
||||||
|
|
||||||
|
fun File.doesThisOrParentHaveNoMedia(): Boolean {
|
||||||
|
var curFile = this
|
||||||
|
while (true) {
|
||||||
|
if (curFile.containsNoMedia()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
curFile = curFile.parentFile ?: break
|
||||||
|
if (curFile.absolutePath == "/") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,10 @@ fun String.getGenericMimeType(): String {
|
||||||
|
|
||||||
fun String.getParentPath() = removeSuffix("/${getFilenameFromPath()}")
|
fun String.getParentPath() = removeSuffix("/${getFilenameFromPath()}")
|
||||||
|
|
||||||
|
fun String.containsNoMedia() = File(this).containsNoMedia()
|
||||||
|
|
||||||
|
fun String.doesThisOrParentHaveNoMedia() = File(this).doesThisOrParentHaveNoMedia()
|
||||||
|
|
||||||
fun String.getDuration() = getFileDurationSeconds()?.getFormattedDuration()
|
fun String.getDuration() = getFileDurationSeconds()?.getFormattedDuration()
|
||||||
|
|
||||||
fun String.getFileDurationSeconds(): Int? {
|
fun String.getFileDurationSeconds(): Int? {
|
||||||
|
|
|
@ -17,6 +17,7 @@ const val IS_FROM_GALLERY = "is_from_gallery"
|
||||||
const val BROADCAST_REFRESH_MEDIA = "com.simplemobiletools.REFRESH_MEDIA"
|
const val BROADCAST_REFRESH_MEDIA = "com.simplemobiletools.REFRESH_MEDIA"
|
||||||
const val REFRESH_PATH = "refresh_path"
|
const val REFRESH_PATH = "refresh_path"
|
||||||
const val IS_CUSTOMIZING_COLORS = "is_customizing_colors"
|
const val IS_CUSTOMIZING_COLORS = "is_customizing_colors"
|
||||||
|
const val NOMEDIA = ".nomedia"
|
||||||
const val ALARM_SOUND_TYPE_ALARM = 1
|
const val ALARM_SOUND_TYPE_ALARM = 1
|
||||||
const val ALARM_SOUND_TYPE_NOTIFICATION = 2
|
const val ALARM_SOUND_TYPE_NOTIFICATION = 2
|
||||||
const val YOUR_ALARM_SOUNDS_MIN_ID = 1000
|
const val YOUR_ALARM_SOUNDS_MIN_ID = 1000
|
||||||
|
|
Loading…
Reference in a new issue