Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe

Wajahat Karim wajahatkarim3

:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe
View GitHub Profile
View checkout start-here branch
git clone -b start-here https://github.com/wajahatkarim3/ZocDoc-Clone
@wajahatkarim3
wajahatkarim3 / Zocdoc.kt
Created Feb 4, 2021
Customizing Color of CometChat UI Kit
View Zocdoc.kt
fun initCometChat() {
val appID = getString(R.string.app_id) // Replace with your App ID
val region = getString(R.string.region) // Replace with your App Region ("eu" or "us")
val appSettings: AppSettings = AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(
region
).build()
CometChat.init(this, appID, appSettings, object : CometChat.CallbackListener<String?>() {
override fun onSuccess(successMessage: String?) {
@wajahatkarim3
wajahatkarim3 / SignupActivity.kt
Created Feb 4, 2021
Creating CometUser from Firebase User
View SignupActivity.kt
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()
View ConversationsFragment.kt
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>?) {
@wajahatkarim3
wajahatkarim3 / ChatActivity.kt
Created Jan 31, 2021
Adding Chat for patient
View ChatActivity.kt
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()
View ProfileFragment.kt
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()
}
@wajahatkarim3
wajahatkarim3 / LoginActivity.kt
Created Jan 31, 2021
Login Firebase and CometChat user
View LoginActivity.kt
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)
@wajahatkarim3
wajahatkarim3 / SignupActivity.kt
Last active Feb 4, 2021
CometChat Authentication
View SignupActivity.kt
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>() {
@wajahatkarim3
wajahatkarim3 / SignupActivity.kt
Created Jan 31, 2021
Firebase Authentication
View SignupActivity.kt
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()
@wajahatkarim3
wajahatkarim3 / SignupActivity.kt
Created Jan 31, 2021
Signup click listener before CometChat
View SignupActivity.kt
// 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)