Skip to content

Commit

Permalink
-local file reading
Browse files Browse the repository at this point in the history
-content resolver for local filels
  • Loading branch information
rrpvm committed May 2, 2023
1 parent 65b6eee commit e6a6aff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GifDataSourceBuilder(
return GifRequestBuilder(
context,
videoGifSource = localPath,
LocalFileDataSource(localPath),
LocalFileDataSource(localPath, context),
cacheRepository = repository,
workManager = workManager
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package com.rrpvm.gif_loader.common.data_source

import android.content.Context
import androidx.core.net.toUri
import com.rrpvm.gif_loader.domain.entity.GifLoaderRequestCacheStrategy
import com.rrpvm.gif_loader.domain.entity.IGifDataSource
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException

class LocalFileDataSource(private val path: String) : IGifDataSource {
class LocalFileDataSource(
private val path: String,
private val context: Context
) : IGifDataSource {
/* @kotlin.jvm.Throws(IOException::class, NullPointerException::class)
override fun getVideoSource(cacheStrategy: GifLoaderRequestCacheStrategy): ByteArray {
return File(path).inputStream().use { input ->
return@use input.readBytes()
}
}*/
@kotlin.jvm.Throws(IOException::class, NullPointerException::class)
override fun getVideoSource(cacheStrategy: GifLoaderRequestCacheStrategy): ByteArray {
return File(path).inputStream().use { input ->
return@use input.readBytes()
return context.contentResolver.openInputStream(path.toUri()).use { input ->
return@use input?.readBytes() ?: throw FileNotFoundException()
}
}
}

0 comments on commit e6a6aff

Please # to comment.