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
private fun signInWithPhoneAuthCredential(credential: PhoneAuthCredential) { | |
FirebaseAuth.getInstance().signInWithCredential(credential) | |
.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
Timber.v("signInWithCredential:success ${taskId.result?.user?.uid}") | |
} else { | |
Timber.v("signInWithCredential:failure ${task.exception}") | |
if (task.exception is FirebaseAuthInvalidCredentialsException) | |
context.toast("Invalid verification code!") | |
} |
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 UserProfile(var uId: String, | |
@ServerTimestamp | |
var createdAt: Date?=null, | |
@ServerTimestamp | |
var updatedAt: Date?=null, | |
var image: String="", | |
@get:PropertyName("user_name") | |
@set:PropertyName("user_name") | |
var userName: String="", | |
var token :String="", |
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
fun insertUser(){ | |
val mobileNumber= MobileNumber("+91","9876543210") | |
val profile = UserProfile( | |
uId= userId, | |
image = "https://i.pravatar.cc/150?img=2", | |
userName = "otis", | |
mobile = mobileNumber, | |
token = "el3LZrv0QmK5k-vjoO970:APA91bF8XKRqqTmf2n7E2PUrVDaxvhxq3WAIwQ5sHqLkwGbiICkebrCpkpwJvrVrvcJiDgaeLndJQwJDWvv2ad-W0SGDpDyuYgrQGFo5eDQSvce20gS1Q5ijmkD-QmzBAgFoRVaDi2u", | |
) |
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
interface QueryListener{ | |
fun onCompleted(queriedList: ArrayList<UserProfile>) | |
fun onStart(position: Int,contactBatch: ArrayList<String>) | |
} | |
class ContactsQuery{ | |
companion object{ | |
var queriedList=ArrayList<UserProfile>() | |
var currentQueryCount=0 |
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
object UserUtils { | |
fun queryContacts() { | |
val listOfContact= mutableListOf<String>() | |
listOfContacts.add("9500552211") | |
listOfContacts.add("9500552212") | |
listOfContacts.add("9500552213") | |
listOfContacts.add("9500552214") | |
listOfContacts.add("9500552215") | |
listOfContacts.add("9500552216") |
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 ChatUser( | |
@PrimaryKey | |
var id: String,var localName: String,var user: UserProfile, var messageDocId: String="", | |
var locallySaved: Boolean=false, | |
var unRead: Int=0) |
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>) { |
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 Message( | |
@PrimaryKey | |
val id: String, | |
var chatUsers: ArrayList<String>, | |
@ServerTimestamp | |
var createdAt: Date?=Date(), | |
var type: String="text",//0=text,1=audio,2=image,3=video,4=file | |
var status: Int=0,//0=sending,1=sent,2=delivered,3=seen,4=failed | |
var textMessage: TextMessage=TextMessage("hello chat"), | |
@ServerTimestamp |
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
class FSingleChat : Fragment(), MessageSenderCallback{ | |
@Inject | |
lateinit var dbRepository: DbRepository | |
fun sendMessage(){ | |
val message= createMessage("my first message") | |
msgDao.insertMessage(message) | |
val db = FirebaseFirestore.getInstance() |
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
interface MessageSenderCallback{ | |
fun onSuccess(message: Message) | |
fun onFailed(message: Message) | |
} | |
class MessageSender(private val msgCollection: CollectionReference, | |
private val dbRepo: DbRepository, private val chatUser: ChatUser, | |
private val listener: MessageSenderCallback) { |
OlderNewer