mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Add ability to add contact from avatar
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.provider.Telephony
|
||||
import common.util.NotificationManager
|
||||
@@ -89,6 +90,12 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun addContact(address: String) {
|
||||
val uri = Uri.parse("tel: $address")
|
||||
val intent = Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, uri)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
fun showNotificationSettings() {
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
|
||||
@@ -70,7 +70,12 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
||||
clicks()
|
||||
.autoDisposable(scope())
|
||||
.subscribe {
|
||||
contact?.lookupKey?.takeIf { it.isNotEmpty() }?.let { key ->
|
||||
if (contact?.lookupKey.isNullOrEmpty()) {
|
||||
contact?.numbers?.firstOrNull()?.let { number ->
|
||||
navigator.addContact(number.address)
|
||||
}
|
||||
} else {
|
||||
val key = contact?.lookupKey
|
||||
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, key)
|
||||
ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri,
|
||||
ContactsContract.QuickContact.MODE_MEDIUM, null)
|
||||
|
||||
Reference in New Issue
Block a user