mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-02 10:27:03 +01:00
moving some helper functions into Commons
This commit is contained in:
parent
6db8d2a2d3
commit
ebe1ab967f
@ -56,7 +56,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.26.27'
|
implementation 'com.simplemobiletools:commons:5.27.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||||
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
||||||
|
@ -435,54 +435,6 @@ fun Context.getNameAndPhotoFromPhoneNumber(number: String): NamePhoto? {
|
|||||||
return NamePhoto(number, null)
|
return NamePhoto(number, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getNameFromPhoneNumber(number: String): String {
|
|
||||||
if (!hasPermission(PERMISSION_READ_CONTACTS)) {
|
|
||||||
return number
|
|
||||||
}
|
|
||||||
|
|
||||||
val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number))
|
|
||||||
val projection = arrayOf(
|
|
||||||
PhoneLookup.DISPLAY_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
|
||||||
val cursor = contentResolver.query(uri, projection, null, null, null)
|
|
||||||
cursor.use {
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
|
||||||
return cursor.getStringValue(PhoneLookup.DISPLAY_NAME)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
showErrorToast(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return number
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.getPhotoUriFromPhoneNumber(number: String): String {
|
|
||||||
if (!hasPermission(PERMISSION_READ_CONTACTS)) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number))
|
|
||||||
val projection = arrayOf(
|
|
||||||
PhoneLookup.PHOTO_URI
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
|
||||||
val cursor = contentResolver.query(uri, projection, null, null, null)
|
|
||||||
cursor.use {
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
|
||||||
return cursor.getStringValue(PhoneLookup.PHOTO_URI) ?: ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
showErrorToast(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.getContactNames(): List<Contact> {
|
fun Context.getContactNames(): List<Contact> {
|
||||||
val contacts = ArrayList<Contact>()
|
val contacts = ArrayList<Contact>()
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user