From 74140b1665f5ea67eb0b4827f6b5ac8f5765ec77 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 21 Feb 2018 15:57:45 +0100 Subject: [PATCH] adding a null check at handling Edit Photo result --- .../contacts/activities/EditContactActivity.kt | 9 +++++++-- .../com/simplemobiletools/contacts/helpers/DBHelper.kt | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index 6d70b9f8..bb10ac81 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -94,7 +94,7 @@ class EditContactActivity : ContactActivity() { super.onActivityResult(requestCode, resultCode, resultData) if (resultCode == RESULT_OK) { when (requestCode) { - INTENT_TAKE_PHOTO, INTENT_CHOOSE_PHOTO -> startCropPhotoIntent(lastPhotoIntentUri!!) + INTENT_TAKE_PHOTO, INTENT_CHOOSE_PHOTO -> startCropPhotoIntent(lastPhotoIntentUri) INTENT_CROP_PHOTO -> updateContactPhoto(lastPhotoIntentUri.toString(), contact_photo) } } @@ -190,7 +190,12 @@ class EditContactActivity : ContactActivity() { invalidateOptionsMenu() } - private fun startCropPhotoIntent(uri: Uri) { + private fun startCropPhotoIntent(uri: Uri?) { + if (uri == null) { + toast(R.string.unknown_error_occurred) + return + } + lastPhotoIntentUri = getCachePhotoUri() Intent("com.android.camera.action.CROP").apply { setDataAndType(uri, "image/*") diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 52255721..f598e576 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -35,7 +35,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val FIRST_CONTACT_ID = 1000000 - private val mDb: SQLiteDatabase = writableDatabase + private val mDb = writableDatabase companion object { private const val DB_VERSION = 1