fix: test cases

This commit is contained in:
Saifuddin 2024-12-04 22:05:07 +05:30
parent 24181a8fb8
commit fcfb8255cc
2 changed files with 11 additions and 1 deletions

View file

@ -29,7 +29,6 @@ object FilePicker : Constants {
* Returns the uri of the clicked image so that it can be put in MediaStore
*/
@Throws(IOException::class)
@JvmStatic
private fun createCameraPictureFile(context: Context): Uri {
val imagePath = PickedFiles.getCameraPicturesLocation(context)

View file

@ -30,6 +30,7 @@ object PickedFiles : Constants {
* Get Folder Name
* @return default application folder name.
*/
@JvmStatic
private fun getFolderName(context: Context): String {
return FilePicker.configuration(context).getFolderName()
}
@ -38,6 +39,7 @@ object PickedFiles : Constants {
* tempImageDirectory
* @return temporary image directory to copy and perform exif changes.
*/
@JvmStatic
private fun tempImageDirectory(context: Context): File {
val privateTempDir = File(context.cacheDir, DEFAULT_FOLDER_NAME)
if (!privateTempDir.exists()) privateTempDir.mkdirs()
@ -48,6 +50,7 @@ object PickedFiles : Constants {
* writeToFile
* Writes inputStream data to the destination file.
*/
@JvmStatic
@Throws(IOException::class)
private fun writeToFile(inputStream: InputStream, file: File) {
inputStream.use { input ->
@ -66,6 +69,7 @@ object PickedFiles : Constants {
* Copies source file to destination file.
*/
@Throws(IOException::class)
@JvmStatic
private fun copyFile(src: File, dst: File) {
FileInputStream(src).use { inputStream ->
writeToFile(inputStream, dst)
@ -76,6 +80,7 @@ object PickedFiles : Constants {
* Copy files in separate thread.
* Copies all the uploadable files to the temp image folder on background thread.
*/
@JvmStatic
fun copyFilesInSeparateThread(context: Context, filesToCopy: List<UploadableFile>) {
Thread {
val copiedFiles = mutableListOf<File>()
@ -112,6 +117,7 @@ object PickedFiles : Constants {
* singleFileList
* Converts a single uploadableFile to list of uploadableFile.
*/
@JvmStatic
fun singleFileList(file: UploadableFile): List<UploadableFile> {
return listOf(file)
}
@ -120,6 +126,7 @@ object PickedFiles : Constants {
* ScanCopiedImages
* Scans copied images metadata using media scanner.
*/
@JvmStatic
fun scanCopiedImages(context: Context, copiedImages: List<File>) {
val paths = copiedImages.map { it.toString() }.toTypedArray()
MediaScannerConnection.scanFile(context, paths, null) { path, uri ->
@ -133,6 +140,7 @@ object PickedFiles : Constants {
* Convert the image into uploadable file.
*/
@Throws(IOException::class, SecurityException::class)
@JvmStatic
fun pickedExistingPicture(context: Context, photoUri: Uri): UploadableFile {
val directory = tempImageDirectory(context)
val mimeType = getMimeType(context, photoUri)
@ -152,6 +160,7 @@ object PickedFiles : Constants {
* getCameraPictureLocation
*/
@Throws(IOException::class)
@JvmStatic
fun getCameraPicturesLocation(context: Context): File {
val dir = tempImageDirectory(context)
return File.createTempFile(UUID.randomUUID().toString(), ".jpg", dir)
@ -160,6 +169,7 @@ object PickedFiles : Constants {
/**
* To find out the extension of the required object in a given uri
*/
@JvmStatic
private fun getMimeType(context: Context, uri: Uri): String {
return if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
context.contentResolver.getType(uri)
@ -176,6 +186,7 @@ object PickedFiles : Constants {
* @param file get uri of file
* @return uri of requested file.
*/
@JvmStatic
fun getUriToFile(context: Context, file: File): Uri {
val packageName = context.applicationContext.packageName
val authority = "$packageName.provider"