This file contains hidden or 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
var auth = FirebaseAuth.getInstance() | |
auth.createUserWithEmailAndPassword(bi.txtEmail.text.toString(), bi.txtPassword.text.toString()) | |
.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
var firebaseUser = auth.currentUser | |
createAndLoginCometUser(firebaseUser!!.uid, bi.txtName.text.toString(), bi.radioDoctor.isChecked) | |
} else { | |
Snackbar.make(bi.root, "Authentication failed!", Snackbar.LENGTH_SHORT).show() |
This file contains hidden or 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 setLoggedInUI() { | |
if (CometChat.getLoggedInUser() != null) { | |
var conversationsRequest = ConversationsRequest.ConversationsRequestBuilder() | |
.setLimit(50) | |
.setConversationType(CometChatConstants.CONVERSATION_TYPE_USER) | |
.build() | |
conversationsRequest.fetchNext(object : | |
CometChat.CallbackListener<List<Conversation>>() { | |
override fun onSuccess(conversations: List<Conversation>?) { |
This file contains hidden or 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 initChat() { | |
initEmoji() | |
if (doctor != null) { | |
CometChat.getLoggedInUser()?.let { | |
CometChat.getUser(doctor!!.doctorId, object : CometChat.CallbackListener<User>() { | |
override fun onSuccess(doctorUser: User?) { | |
var bundle = Bundle() | |
var chatFragment: Fragment = CometChatMessageScreen() |
This file contains hidden or 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
bi.txtSignout.setOnClickListener { | |
CometChat.logout(object : CometChat.CallbackListener<String>() { | |
override fun onSuccess(p0: String?) { | |
val i = Intent(activity, MainActivity::class.java) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) | |
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(i) | |
activity?.finish() | |
} |
This file contains hidden or 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
var auth = FirebaseAuth.getInstance() | |
auth.signInWithEmailAndPassword(bi.txtEmail.text.toString(), bi.txtPassword.text.toString()) | |
.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
var firebaseUser = auth.currentUser | |
CometChat.login(firebaseUser!!.uid, getString(R.string.auth_key), object : CometChat.CallbackListener<User>() { | |
override fun onSuccess(u: User?) { | |
if (u?.metadata?.has("isDoctor") == true && u.metadata?.getBoolean("isDoctor") == true) { | |
val i = Intent(applicationContext, DoctorMainActivity::class.java) | |
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) |
This file contains hidden or 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 createAndLoginCometUser(uid: String, name: String, isDoctor: Boolean) { | |
var cometUser = User() | |
cometUser.uid = uid | |
cometUser.name = name | |
var meta = JSONObject() | |
meta.put("isDoctor", isDoctor) | |
cometUser.metadata = meta | |
CometChat.createUser(cometUser, getString(R.string.auth_key), object : CometChat.CallbackListener<User>() { |
This file contains hidden or 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
var auth = FirebaseAuth.getInstance() | |
auth.createUserWithEmailAndPassword(bi.txtEmail.text.toString(), bi.txtPassword.text.toString()) | |
.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
var firebaseUser = auth.currentUser | |
// CometChat Auth will be here. | |
} else { | |
Snackbar.make(bi.root, "Authentication failed!", Snackbar.LENGTH_SHORT).show() |
This file contains hidden or 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
// Signup | |
bi.btnSignup.setOnClickListener { | |
// Form Validation | |
// .................................. | |
// The random code for dummy signup flow | |
var isDoctor = bi.radioDoctor.isChecked | |
if (isDoctor) { | |
val i = Intent(applicationContext, DoctorMainActivity::class.java) |
This file contains hidden or 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 ZocdocApp : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
initEmoji() | |
initCometChat() | |
} | |
fun initCometChat() { |
This file contains hidden or 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
dependencies { | |
// ........ Your other dependencies | |
// CometChat | |
implementation 'com.cometchat:pro-android-chat-sdk:2.1.6' | |
implementation(project(":uikit")) | |
implementation "androidx.emoji:emoji-appcompat:1.0.0" | |
// Firebase |