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 * Returns the uri of the clicked image so that it can be put in MediaStore
*/ */
@Throws(IOException::class) @Throws(IOException::class)
@JvmStatic @JvmStatic
private fun createCameraPictureFile(context: Context): Uri { private fun createCameraPictureFile(context: Context): Uri {
val imagePath = PickedFiles.getCameraPicturesLocation(context) val imagePath = PickedFiles.getCameraPicturesLocation(context)

View file

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