mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
fix: test cases
This commit is contained in:
parent
24181a8fb8
commit
fcfb8255cc
2 changed files with 11 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue