Skip to content

Instantly share code, notes, and snippets.

View hieptl's full-sized avatar
🎯
Focusing

Hiep Le hieptl

🎯
Focusing
View GitHub Profile
@hieptl
hieptl / LoginActivity.java
Last active October 13, 2021 03:20
LoginActivity.java - Init CometChat and Login to CometChat - Voice and Video Chat App - Android App
...
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
this.initCometChat();
}
...
private void initCometChat() {
@hieptl
hieptl / SignUpActivity.java
Last active October 12, 2021 08:42
SignUpActivity.java - Voice and Video Chat App - Android App
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;
@hieptl
hieptl / SignUpActivity.java
Last active October 12, 2021 08:43
SignUpActivity.java - Register CometChat Account - Voice and Video Chat App - Android App
...
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();
@hieptl
hieptl / App.js
Last active October 12, 2021 09:12
App.js - Init CometChat - React Native Gifted Chat App
...
useEffect(() => {
initCometChat();
...
}, []);
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/react-native-chat');
const appID = `${cometChatConfig.cometChatAppId}`;
const region = `${cometChatConfig.cometChatRegion}`;
@hieptl
hieptl / firebase.js
Created October 10, 2021 16:04
firebase.js - React Native Gifted Chat App
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}`,
@hieptl
hieptl / login.js
Created October 10, 2021 16:13
login.js - React Native Gifted Chat App
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.
@hieptl
hieptl / login.js
Created October 10, 2021 16:19
login.js - Login CometChat - React Native Gifted Chat App
...
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');
@hieptl
hieptl / SignUp.js
Last active October 15, 2021 12:18
SignUp.js - React Native Gifted Chat App
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.
@hieptl
hieptl / SignUp.js
Created October 10, 2021 16:25
SignUp.js - Create a New CometChat Account - React Native Gifted Chat App
...
// 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 => {
@hieptl
hieptl / Home.js
Created October 10, 2021 16:35
Home.js - React Native Gifted Chat App
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;