"Kwickk Finance" is a modern blog dedicated to empowering readers with practical, insightful, and actionable financial advice.

Friday, March 21, 2025

Introducing FastChat: A Kotlin-Based Chat App Powered by Firebase

 Introducing FastChat: A Kotlin-Based Chat App Powered by Firebase


🚀 Overview

FastChat is a real-time chatting app built using Kotlin and Firebase Cloud Platform. It allows users to sign up, log in, send messages, and customize their settings in a fast, secure, and user-friendly environment.

🔗 GitHub Repository: [Complete Source Code Available Here]

📸 Sample Screenshots:

FastChat: App Home Screen


FastChat: App Login Screen


FastChat: App Messaging Screen



📌 Key Features of FastChat

User Authentication (Signup & Login) with Firebase Authentication
Real-time Messaging powered by Firebase Firestore
User Profile Settings (Change Display Name & Profile Picture)
Secure & Scalable using Firebase Cloud Functions and Firestore Rules
Push Notifications for New Messages (Optional)
Responsive UI with Material Design Components


🛠️ Tech Stack

  • Frontend: Kotlin (Jetpack Compose or XML UI)
  • Backend: Firebase Firestore, Firebase Authentication, Firebase Cloud Messaging (FCM)
  • State Management: ViewModel + LiveData
  • Dependency Injection: Hilt
  • UI Components: Material Design

🛠️ Step 1: Setting Up the Android Project

1️⃣ Install Android Studio

Download and install Android Studio from developer.android.com.

2️⃣ Create a New Android Project

  1. Open Android Studio → Create a new project
  2. Choose Empty Activity
  3. Select Kotlin as the programming language

3️⃣ Add Firebase SDK to Your Project

  1. Go to Firebase Console
  2. Create a new project → Add an Android app
  3. Register your app using the package name
  4. Download google-services.json and place it in app/
  5. Add dependencies in build.gradle (Module: app):
dependencies { implementation 'com.google.firebase:firebase-auth-ktx' implementation 'com.google.firebase:firebase-firestore-ktx' implementation 'com.google.firebase:firebase-storage-ktx' }
  1. Sync the project

🛠️ Step 2: Implementing Authentication (Signup & Login)

1️⃣ Create Authentication Service (AuthService.kt)

import com.google.firebase.auth.FirebaseAuth class AuthService { private val auth: FirebaseAuth = FirebaseAuth.getInstance() fun signUp(email: String, password: String, onResult: (Boolean, String?) -> Unit) { auth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener { task -> if (task.isSuccessful) { onResult(true, null) } else { onResult(false, task.exception?.message) } } } fun login(email: String, password: String, onResult: (Boolean, String?) -> Unit) { auth.signInWithEmailAndPassword(email, password) .addOnCompleteListener { task -> if (task.isSuccessful) { onResult(true, null) } else { onResult(false, task.exception?.message) } } } fun logout() { auth.signOut() } }

2️⃣ Create Login Screen (LoginActivity.kt)

class LoginActivity : AppCompatActivity() { private lateinit var authService: AuthService override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) authService = AuthService() val emailField = findViewById<EditText>(R.id.email) val passwordField = findViewById<EditText>(R.id.password) val loginButton = findViewById<Button>(R.id.loginButton) loginButton.setOnClickListener { val email = emailField.text.toString() val password = passwordField.text.toString() authService.login(email, password) { success, message -> if (success) { startActivity(Intent(this, ChatActivity::class.java)) finish() } else { Toast.makeText(this, "Login Failed: $message", Toast.LENGTH_SHORT).show() } } } } }

🛠️ Step 3: Building the Messaging System

1️⃣ Define Message Model (Message.kt)

data class Message( val senderId: String = "", val message: String = "", val timestamp: Long = System.currentTimeMillis() )

2️⃣ Create Firestore Database for Chats

  1. Go to Firebase Console → Firestore Database
  2. Click "Start Collection" → Name it "messages"

3️⃣ Implement Chat Service (ChatService.kt)

import com.google.firebase.firestore.FirebaseFirestore class ChatService { private val db = FirebaseFirestore.getInstance() fun sendMessage(senderId: String, message: String) { val chatMessage = Message(senderId, message) db.collection("messages").add(chatMessage) } fun getMessages(onMessagesReceived: (List<Message>) -> Unit) { db.collection("messages").orderBy("timestamp") .addSnapshotListener { snapshot, _ -> snapshot?.let { val messages = it.toObjects(Message::class.java) onMessagesReceived(messages) } } } }

4️⃣ Create Chat Screen (ChatActivity.kt)

class ChatActivity : AppCompatActivity() { private lateinit var chatService: ChatService private lateinit var messageList: RecyclerView private lateinit var messageInput: EditText override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_chat) chatService = ChatService() messageList = findViewById(R.id.recyclerView) messageInput = findViewById(R.id.messageInput) val sendButton = findViewById<Button>(R.id.sendButton) sendButton.setOnClickListener { val message = messageInput.text.toString() if (message.isNotEmpty()) { chatService.sendMessage("user123", message) messageInput.text.clear() } } chatService.getMessages { messages -> messageList.adapter = MessageAdapter(messages) } } }

🛠️ Step 4: Deploying FastChat on Firebase

1️⃣ Enable Firebase Firestore Rules for Security

Go to Firestore Rules and add:

rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /messages/{messageId} { allow read, write: if request.auth != null; } } }

2️⃣ Run the App on an Android Device or Emulator

./gradlew installDebug

3️⃣ Publish the App on Google Play Store

Follow the Google Play Console guide to publish your app.


🚀 Conclusion

FastChat is a fully functional real-time chat app built with Kotlin and Firebase.

🔗 GitHub Repository: [Complete Source Code Available Here]

Share:

0 comments:

Post a Comment

BTemplates.com

Ads block

Banner 728x90px

Contact Form

Name

Email *

Message *

Logo

SEARCH

Translate

Popular Posts