This guide will help you set up Firebase for the project you've cloned. The necessary Firebase dependencies are already included. Follow these steps to create signing keys, generate SHA-1 keys, and configure Firebase.
build.gradle
file under applicationId
.google-services.json
file.google-services.json
File:
google-services.json
file in the app/
directory of your cloned project../gradlew signingReport
Locate the SHA-1 key:
The SHA-1 key will be listed under Variant: debug
. Copy this key for use in the Firebase Console.
keytool -genkey -v -keystore release-key.keystore -alias release-key -keyalg RSA -keysize 2048 -validity 10000
You'll be prompted to provide information like your name, organization, and location. After completing this step, a release-key.keystore
file will be created.
keytool -list -v -keystore release-key.keystore -alias release-key
you can replace the release-key
with your preferred name
Enter the password you set during the keystore creation. Copy the displayed SHA-1 key for use in Firebase.
With the google-services.json
file in place and the SHA-1 keys added to Firebase, you can now build and run the project as intended.
If you are lost, you can refer Generating Signing Key for android project for detailed instructions
This section provides a detailed overview of the components and functionality related to user authentication within Uni Admin. It covers different authentication methods, including email/password login, third-party authentication using Google and GitHub, and password reset functionality. The documentation outlines the UI components, state management, and backend logic involved in each authentication process. It also includes references to relevant code files and visual representations of the user interface.
File: GoogleAuth.kt
Functionality
The GoogleAuth
composable function handles Google authentication using Firebase. It initiates the Google sign-in process and provides visual feedback to the user.
Parameters
firebaseAuth
: An instance of FirebaseAuth
used to initiate the Google sign-in process.onSignInSuccess
: A callback function triggered when the sign-in process is successful.onSignInFailure
: A callback function triggered when the sign-in process fails, passing an error message.Behavior
onSignInSuccess
is called.onSignInFailure
is called.File: GithubAuth.kt
Functionality
The GitAuth
composable function handles GitHub authentication using Firebase. It initiates the GitHub sign-in process and provides visual feedback to the user.
Parameters
firebaseAuth
: An instance of FirebaseAuth
used to initiate the GitHub sign-in process.onSignInSuccess
: A callback function triggered when the sign-in process is successful.onSignInFailure
: A callback function triggered when the sign-in process fails, passing an error message.Behavior
onSignInSuccess
is called.onSignInFailure
is called.File: Login.kt
val auth: FirebaseAuth = FirebaseAuth.getInstance()
: Initializes a FirebaseAuth
instance.firstName
, lastName
, email
, password
: Holds user input values.isSigningUp
: Boolean to toggle between Sign Up and Sign In modes.isGithubLoading
, isGoogleLoading
: Boolean flags for loading states during GitHub and Google sign-in.visible
: Controls visibility, initially set to true.loading
: Manages the loading state during form submission.isSigningUp
state.GoogleAuth
and GitAuth
components handle third-party authentication.handleAuthSuccess
is called.isSigningUp
is true, additional fields for first and last name are shown.handleSignUp
or handleSignIn
based on the isSigningUp
state.handleAuthSuccess
:
homeScreen
or moreDetails
).handleSignUp
:
UserViewModel
.handleSignIn
:
This structure ensures the screen dynamically handles both sign-in and sign-up processes, manages third-party authentication, and updates the user interface accordingly based on user interactions and authentication states.
File: MoreDetails.kt
The MoreDetails
composable function displays a form for users to enter additional details like their first and last names after signing in. It also allows saving these details to the local database and notifies other users about the new user joining.
context
: Context
: The context of the calling component.navController
: NavController
: The navigation controller to handle navigation between different screens.UserRepository
and NotificationRepository
from the UniConnect
application context.UserViewModel
and NotificationViewModel
using the repositories.remember
and mutableStateOf
to manage state variables for loading status (addloading
), first name, and last name.Brush.verticalGradient
.TopAppBar
with a back navigation button.UserEntity
with the entered details.UserViewModel
.NotificationViewModel
.UserRepository
is not null and throws an exception if it is.LaunchedEffect
to find the user by email when the composable is first launched.Scaffold
to provide a consistent layout structure with a top app bar and a content area.File: PasswordReset.kt
The PasswordReset
composable function provides a screen for users to reset their forgotten passwords. It allows users to enter their email address and sends a password reset email using Firebase Authentication.
navController
: NavController
: The navigation controller to handle navigation between different screens.context
: Context
: The context of the calling component.FirebaseAuth
for authentication operations.Brush.verticalGradient
.AnimatedVisibility
to animate the screen content.Scaffold
for basic layout structure with a top app bar (though not used) and content area.auth.sendPasswordResetEmail()
.CircularProgressIndicator
on the button while the password reset email is being sent.LaunchedEffect
to control the visibility of the screen content with an animation.remember
and mutableStateOf
to manage state variables.FileAnnouncements.kt
The AnnouncementsScreen
Composable function is responsible for displaying a screen where users can view, add, and manage announcements. It utilizes a top app bar with buttons for adding new announcements and refreshing the list. The screen presents a list of announcements retrieved from a repository and offers functionality to edit or delete them.
addAnnouncement
: A Boolean state variable that controls the visibility of the add announcement form.announcementAdmin
, announcementRepository
, userRepository
: Instances used to access the respective repositories from the application context.announcementViewModel
, userViewModel
: ViewModel instances created using factories to manage the state and business logic related to announcements and users.announcements
, announcementsLoading
: Observed states from announcementViewModel
that represent the list of announcements and the loading status, respectively.refresh
: A Boolean state that triggers the fetching of announcements when its value changes.editingAnnouncementId
: A nullable String state variable that keeps track of the announcement currently being edited.LaunchedEffect
: This effect is triggered when the refresh
state changes. It calls the fetchAnnouncements()
function from the announcementViewModel
to load the announcements.Scaffold
: Provides the basic structure for the screen, including a TopAppBar
.TopAppBar
: Contains two IconButton
components: one for adding a new announcement and another for refreshing the announcements list. Clicking the add button toggles the visibility of the add announcement form, while the refresh button initiates data re-fetching.Column
and Row
Layouts: A Column
is used to arrange the content vertically, with a Row
employed to display the screen title centered at the top.Text
and Spacer
: The Text
composable displays the "Announcements" title and a subtitle for user guidance. The Spacer
adds vertical spacing between components.AddAnnouncement
composable based on the addAnnouncement
state.announcementsLoading
and announcements
states:
announcementsLoading
is true, a CircularProgressIndicator
is displayed.announcements
is empty or null, a message indicating that there are no announcements is shown.LazyColumn
.AnnouncementCard
, which provides options to edit or delete the announcement:
deleteAnnouncement
function in announcementViewModel
and displays a Toast message if the deletion fails.The AnnouncementsScreen
presents a visually appealing and user-friendly interface for managing announcements. The top app bar provides easy access to actions for adding new announcements and refreshing the list. The announcements are displayed in a clear and organized manner within the LazyColumn
, with each AnnouncementCard
offering options for editing or deleting. Loading states and potential empty states are handled gracefully, providing appropriate feedback to the user.
remember
and mutableStateOf
to manage state variables.By leveraging these components and logic, the AnnouncementsScreen
provides a robust and intuitive experience for managing announcements within the Uni Admin.
AddAnnouncement
is a Composable function that provides a UI for adding a new announcement. It includes input fields for the announcement title and description, and displays the user's profile image or initials, along with the current date.
context: Context
: The context of the current application, used for styling and resources.onComplete: (Boolean) -> Unit
: A callback function that is triggered upon the completion of the announcement addition process, passing a Boolean indicating success.userViewModel: UserViewModel
: A ViewModel
instance for managing user-related data and operations.announcementViewModel: AnnouncementViewModel
: A ViewModel
instance for managing announcement-related data and operations.title
: A String
representing the announcement title, managed using mutableStateOf
.description
: A String
representing the announcement description, managed using mutableStateOf
.signedInUser
, user
: Observed states for the signed-in user and current user, respectively, from the userViewModel
.saveAnnouncement
function from the announcementViewModel
.user
state accordingly.EditAnnouncement
is a Composable function that provides a UI for editing an existing announcement. It allows users to modify the title and description of an announcement.
context: Context
: The context of the current application, used for styling and resources.onComplete: () -> Unit
: A callback function that is triggered upon the completion of the announcement editing process.announcement: AnnouncementEntity
: The announcement entity being edited.announcementViewModel: AnnouncementViewModel
: A ViewModel
instance for managing announcement-related data and operations.title
: A String
representing the announcement title, initialized with the existing title and managed using mutableStateOf
.description
: A String
representing the announcement description, initialized with the existing description and managed using mutableStateOf
.saveAnnouncement
function from the announcementViewModel
.AnnouncementTextField
is a Composable function that provides a styled text input field used within the AddAnnouncement
and EditAnnouncement
Composable.
modifier: Modifier
: A Modifier
instance to apply to the TextField for styling and layout. Defaults to an empty Modifier
.value: String
: The current text value of the TextField.onValueChange: (String) -> Unit
: A callback function that is triggered when the text value changes.singleLine: Boolean
: A flag indicating whether the TextField should be single-lined or multi-lined.placeholder: String
: A placeholder text displayed when the TextField is empty.context: Context
: The context of the current application, used for styling.CC
, a style configuration presumably managing theme colors for the app.singleLine
parameter.AnnouncementCard
is a Composable function that displays an announcement in a card format. It allows users to view, edit, and delete announcements, with the ability to expand or collapse the announcement details.
announcement: AnnouncementEntity
: The announcement entity to be displayed in the card.onEdit: () -> Unit
: A callback function triggered when the edit button is clicked.onDelete: (String) -> Unit
: A callback function triggered when the delete button is clicked, with the announcement ID as a parameter.context: Context
: The context of the current application, used for styling and resources.isEditing: Boolean
: A flag indicating whether the announcement is currently being edited.onEditComplete: () -> Unit
: A callback function triggered upon completion of the editing process.announcementViewModel: AnnouncementViewModel
: A ViewModel
instance for managing announcement-related data and operations.expanded
: A Boolean
state managed using mutableStateOf
, determining whether the announcement details are expanded or collapsed.isEditing
is true, the EditAnnouncement
Composable is displayed, allowing users to edit the announcement details.CC
, managing colors and text styles.expanded
state.AssignmentScreen
is a Composable function that displays a list of assignments for modules. It allows users to navigate between modules using tabs and view assignments specific to the selected module.
UniConnect
: A custom application class that provides repositories for modules and assignments.ModuleViewModel
: ViewModel for managing module-related data and operations.ModuleAssignmentViewModel
: ViewModel for managing module assignment-related data and operations.context: Context
: The context of the current application, used for styling and resources.selectedTabIndex
: An Int
state managed using mutableIntStateOf
, representing the index of the currently selected module tab.selectedModuleId
: A String?
state managed using mutableStateOf
, representing the ID of the currently selected module.isLoading
: A Boolean
state indicating whether the data is still being loaded.AssignmentCard
Composable.CC
, managing colors and text styles.AssignmentCard
is a Composable function that displays the details of a single assignment in a card format.
assignment: ModuleAssignment
: The assignment entity to be displayed in the card.context: Context
: The context of the current application, used for styling and resources.CC
, managing colors and text styles.ManageAttendanceScreen
is a Composable function that allows users to manage attendance for modules. Users can view a list of modules and toggle attendance states using switches.
UniConnect
: A custom application class that provides a module repository.ModuleViewModel
: ViewModel for managing module-related data and operations.context: Context
: The context of the current application, used for styling and resources.modules
: A list of modules fetched from ModuleViewModel
.attendanceStates
: A map of attendance states keyed by module codes.refresh
: A Boolean
state to trigger the refresh of attendance states.ModuleViewModel
.animateColorAsState
to animate the background color of module rows based on attendance state.animateContentSize
to animate the size changes of module rows.CC
, managing colors and text styles.The ModuleContent
composable is responsible for displaying detailed information about a specific module, including announcements, assignments, timetables, and other details. It dynamically fetches and displays data from various repositories based on the provided module ID.
UniConnect
).LaunchedEffect
with the targetModuleID
to trigger data fetching whenever the module ID changes.Scaffold
to provide a consistent layout structure with a container color.AsyncImage
and Text
.ScrollableTabRow
to allow users to switch between different sections (Announcements, Assignments, Timetable, Details) of the module.AnnouncementsItem
, AssignmentsItem
, TimetableItem
, and DetailsItem
.The ModuleContent
composable effectively manages and displays various aspects of a module's content, providing a tabbed interface for users to easily navigate between announcements, assignments, timetables, and other details. It uses ViewModels to handle data fetching and observes loading states to update the UI dynamically.
The AnnouncementsItem
composable displays a list of module announcements and provides an option to add new announcements. It leverages various UI components and state management to provide an interactive user experience.
remember
and mutableStateOf
to manage the visibility state of the "Add Announcement" section.ModuleAnnouncementViewModel
to display the list of announcements.FloatingActionButton
to toggle the visibility of the "Add Announcement" section.LazyColumn
to efficiently display a scrollable list of AnnouncementCard
items.The AnnouncementCard
composable represents a single announcement in a card format.
Card
to provide a bordered and colored background.The AddAnnouncementItem
composable provides a form for users to add new announcements.
remember
to store the title, description, loading state, and sender's name.ModuleAnnouncement
object.ModuleAnnouncementViewModel
and updates the UI accordingly.CircularProgressIndicator
while the announcement is being posted.The AddTextField
composable creates a reusable text field with customizable properties.
The AssignmentsItem
composable displays a list of module assignments and provides an option to add new assignments. It uses various UI components and state management to provide an interactive user experience.
remember
and mutableStateOf
to manage the visibility state of the "Add Assignment" section.ModuleAssignmentViewModel
to display the list of assignments.FloatingActionButton
to toggle the visibility of the "Add Assignment" section.IconButton
for refreshing the list of assignments.LazyColumn
to efficiently display a scrollable list of AssignmentCard
items.The AssignmentCard
composable represents a single assignment in a card format.
Card
to provide a bordered and colored background.The AddAssignmentItem
composable provides a form for users to add new assignments.
remember
to store the title, description, due date, due time, and loading state.SimpleDateFormat
to format the date and time.DatePickerDialog
and TimePickerDialog
.ModuleAssignment
object.ModuleAssignmentViewModel
and updates the UI accordingly.CircularProgressIndicator
while the assignment is being posted.Toast
message if the assignment fails to save.The UniChat
composable function is the main component for the chat screen in the Uni Admin app. It provides a user interface for viewing messages, searching users, and navigating between different sections, such as Chats and Groups. The function leverages Jetpack Compose for UI rendering, a ViewModel for managing state, and a real-time database for fetching and displaying messages.
ViewModel Integration
MessageViewModel
and UserViewModel
are used to manage message and user data.userStates
and currentUser
from UserViewModel
to track the status of users and the current user.Data Loading
LaunchedEffect
block fetches the current user's data by email and monitors the status of all users.users
list is dynamically filtered based on the searchQuery
entered by the user.UI Layout
Scaffold
as the top-level container for the chat screen.TabRow
allows switching between "Chats" and "Groups" sections, with custom animations.Chats Section
UserMessageCard
displaying their name, latest message, and online status.LazyColumn
displays the filtered list of users, updating in real-time with the latest messages.Groups Section
UniGroups
composable (implementation not shown in the snippet) that handles group functionality.UserMessageCard
ProfileImage
composable to handle profile image display and interactions.Profile Image
Annotated Message
createAnnotatedMessage
function formats messages with custom styles, such as emojis and other text elements.This overview provides insight into how the UniChat
composable function and its related components work together to create a dynamic chat interface in the Uni Admin app.
The UserChatScreen
composable function is designed to display a chat interface between the current user and a target user. It utilizes Jetpack Compose for UI rendering, handles state management through ViewModel
, and integrates with Firebase for user authentication and message storage.
ViewModel Integration
MessageViewModelFactory
with a UserGroupChatRepository
.UserViewModelFactory
with a UserRepository
.messages
, user
, user2
, and userState
LiveData, reflecting real-time updates on the UI.State Variables
userState
.Data Loading
targetUserId
.Conversation ID Generation
conversationId
is generated by combining the IDs of the current user and the target user. This ID is used to fetch and save messages in the conversation.Message Sending
sendMessage
function:UserChatEntity
with details such as message content, sender ID, recipient ID, and timestamp.UI Layout
isSearchVisible
is true, allowing the user to search through messages.Message Grouping
groupBy
, allowing the UI to display date separators between message groups.Scroll Behavior
This composable function encapsulates the logic and UI for a dynamic chat screen, handling user interactions, message sending, and real-time updates.