class OpenPhotoFromFile(private val activity: AppCompatActivity) : Example(activity) {
override fun invoke() {
val file = File(activity.cacheDir, "imgly_photo.jpg")
if (!file.exists()) {
showMessage("File does not exist")
return
}
val settingsList = PhotoEditorSettingsList(false)
.configure<LoadSettings> {
it.source = Uri.fromFile(file)
}
PhotoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
settingsList.release()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
intent ?: return
if (requestCode == EDITOR_REQUEST_CODE) {
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
}
}