diff --git a/.gitignore b/.gitignore index aa724b7..3df0749 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .externalNativeBuild .cxx local.properties +/.idea/runConfigurations.xml diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentAdapter.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentLister.kt similarity index 90% rename from app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentAdapter.kt rename to app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentLister.kt index c7fbe4b..c451cf2 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentAdapter.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/DocumentLister.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.io.File -class DocumentLister : Lister() { +class DocumentLister : Lister { companion object { val instance by lazy { DocumentLister() } val directories = listOf("Documents", "Download") @@ -31,7 +31,7 @@ class DocumentLister : Lister() { return } - fun dateOrderedList(): List { + override fun dateOrderedList(): List { val wrappedFileList = mutableListOf() documentList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.lastModifiedTime } @@ -40,7 +40,7 @@ class DocumentLister : Lister() { return result } - fun sizeOrderedList(): List { + override fun sizeOrderedList(): List { val wrappedFileList = mutableListOf() documentList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.size } @@ -49,7 +49,7 @@ class DocumentLister : Lister() { return result } - fun getFullSize(): ULong { + override fun getFullSize(): ULong { var size = 0UL val wrappedFileList = mutableListOf() documentList.forEach { wrappedFileList.add(WrappedFile(File(it))) } diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/ImageLister.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/ImageLister.kt index cd21a02..01cdfeb 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/ImageLister.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/ImageLister.kt @@ -7,14 +7,14 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.io.File -class ImageLister private constructor() : Lister() { +class ImageLister private constructor() : Lister { companion object { val instance by lazy { ImageLister() } val directories = listOf("DCIM", "Pictures", "Download") - val regex = "\\.(jpg|png|jpeg|webp)".toRegex() + val regex = "\\.(jpg|png|jpeg|webp)$".toRegex() } - val imageList = mutableListOf() + private val imageList = mutableListOf() fun initialize(onFinished: (() -> Unit)? = null) { imageList.clear() @@ -31,7 +31,7 @@ class ImageLister private constructor() : Lister() { return } - fun dateOrderedList(): List { + override fun dateOrderedList(): List { val wrappedFileList = mutableListOf() imageList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.lastModifiedTime } @@ -40,7 +40,7 @@ class ImageLister private constructor() : Lister() { return result } - fun sizeOrderedList(): List { + override fun sizeOrderedList(): List { val wrappedFileList = mutableListOf() imageList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.size } @@ -49,7 +49,7 @@ class ImageLister private constructor() : Lister() { return result } - fun getFullSize(): ULong { + override fun getFullSize(): ULong { var size = 0UL val wrappedFileList = mutableListOf() imageList.forEach { wrappedFileList.add(WrappedFile(File(it))) } diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Lister.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Lister.kt index b5aac21..0dd9775 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Lister.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Lister.kt @@ -1,4 +1,34 @@ package com.example.myapplication.fileSystem.byTypeFileLister -abstract class Lister { -} \ No newline at end of file +import java.io.File + +interface Lister { + fun dateOrderedList(): List + + fun sizeOrderedList(): List + + fun getFullSize(): ULong + + fun walkDir( + directory: File, + list: MutableList, + pattern: Regex, + ignoreDotFile: Boolean = true + ) { + if (!directory.exists() || !directory.isDirectory) { + return + } + directory.listFiles()?.forEach { + if (ignoreDotFile && !it.name.startsWith(".")) { + if (it.isDirectory) { + walkDir(it, list, pattern) + } else if (it.isFile) { + if (it.name.contains(pattern)) { + list.add(it.path) + } + } + } + } + } + +} diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/MusicLister.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/MusicLister.kt index bbcc82b..cb4642b 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/MusicLister.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/MusicLister.kt @@ -7,15 +7,15 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.io.File -class MusicLister : Lister() { +class MusicLister : Lister { companion object { val instance by lazy { MusicLister() } val directories = listOf("Recordings", "Download", "Audiobooks", "Music", "Podcasts", "Ringtones") - val regex = "\\.(mp3|ogg|aac|wav)".toRegex() + val regex = "\\.(mp3|ogg|aac|wav)$".toRegex() } - val musicList = mutableListOf() + private val musicList = mutableListOf() fun initialize(onFinished: (() -> Unit)? = null) { musicList.clear() @@ -32,7 +32,7 @@ class MusicLister : Lister() { return } - fun dateOrderedList(): List { + override fun dateOrderedList(): List { val wrappedFileList = mutableListOf() musicList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.lastModifiedTime } @@ -41,7 +41,7 @@ class MusicLister : Lister() { return result } - fun sizeOrderedList(): List { + override fun sizeOrderedList(): List { val wrappedFileList = mutableListOf() musicList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.size } @@ -50,7 +50,7 @@ class MusicLister : Lister() { return result } - fun getFullSize(): ULong { + override fun getFullSize(): ULong { var size = 0UL val wrappedFileList = mutableListOf() musicList.forEach { wrappedFileList.add(WrappedFile(File(it))) } diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/VideoLister.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/VideoLister.kt index 5e97380..acb204a 100644 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/VideoLister.kt +++ b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/VideoLister.kt @@ -7,11 +7,11 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.io.File -class VideoLister : Lister() { +class VideoLister : Lister { companion object { val instance by lazy { VideoLister() } val directories = listOf("DCIM", "Download", "Movies") - val regex = "\\.(mp4|avi|video|webm)".toRegex() + val regex = "\\.(mp4|avi|video|webm)$".toRegex() } val videoList = mutableListOf() @@ -31,7 +31,7 @@ class VideoLister : Lister() { return } - fun dateOrderedList(): List { + override fun dateOrderedList(): List { val wrappedFileList = mutableListOf() videoList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.lastModifiedTime } @@ -40,7 +40,7 @@ class VideoLister : Lister() { return result } - fun sizeOrderedList(): List { + override fun sizeOrderedList(): List { val wrappedFileList = mutableListOf() videoList.forEach { wrappedFileList.add(WrappedFile(File(it))) } wrappedFileList.sortBy { it.size } @@ -49,7 +49,7 @@ class VideoLister : Lister() { return result } - fun getFullSize(): ULong { + override fun getFullSize(): ULong { var size = 0UL val wrappedFileList = mutableListOf() videoList.forEach { wrappedFileList.add(WrappedFile(File(it))) } diff --git a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Walker.kt b/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Walker.kt deleted file mode 100644 index 988eb25..0000000 --- a/app/src/main/java/com/example/myapplication/fileSystem/byTypeFileLister/Walker.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.myapplication.fileSystem.byTypeFileLister - -import java.io.File - -fun Lister.walkDir( - directory: File, - list: MutableList, - pattern: Regex, - ignoreDotFile: Boolean = true -) { - if (!directory.exists() || !directory.isDirectory) { - return - } - directory.listFiles()?.forEach { - if (ignoreDotFile && !it.name.startsWith(".")) { - if (it.isDirectory) { - walkDir(it, list, pattern) - } else if (it.isFile) { - if (it.name.contains(pattern)) { - list.add(it.path) - } - } - } - } -} \ No newline at end of file