From 862cc56f290aba1a352e81c332fa4628ef6a91ba Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 3 Apr 2020 16:05:02 +0200 Subject: [PATCH] importing a class to shorten some code --- .../smsmessenger/activities/MainActivity.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index ec365aff..aca1ff79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.database.Cursor import android.os.Bundle import android.provider.ContactsContract +import android.provider.ContactsContract.CommonDataKinds import android.provider.Telephony import android.text.TextUtils import android.view.Menu @@ -111,19 +112,19 @@ class MainActivity : SimpleActivity() { private fun getPersonsName(id: Int): String? { val uri = ContactsContract.Data.CONTENT_URI val projection = arrayOf( - ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, - ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME, - ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, - ContactsContract.CommonDataKinds.Organization.COMPANY, - ContactsContract.CommonDataKinds.Organization.TITLE, + CommonDataKinds.StructuredName.GIVEN_NAME, + CommonDataKinds.StructuredName.MIDDLE_NAME, + CommonDataKinds.StructuredName.FAMILY_NAME, + CommonDataKinds.Organization.COMPANY, + CommonDataKinds.Organization.TITLE, ContactsContract.Data.MIMETYPE ) val selection = "(${ContactsContract.Data.MIMETYPE} = ? OR ${ContactsContract.Data.MIMETYPE} = ?) AND ${ContactsContract.Data.CONTACT_ID} = ?" val selectionArgs = arrayOf( - ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, - ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE, + CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, + CommonDataKinds.Organization.CONTENT_ITEM_TYPE, id.toString() ) @@ -133,18 +134,18 @@ class MainActivity : SimpleActivity() { if (cursor?.moveToFirst() == true) { do { val mimetype = cursor.getStringValue(ContactsContract.Data.MIMETYPE) - val firstName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME) ?: "" - val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" - val familyName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" - val isPerson = mimetype == ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: "" + val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" + val familyName = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" + val isPerson = mimetype == CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE if (isPerson && (firstName.isNotEmpty() || middleName.isNotEmpty() || familyName.isNotEmpty())) { val names = arrayOf(firstName, middleName, familyName).filter { it.isNotEmpty() } return TextUtils.join(" ", names) } - val isOrganization = mimetype == ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE - val company = cursor.getStringValue(ContactsContract.CommonDataKinds.Organization.COMPANY) ?: "" - val jobTitle = cursor.getStringValue(ContactsContract.CommonDataKinds.Organization.TITLE) ?: "" + val isOrganization = mimetype == CommonDataKinds.Organization.CONTENT_ITEM_TYPE + val company = cursor.getStringValue(CommonDataKinds.Organization.COMPANY) ?: "" + val jobTitle = cursor.getStringValue(CommonDataKinds.Organization.TITLE) ?: "" if (isOrganization && (company.isNotEmpty() || jobTitle.isNotEmpty())) { return "$company $jobTitle".trim() }