Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class IONCAMRCameraManager(
activity: Activity,
intent: Intent?,
camParameters: IONCAMRCameraParameters,
onImage: (String) -> Unit,
onMediaResult: (IONCAMRMediaResult) -> Unit,
onError: (IONCAMRError) -> Unit
) {
Expand Down Expand Up @@ -235,12 +234,10 @@ class IONCAMRCameraManager(

mediaProcessor.processCameraImage(
activity = activity,
intent = intent,
sourcePath = sourcePath,
"$applicationId$AUTHORITY",
camParameters = camParameters,
savedSuccessfully = savedSuccessfully,
onImage = onImage,
onMediaResult = onMediaResult,
onError = onError
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ data class IONCAMRCameraParameters(
@SerializedName("allowEdit") val allowEdit: Boolean,
@SerializedName("correctOrientation") val correctOrientation: Boolean,
@SerializedName("saveToPhotoAlbum") val saveToPhotoAlbum: Boolean,
@SerializedName("includeMetadata") val includeMetadata: Boolean,
@SerializedName("latestVersion") val latestVersion: Boolean
@SerializedName("includeMetadata") val includeMetadata: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -189,73 +189,39 @@ class IONCAMRMediaProcessor(

fun processCameraImage(
activity: Activity,
intent: Intent?,
sourcePath: String?,
authority: String,
camParameters: IONCAMRCameraParameters,
savedSuccessfully: Boolean,
onImage: (String) -> Unit,
onMediaResult: (IONCAMRMediaResult) -> Unit,
onError: (IONCAMRError) -> Unit
) {
var bitmap: Bitmap?
if (camParameters.latestVersion) {

val mediaResult =
sourcePath?.let {
val imageUri = fileHelper.getUriForFile(
activity,
authority,
File(sourcePath)
)
if (imageUri == null) {
onError(IONCAMRError.TAKE_PHOTO_ERROR)
return
}
createImageMediaResult(
activity,
it,
imageUri,
camParameters.includeMetadata,
camParameters,
savedSuccessfully
)
}

if (mediaResult == null) {
onError(IONCAMRError.TAKE_PHOTO_ERROR)
return
}
onMediaResult(mediaResult)
} else {
//get bitmap
bitmap = sourcePath?.let { getScaledAndRotatedBitmap(activity, it, camParameters) }
if (bitmap == null) {
// Try to get the bitmap from intent.
if (intent != null) {
try {
// getExtras can throw different exceptions
val extras = intent.extras
if (extras != null) {
bitmap = extras["data"] as Bitmap?
}
} catch (e: Exception) {
// Don't let the exception bubble up, bitmap will be null (check below)
}
val mediaResult =
sourcePath?.let {
val imageUri = fileHelper.getUriForFile(
activity,
authority,
File(sourcePath)
)
if (imageUri == null) {
onError(IONCAMRError.TAKE_PHOTO_ERROR)
return
}
createImageMediaResult(
activity,
it,
imageUri,
camParameters.includeMetadata,
camParameters,
savedSuccessfully
)
}

//get base64 representation of bitmap
imageHelper.processPicture(
bitmap, camParameters.encodingType, camParameters.mQuality,
{
onImage(it)
},
{
onError(it)
}
)
if (mediaResult == null) {
onError(IONCAMRError.TAKE_PHOTO_ERROR)
return
}
onMediaResult(mediaResult)
}

fun processEditedImage(
Expand Down
30 changes: 10 additions & 20 deletions src/test/kotlin/io/ionic/libs/ioncameralib/ChoosePictureTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -125,8 +124,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -171,8 +169,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -217,8 +214,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = false,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -264,8 +260,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -312,8 +307,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -361,8 +355,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -409,8 +402,7 @@ class ChoosePictureTests {
allowEdit = false,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -457,8 +449,7 @@ class ChoosePictureTests {
allowEdit = true,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down Expand Up @@ -512,8 +503,7 @@ class ChoosePictureTests {
allowEdit = true,
correctOrientation = true,
saveToPhotoAlbum = false,
includeMetadata = false,
latestVersion = false
includeMetadata = false
)

val exifHelperMock = IONExifHelperMock()
Expand Down
114 changes: 0 additions & 114 deletions src/test/kotlin/io/ionic/libs/ioncameralib/EditPictureTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import android.os.Environment
import android.util.Base64
import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import io.ionic.libs.ioncameralib.manager.IONCAMRCameraManager
import io.ionic.libs.ioncameralib.manager.IONCAMREditManager
import io.ionic.libs.ioncameralib.mocks.IONExifHelperMock
import io.ionic.libs.ioncameralib.mocks.IONCAMRFileHelperMock
import io.ionic.libs.ioncameralib.mocks.IONCAMRImageHelperMock
import io.ionic.libs.ioncameralib.mocks.IONCAMRMediaHelperMock
import io.ionic.libs.ioncameralib.model.IONCAMRCameraParameters
import io.ionic.libs.ioncameralib.model.IONCAMREditParameters
import io.ionic.libs.ioncameralib.model.IONCAMRError
import io.ionic.libs.ioncameralib.view.IONCAMRImageEditorActivity
Expand Down Expand Up @@ -58,7 +56,6 @@ class EditPictureTests {
)

companion object{
private const val PROCESS_SUCCESS = "myImage"
private const val FILE_LOCATION = "file://content/storage/emulated/sampleFileLocation"
private const val BASE_64 = "base64"
private const val METADATA_SIZE = 23456L
Expand Down Expand Up @@ -163,117 +160,6 @@ class EditPictureTests {
})
}

@Test
fun givenTakePictureAllowEditWhenEditProcessSuccessThenSuccess() {

val camParameters = IONCAMRCameraParameters(
20,
-1,
-1,
0,
0,
allowEdit = true,
correctOrientation = true,
saveToPhotoAlbum = true,
includeMetadata = false,
latestVersion = false
)

val exifHelperMock = IONExifHelperMock()
val fileHelperMock = IONCAMRFileHelperMock()
val camHelperMock = IONCAMRMediaHelperMock()
val imgHelperMock = IONCAMRImageHelperMock()

val IONCAMRCameraManager = IONCAMRCameraManager(
"someAppId",
exifHelperMock,
fileHelperMock,
camHelperMock,
imgHelperMock
)
val IONCAMREditManager = IONCAMREditManager(
"someAppId",
exifHelperMock,
fileHelperMock,
camHelperMock,
imgHelperMock
)

Mockito.`when`(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)).thenReturn(mFile)

imgHelperMock.processPicSuccess = true
imgHelperMock.areOptionsZero = false

IONCAMRCameraManager.takePicture(mockActivity, 0, 0)
IONCAMREditManager.openCropActivity(null, mUri, mActivityLauncher)
IONCAMRCameraManager.processResultFromCamera(mockActivity, mIntent, camParameters,
onImage = {
assertEquals(it, PROCESS_SUCCESS)
},
onMediaResult = {
fail()
},
onError = {
fail()
})
}

@Test
fun givenTakePictureAllowEditWhenEditProcessErrorThenError() {

val camParameters = IONCAMRCameraParameters(
20,
-1,
-1,
0,
0,
allowEdit = true,
correctOrientation = true,
saveToPhotoAlbum = true,
includeMetadata = false,
latestVersion = false
)

val exifHelperMock = IONExifHelperMock()
val fileHelperMock = IONCAMRFileHelperMock()
val camHelperMock = IONCAMRMediaHelperMock()
val imgHelperMock = IONCAMRImageHelperMock()

val IONCAMRCameraManager = IONCAMRCameraManager(
"someAppId",
exifHelperMock,
fileHelperMock,
camHelperMock,
imgHelperMock
)
val IONCAMREditManager = IONCAMREditManager(
"someAppId",
exifHelperMock,
fileHelperMock,
camHelperMock,
imgHelperMock
)

Mockito.`when`(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)).thenReturn(mFile)

imgHelperMock.processPicSuccess = false
imgHelperMock.areOptionsZero = false

IONCAMRCameraManager.takePicture(mockActivity, 0, 0)
IONCAMREditManager.openCropActivity(null, mUri, mActivityLauncher)
IONCAMRCameraManager.processResultFromCamera(mockActivity, mIntent, camParameters,
onImage = {
fail()
},
onMediaResult = {
fail()
},
onError = {
assertEquals(it.code, IONCAMRError.PROCESS_IMAGE_ERROR.code)
assertEquals(it.description, IONCAMRError.PROCESS_IMAGE_ERROR.description)
})
}

@Test
fun givenFileDoesNotExistWhenEditURIPictureThenError() {

Expand Down
Loading
Loading