diff --git a/app/build.gradle b/app/build.gradle index 19a6fd0e..f7c5bd5b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:5cec51606a' + implementation 'com.github.SimpleMobileTools:Simple-Commons:8084f88f20' implementation 'joda-time:joda-time:2.10.3' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt index f24a95ce..3c9c25b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.contacts.pro.activities import android.app.Activity +import android.content.ActivityNotFoundException import android.content.ClipData import android.content.ContentValues import android.content.Intent @@ -275,11 +276,7 @@ class EditContactActivity : ContactActivity() { Intent().apply { action = Intent.ACTION_EDIT data = getContactPublicUri(contact!!) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } @@ -320,10 +317,13 @@ class EditContactActivity : ContactActivity() { putExtra("scaleUpIfNeeded", "true") clipData = ClipData("Attachment", arrayOf("text/primaryUri-list"), ClipData.Item(lastPhotoIntentUri)) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) - if (resolveActivity(packageManager) != null) { + + try { startActivityForResult(this, INTENT_CROP_PHOTO) - } else { + } catch (e: ActivityNotFoundException) { toast(R.string.no_app_found) + } catch (e: Exception) { + showErrorToast(e) } } } @@ -494,9 +494,9 @@ class EditContactActivity : ContactActivity() { private fun setupRingtone() { contact_ringtone.setOnClickListener { val ringtonePickerIntent = getRingtonePickerIntent() - if (ringtonePickerIntent.resolveActivity(packageManager) != null) { + try { startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE) - } else { + } catch (e: Exception) { val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri SelectAlarmSoundDialog(this, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true, onAlarmPicked = { @@ -1227,10 +1227,13 @@ class EditContactActivity : ContactActivity() { lastPhotoIntentUri = uri Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply { putExtra(MediaStore.EXTRA_OUTPUT, uri) - if (resolveActivity(packageManager) != null) { + + try { startActivityForResult(this, INTENT_TAKE_PHOTO) - } else { + } catch (e: ActivityNotFoundException) { toast(R.string.no_app_found) + } catch (e: Exception) { + showErrorToast(e) } } } @@ -1243,10 +1246,13 @@ class EditContactActivity : ContactActivity() { clipData = ClipData("Attachment", arrayOf("text/uri-list"), ClipData.Item(uri)) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) putExtra(MediaStore.EXTRA_OUTPUT, uri) - if (resolveActivity(packageManager) != null) { + + try { startActivityForResult(this, INTENT_CHOOSE_PHOTO) - } else { + } catch (e: ActivityNotFoundException) { toast(R.string.no_app_found) + } catch (e: Exception) { + showErrorToast(e) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt index b462074e..f0bbca97 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.activities import android.app.Activity import android.app.SearchManager +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.graphics.drawable.ColorDrawable @@ -269,10 +270,12 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { putExtra(KEY_EMAIL, email) } - if (resolveActivity(packageManager) != null) { + try { startActivityForResult(this, START_INSERT_ACTIVITY) - } else { + } catch (e: ActivityNotFoundException) { toast(R.string.no_app_found) + } catch (e: Exception) { + showErrorToast(e) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt index 19e91b82..e33a82df 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt @@ -595,9 +595,9 @@ class ViewContactActivity : ContactActivity() { contact_ringtone.setOnClickListener { val ringtonePickerIntent = getRingtonePickerIntent() - if (ringtonePickerIntent.resolveActivity(packageManager) != null) { + try { startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE) - } else { + } catch (e: Exception) { val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri SelectAlarmSoundDialog(this@ViewContactActivity, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true, onAlarmPicked = { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index b90a906f..077435cd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -21,12 +21,7 @@ fun SimpleActivity.startCallIntent(recipient: String) { val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL Intent(action).apply { data = Uri.fromParts("tel", recipient, null) - - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index 7ea4e3ee..05ca1913 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -58,11 +58,7 @@ fun Context.editContact(contact: Contact) { fun Context.sendEmailIntent(recipient: String) { Intent(Intent.ACTION_SENDTO).apply { data = Uri.fromParts(KEY_MAILTO, recipient, null) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } @@ -71,11 +67,7 @@ fun Context.sendAddressIntent(address: String) { val uri = Uri.parse("geo:0,0?q=$location") Intent(Intent.ACTION_VIEW, uri).apply { - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } @@ -88,11 +80,7 @@ fun Context.openWebsiteIntent(url: String) { Intent(Intent.ACTION_VIEW).apply { data = Uri.parse(website) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } @@ -235,11 +223,7 @@ fun Context.sendSMSToContacts(contacts: ArrayList) { val uriString = "smsto:${numbers.toString().trimEnd(';')}" Intent(Intent.ACTION_SENDTO, Uri.parse(uriString)).apply { - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } } @@ -256,11 +240,7 @@ fun Context.sendEmailToContacts(contacts: ArrayList) { Intent(Intent.ACTION_SEND_MULTIPLE).apply { type = "message/rfc822" putExtra(Intent.EXTRA_EMAIL, emails.toTypedArray()) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + launchActivityIntent(this) } }