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
... | |
public class LoginActivity extends AppCompatActivity implements View.OnClickListener { | |
... | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
... | |
this.initCometChat(); | |
} | |
... | |
private void 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
package com.cometchat.chatapp; | |
import android.app.ProgressDialog; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; |
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
... | |
public class SignUpActivity extends AppCompatActivity implements View.OnClickListener { | |
... | |
private void registerCometChatAccount(String username, String email) { | |
if (username == null) { | |
return; | |
} | |
String uid = UUID.randomUUID().toString(); | |
String avatar = this.generateAvatar(); | |
User user = new 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
... | |
useEffect(() => { | |
initCometChat(); | |
... | |
}, []); | |
const initCometChat = async () => { | |
const { CometChat } = await import('@cometchat-pro/react-native-chat'); | |
const appID = `${cometChatConfig.cometChatAppId}`; | |
const region = `${cometChatConfig.cometChatRegion}`; |
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
import { fbConfig } from "./env"; | |
import { initializeApp } from 'firebase/app'; | |
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "firebase/auth"; | |
const firebaseConfig = { | |
apiKey: `${fbConfig.apiKey}`, | |
authDomain: `${fbConfig.authDomain}`, | |
projectId: `${fbConfig.projectId}`, | |
storageBucket: `${fbConfig.storageBucket}`, |
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
import React, { useState, useContext, useEffect } from 'react'; | |
import { StyleSheet, View, TextInput, TouchableOpacity, Text, ActivityIndicator, Alert } from 'react-native'; | |
// import environment variables. | |
import { cometChatConfig } from '../env'; | |
// import Context to get shared data from React context. | |
import Context from "../context"; | |
// import firebase authentication and real time database. | |
import { auth, signInWithEmailAndPassword } from "../firebase"; | |
// import validator to validate user's credentials. |
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
... | |
cometChat.login(firebaseUid, `${cometChatConfig.cometChatAuthKey}`).then( | |
user => { | |
// User loged in successfully. | |
// save authenticated user to local storage. | |
AsyncStorage.setItem('auth', JSON.stringify(user)); | |
// save authenticated user to context. | |
setUser(user); | |
// navigate to the home page | |
navigation.navigate('Home'); |
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
import React, { useState, useContext } from 'react'; | |
import { StyleSheet, View, TextInput, TouchableOpacity, Text, Alert, ActivityIndicator } from 'react-native'; | |
// import environment variables. | |
import { cometChatConfig } from '../env'; | |
// import Context to get shared data. | |
import Context from "../context"; | |
// import validator to validate user's information. | |
import validator from "validator"; | |
// import firebase authentication. |
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
... | |
// cometchat auth key | |
const authKey = `${cometChatConfig.cometChatAuthKey}`; | |
// call cometchat service to register a new account. | |
const user = new cometChat.User(firebaseUid); | |
user.setName(fullname); | |
user.setAvatar(userAvatar); | |
cometChat.createUser(user, authKey).then( | |
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
import React, { useState, useEffect, useContext } from 'react'; | |
import { StyleSheet, View, TextInput, TouchableOpacity, Text, FlatList, Image } from 'react-native'; | |
import Context from '../context'; | |
import 'react-native-get-random-values'; | |
import { v4 as uuidv4 } from "uuid"; | |
const Home = (props) => { | |
const { navigation } = props; |