Skip to content

Commit

Permalink
[fix] Fix Android 10 and blow version can't get media files.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanpengcheng committed Apr 22, 2024
1 parent 58cddae commit 2da8315
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tans.tfiletransporter.ui.filetransport

import android.os.Environment
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -41,7 +40,6 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File


abstract class BaseMediaFragment(
Expand All @@ -57,10 +55,6 @@ abstract class BaseMediaFragment(
(requireActivity() as FileTransportActivity).fileExplore
}

private val androidRootDir: File by lazy {
Environment.getExternalStorageDirectory()
}

override fun CoroutineScope.firstLaunchInitDataCoroutine() {
launch {
refreshMediaItems()
Expand Down Expand Up @@ -206,9 +200,9 @@ abstract class BaseMediaFragment(
launch(Dispatchers.IO) {
val currentState = currentState()
val files = when (mediaType) {
MediaType.Image -> currentState.selectedImages.map { File(File(androidRootDir, it.relativePath), it.displayName) }
MediaType.Video -> currentState.selectedVideos.map { File(File(androidRootDir, it.relativePath), it.displayName) }
MediaType.Audio -> currentState.selectedAudios.map { File(File(androidRootDir, it.relativePath), it.displayName) }
MediaType.Image -> currentState.selectedImages.mapNotNull { it.file }
MediaType.Video -> currentState.selectedVideos.mapNotNull { it.file }
MediaType.Audio -> currentState.selectedAudios.mapNotNull { it.file }
}.filter { it.isFile }
val senderFiles = files.map { SenderFile(it, it.toFileExploreFile()) }
if (senderFiles.isNotEmpty()) {
Expand Down Expand Up @@ -246,15 +240,15 @@ abstract class BaseMediaFragment(
withContext(Dispatchers.IO) {
when (mediaType) {
MediaType.Image -> {
val images = queryImageFromMediaStore().sortedByDescending { it.dateModified }
val images = queryImageFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
updateState { it.copy(selectedImages = emptyList(), images = images) }
}
MediaType.Video -> {
val videos = queryVideoFromMediaStore().sortedByDescending { it.dateModified }
val videos = queryVideoFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
updateState { it.copy(selectedVideos = emptyList(), videos = videos) }
}
MediaType.Audio -> {
val audios = queryAudioFromMediaStore().sortedByDescending { it.dateModified }
val audios = queryAudioFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
updateState { it.copy(selectedAudios = emptyList(), audios = audios) }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.tans.tfiletransporter.ui.filetransport

class MyImagesFragment : BaseMediaFragment(mediaType = Companion.MediaType.Image)
class MyImagesFragment : BaseMediaFragment(Companion.MediaType.Image)
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ androidJunit = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.11.0"
activity = "1.8.2"
activity = "1.9.0"
annotaion = "1.7.1"
constraintlayout = "2.1.4"
swiperefreshlayout = "1.1.0"
Expand All @@ -23,12 +23,12 @@ moshi = "1.15.1"
netty = "4.1.86.Final"
okio = "3.6.0"
rxbinding = "4.0.0"
camerax = "1.3.2"
camerax = "1.3.3"
barcodescan = "17.2.0"
qrcodegen = "3.0.1"
threetenabp = "1.4.6"
glide = "4.16.0"
tuiutils = "1.0.4"
tuiutils = "1.0.5"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down

0 comments on commit 2da8315

Please sign in to comment.