Last active
September 29, 2021 08:35
-
-
Save a914-gowtham/a6afa7e27cac3e73cbf0d56970ecd8d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Contact(var name: String,var mobile: String) | |
object UserUtils { | |
/* | |
creating data for query | |
*/ | |
private val onQueryListener=object : QueryListener { | |
override fun onCompleted(queriedList: ArrayList<UserProfile>) { | |
try { | |
Timber.v("onQueryCompleted ${queriedList.size}") | |
val localDeviceContacts= fetchLocalDeviceContacts() | |
val finalList = ArrayList<ChatUser>() | |
//set localsaved name to queried users | |
CoroutineScope(Dispatchers.IO).launch { | |
val chatUsers=userDaoo.getChatUserList() | |
for(doc in queriedList){ | |
val savedNumber=localDeviceContacts.first { it.mobile == doc.mobile?.number } | |
val chatUser=getChatUser(doc,chatUsers,savedNumber.name) | |
finalList.add(chatUser) | |
} | |
setDefaultValues() | |
userDaoo.insertMultipleUser(finalList) | |
} | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} | |
} | |
override fun onStart(position: Int, contactBatch: ArrayList<String>) { | |
Timber.v("onQueryStart pos: $position inputs: ${contactBatch.size}") | |
} | |
} | |
fun getChatUser( | |
doc: UserProfile, | |
chatUsers: List<ChatUser>, | |
savedName: String): ChatUser { | |
var existChatUser: ChatUser? = null | |
if (chatUsers.isNotEmpty()) { | |
val contact = chatUsers.firstOrNull { it.id == doc.uId } | |
if(contact!=null) | |
existChatUser=contact | |
} | |
return existChatUser?.apply { | |
user = doc | |
localName = savedName | |
locallySaved=true | |
} ?: ChatUser(id = doc.uId.toString(),localName = savedName,user = doc,locallySaved = true) | |
} | |
fun fetchLocalDeviceContacts(): List<Contact> { | |
val dummyContactsFromDevice=ArrayList<Contact>() | |
dummyContacts.add(Contact("Arthur","9500112233")) | |
dummyContacts.add(Contact("Arthur1","9500112232")) | |
dummyContacts.add(Contact("Arthur2","9500112235")) | |
dummyContacts.add(Contact("Arthur3","9500112236")) | |
dummyContacts.add(Contact("Arthur4","9500112237")) | |
dummyContacts.add(Contact("Arthur5","9500112238")) | |
return dummyContacts | |
} | |
private fun setDefaultValues() { | |
ContactsQuery.totalQueryCount =0 | |
ContactsQuery.currentQueryCount =0 | |
ContactsQuery.queriedList.clear() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment