Skip to content

Commit

Permalink
v1.37_beta
Browse files Browse the repository at this point in the history
  - Better loading status
  • Loading branch information
Hamza417 committed Mar 16, 2024
1 parent 58f027b commit a0d80db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
24 changes: 16 additions & 8 deletions app/src/main/java/app/simple/peri/utils/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.documentfile.provider.DocumentFile
import app.simple.peri.utils.StringUtils.endsWithAny
import java.text.CharacterIterator
import java.text.StringCharacterIterator
import java.util.Stack

object FileUtils {

Expand Down Expand Up @@ -39,17 +40,24 @@ object FileUtils {
return String.format("%.1f %cB", bytes / 1000.0, ci.current())
}

fun DocumentFile.listCompleteFiles(): List<DocumentFile> {
fun DocumentFile.listCompleteFiles(func: (String) -> Unit): List<DocumentFile> {
val allFiles = mutableListOf<DocumentFile>()
val stack = Stack<DocumentFile>()
stack.push(this)

listFiles().forEach { child ->
when {
child.isDirectory -> {
allFiles.addAll(child.listCompleteFiles()) // Recursive call for subdirectory
}
while (stack.isNotEmpty()) {
val currentFile = stack.pop()

currentFile.listFiles().forEach { child ->
when {
child.isDirectory -> {
func(child.name!!)
stack.push(child)
}

child.isFile -> {
allFiles.add(child)
child.isFile -> {
allFiles.add(child)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ class WallpaperViewModel(application: Application) : AndroidViewModel(applicatio

val uri = MainPreferences.getStorageUri()?.toUri()!!
val pickedDirectory = DocumentFile.fromTreeUri(getApplication(), uri)
loadingStatus.postValue("0 : 0%")
val files = pickedDirectory?.listCompleteFiles()
loadingStatus.postValue(getApplication<Application>().getString(app.simple.peri.R.string.preparing))
val files = pickedDirectory?.listCompleteFiles() {
loadingStatus.postValue(it)
}
var count = 0
val total = files?.size ?: 0

loadingStatus.postValue("0 : 0%")
files?.parallelStream()?.forEach { file ->
try {
val wallpaper = Wallpaper()
Expand Down

0 comments on commit a0d80db

Please sign in to comment.