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 {
|
||||
dataBinding = true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
@ -183,6 +192,3 @@ ktlint {
|
|||
}
|
||||
|
||||
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.provider.ContactsContract
|
||||
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.corePreferences
|
||||
import org.linphone.R
|
||||
|
@ -332,12 +334,14 @@ class ContactsManager(private val context: Context) {
|
|||
if (sipAddress != null) {
|
||||
Log.d("[Contacts Manager] Found presence information to store in native contact $contact")
|
||||
val contactEditor = NativeContactEditor(contact, null, null)
|
||||
// TODO: could be great to do in a coroutine
|
||||
// launch {
|
||||
// withContext(Dispatchers.IO) {
|
||||
val coroutineScope = CoroutineScope(Dispatchers.Main)
|
||||
coroutineScope.launch {
|
||||
val deferred = async {
|
||||
withContext(Dispatchers.IO) {
|
||||
contactEditor.setPresenceInformation(phoneNumber, sipAddress).commit()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
deferred.await()
|
||||
for (listener in contactsUpdatedListeners) {
|
||||
listener.onContactUpdated(contact)
|
||||
}
|
||||
|
@ -345,3 +349,4 @@ class ContactsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,13 +92,13 @@ class NativeContactEditor(
|
|||
do {
|
||||
if (rawId == null) {
|
||||
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))
|
||||
if (accountType == syncAccountType && linphoneRawId == null) {
|
||||
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)
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ class NativeContactEditor(
|
|||
addLinphoneAddress(sipAddress, phoneNumber)
|
||||
} else {
|
||||
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 {
|
||||
Log.w("[Native Contact Editor] There is already an entry for this phone number but not for the same SIP address")
|
||||
updatePresenceLinphoneSipAddressForPhoneNumber(sipAddress, phoneNumber)
|
||||
|
@ -495,7 +495,7 @@ class NativeContactEditor(
|
|||
Log.i("[Native Contact Editor] SIP address not found, let's add it")
|
||||
addSipAddress(sipAddress)
|
||||
} 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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue