11package com.tans.tfiletransporter.ui.filetransport
22
3- import android.os.Environment
43import android.view.View
54import androidx.core.content.ContextCompat
65import androidx.core.view.ViewCompat
@@ -41,7 +40,6 @@ import kotlinx.coroutines.flow.filter
4140import kotlinx.coroutines.flow.map
4241import kotlinx.coroutines.launch
4342import kotlinx.coroutines.withContext
44- import java.io.File
4543
4644
4745abstract class BaseMediaFragment (
@@ -57,10 +55,6 @@ abstract class BaseMediaFragment(
5755 (requireActivity() as FileTransportActivity ).fileExplore
5856 }
5957
60- private val androidRootDir: File by lazy {
61- Environment .getExternalStorageDirectory()
62- }
63-
6458 override fun CoroutineScope.firstLaunchInitDataCoroutine () {
6559 launch {
6660 refreshMediaItems()
@@ -206,9 +200,9 @@ abstract class BaseMediaFragment(
206200 launch(Dispatchers .IO ) {
207201 val currentState = currentState()
208202 val files = when (mediaType) {
209- MediaType .Image -> currentState.selectedImages.map { File ( File (androidRootDir, it.relativePath), it.displayName) }
210- MediaType .Video -> currentState.selectedVideos.map { File ( File (androidRootDir, it.relativePath), it.displayName) }
211- MediaType .Audio -> currentState.selectedAudios.map { File ( File (androidRootDir, it.relativePath), it.displayName) }
203+ MediaType .Image -> currentState.selectedImages.mapNotNull { it.file }
204+ MediaType .Video -> currentState.selectedVideos.mapNotNull { it.file }
205+ MediaType .Audio -> currentState.selectedAudios.mapNotNull { it.file }
212206 }.filter { it.isFile }
213207 val senderFiles = files.map { SenderFile (it, it.toFileExploreFile()) }
214208 if (senderFiles.isNotEmpty()) {
@@ -246,15 +240,15 @@ abstract class BaseMediaFragment(
246240 withContext(Dispatchers .IO ) {
247241 when (mediaType) {
248242 MediaType .Image -> {
249- val images = queryImageFromMediaStore().sortedByDescending { it.dateModified }
243+ val images = queryImageFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
250244 updateState { it.copy(selectedImages = emptyList(), images = images) }
251245 }
252246 MediaType .Video -> {
253- val videos = queryVideoFromMediaStore().sortedByDescending { it.dateModified }
247+ val videos = queryVideoFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
254248 updateState { it.copy(selectedVideos = emptyList(), videos = videos) }
255249 }
256250 MediaType .Audio -> {
257- val audios = queryAudioFromMediaStore().sortedByDescending { it.dateModified }
251+ val audios = queryAudioFromMediaStore().sortedByDescending { it.dateModified }.filter { it.file != null }
258252 updateState { it.copy(selectedAudios = emptyList(), audios = audios) }
259253 }
260254 }
0 commit comments