Improve the Mp3 song search functionality to search throughout the external storage device and excluding Notification, Android, and Notifications directories #29
This commit is contained in:
committed by
amazing-username
parent
b2a70de4b2
commit
971da4b9d2
@@ -3,8 +3,13 @@ package com.example.mear.management
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
|
||||
import com.example.mear.constants.DirectoryIgnore
|
||||
import com.example.mear.constants.FileTypes
|
||||
|
||||
class MusicFiles (private val demoPath: File) {
|
||||
|
||||
fun demoSearch() {
|
||||
}
|
||||
|
||||
fun loadAllMusicPaths() {
|
||||
try {
|
||||
@@ -41,6 +46,53 @@ class MusicFiles (private val demoPath: File) {
|
||||
}
|
||||
|
||||
|
||||
fun searchForMp3Songs() {
|
||||
try {
|
||||
var pathList: MutableList<String>? = null
|
||||
pathList = mutableListOf()
|
||||
|
||||
var fileSearch = File(demoPath.absolutePath)
|
||||
fileSearch.walkTopDown().forEach {
|
||||
println(it.absolutePath)
|
||||
if (!ignoreThisDirectory(it.absolutePath)) {
|
||||
if (it.isFile) {
|
||||
if (it.endsWith(FileTypes.Mp3)) {
|
||||
pathList.add(it.absolutePath)
|
||||
}
|
||||
if (it.extension.toString().equals(FileTypes.Mp3)) {
|
||||
pathList.add(it.absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
allSongs = pathList
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
val exMsg = ex.message
|
||||
}
|
||||
}
|
||||
|
||||
private fun ignoreThisDirectory(path: String): Boolean {
|
||||
var ignoreDirectory = false
|
||||
try {
|
||||
if (path.contains(DirectoryIgnore.Android_Root)) {
|
||||
ignoreDirectory = true
|
||||
}
|
||||
if (path.contains(DirectoryIgnore.Notifications)) {
|
||||
ignoreDirectory = true
|
||||
}
|
||||
if (path.contains(DirectoryIgnore.Ringtones)) {
|
||||
ignoreDirectory = true
|
||||
}
|
||||
return ignoreDirectory
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
val exMsg = ex.message
|
||||
}
|
||||
return ignoreDirectory
|
||||
}
|
||||
|
||||
var allSongs: MutableList<String>?= null
|
||||
val musicSongLimit = Int.MAX_VALUE
|
||||
|
||||
private val musicSongLimit = Int.MAX_VALUE
|
||||
}
|
||||
Reference in New Issue
Block a user