Using coroutine for presence storage in native contact + changed verbosity of some recurring logs + switched to java 8
This commit is contained in:
parent
ffb04920bb
commit
5caa304b7f
4 changed files with 34 additions and 18 deletions
|
@ -126,6 +126,15 @@ android {
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
dataBinding = true
|
dataBinding = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -183,6 +192,3 @@ ktlint {
|
||||||
}
|
}
|
||||||
|
|
||||||
project.tasks['preBuild'].dependsOn 'ktlintFormat'
|
project.tasks['preBuild'].dependsOn 'ktlintFormat'
|
||||||
|
|
||||||
// Always clean on pre-build, prevents build issues caused by data binding
|
|
||||||
project.tasks['preBuild'].dependsOn 'clean'
|
|
|
@ -28,6 +28,8 @@ import android.net.Uri
|
||||||
import android.os.AsyncTask.THREAD_POOL_EXECUTOR
|
import android.os.AsyncTask.THREAD_POOL_EXECUTOR
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
|
import com.google.android.gms.tasks.Tasks.await
|
||||||
|
import kotlinx.coroutines.*
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
@ -332,16 +334,19 @@ class ContactsManager(private val context: Context) {
|
||||||
if (sipAddress != null) {
|
if (sipAddress != null) {
|
||||||
Log.d("[Contacts Manager] Found presence information to store in native contact $contact")
|
Log.d("[Contacts Manager] Found presence information to store in native contact $contact")
|
||||||
val contactEditor = NativeContactEditor(contact, null, null)
|
val contactEditor = NativeContactEditor(contact, null, null)
|
||||||
// TODO: could be great to do in a coroutine
|
val coroutineScope = CoroutineScope(Dispatchers.Main)
|
||||||
// launch {
|
coroutineScope.launch {
|
||||||
// withContext(Dispatchers.IO) {
|
val deferred = async {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
contactEditor.setPresenceInformation(phoneNumber, sipAddress).commit()
|
contactEditor.setPresenceInformation(phoneNumber, sipAddress).commit()
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
deferred.await()
|
||||||
for (listener in contactsUpdatedListeners) {
|
for (listener in contactsUpdatedListeners) {
|
||||||
listener.onContactUpdated(contact)
|
listener.onContactUpdated(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,13 +92,13 @@ class NativeContactEditor(
|
||||||
do {
|
do {
|
||||||
if (rawId == null) {
|
if (rawId == null) {
|
||||||
rawId = cursor.getString(cursor.getColumnIndex(RawContacts._ID))
|
rawId = cursor.getString(cursor.getColumnIndex(RawContacts._ID))
|
||||||
Log.i("[Native Contact Editor] Found raw id $rawId for native contact with id ${contact.nativeId}")
|
Log.d("[Native Contact Editor] Found raw id $rawId for native contact with id ${contact.nativeId}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val accountType = cursor.getString(cursor.getColumnIndex(RawContacts.ACCOUNT_TYPE))
|
val accountType = cursor.getString(cursor.getColumnIndex(RawContacts.ACCOUNT_TYPE))
|
||||||
if (accountType == syncAccountType && linphoneRawId == null) {
|
if (accountType == syncAccountType && linphoneRawId == null) {
|
||||||
linphoneRawId = cursor.getString(cursor.getColumnIndex(RawContacts._ID))
|
linphoneRawId = cursor.getString(cursor.getColumnIndex(RawContacts._ID))
|
||||||
Log.i("[Native Contact Editor] Found linphone raw id $linphoneRawId for native contact with id ${contact.nativeId}")
|
Log.d("[Native Contact Editor] Found linphone raw id $linphoneRawId for native contact with id ${contact.nativeId}")
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext() && linphoneRawId == null)
|
} while (cursor.moveToNext() && linphoneRawId == null)
|
||||||
}
|
}
|
||||||
|
@ -447,7 +447,7 @@ class NativeContactEditor(
|
||||||
addLinphoneAddress(sipAddress, phoneNumber)
|
addLinphoneAddress(sipAddress, phoneNumber)
|
||||||
} else {
|
} else {
|
||||||
if (data1 != null && data1 == sipAddress) {
|
if (data1 != null && data1 == sipAddress) {
|
||||||
Log.i("[Native Contact Editor] There is already an entry for this phone number and SIP address, skipping")
|
Log.d("[Native Contact Editor] There is already an entry for this phone number and SIP address, skipping")
|
||||||
} else {
|
} else {
|
||||||
Log.w("[Native Contact Editor] There is already an entry for this phone number but not for the same SIP address")
|
Log.w("[Native Contact Editor] There is already an entry for this phone number but not for the same SIP address")
|
||||||
updatePresenceLinphoneSipAddressForPhoneNumber(sipAddress, phoneNumber)
|
updatePresenceLinphoneSipAddressForPhoneNumber(sipAddress, phoneNumber)
|
||||||
|
@ -495,7 +495,7 @@ class NativeContactEditor(
|
||||||
Log.i("[Native Contact Editor] SIP address not found, let's add it")
|
Log.i("[Native Contact Editor] SIP address not found, let's add it")
|
||||||
addSipAddress(sipAddress)
|
addSipAddress(sipAddress)
|
||||||
} else {
|
} else {
|
||||||
Log.i("[Native Contact Editor] There is already an entry for this SIP address, skipping")
|
Log.d("[Native Contact Editor] There is already an entry for this SIP address, skipping")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,13 @@ class PermissionHelper private constructor(private val context: Context) {
|
||||||
|
|
||||||
private fun hasPermission(permission: String): Boolean {
|
private fun hasPermission(permission: String): Boolean {
|
||||||
val granted = Compatibility.hasPermission(context, permission)
|
val granted = Compatibility.hasPermission(context, permission)
|
||||||
val result = if (granted) "granted" else "denied"
|
|
||||||
Log.i("[Permission Helper] Permission $permission is $result")
|
if (granted) {
|
||||||
|
Log.d("[Permission Helper] Permission $permission is granted")
|
||||||
|
} else {
|
||||||
|
Log.w("[Permission Helper] Permission $permission is denied")
|
||||||
|
}
|
||||||
|
|
||||||
return granted
|
return granted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue