diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt index 946a1b44..0477b76e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt @@ -89,16 +89,17 @@ class MainActivity : ComponentActivity() { * follow Android) is loaded from it before the first frame, and saved to it in * the background whenever they change it. * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * Changed with the help of this AI tool (saving the theme choice, System option). - * Prompts: - * - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within - * the app. it disapears after app resets. Let's save it into the sqlite3 db we already have." - * - "Please make sure to also document and cite your changes." - * - "And then add a third button to the settings as system settings." + * @param savedInstanceState Previously saved activity state. */ +// Reference: +// Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. +// https://claude.com/claude-code +// Changed with the help of this AI tool (saving the theme choice, System option). +// Prompts: +// - "Okay so one thing I found was that dark mode doesn't stay if you select dark mode within +// the app. it disappears after app resets. Let's save it into the sqlite3 db we already have." +// - "Please make sure to also document and cite your changes." +// - "And then add a third button to the settings as system settings." @SuppressLint("HardwareIds") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -328,6 +329,5 @@ class MainActivity : ComponentActivity() { startupNotifPermission.launch(Manifest.permission.POST_NOTIFICATIONS) } } - } } \ No newline at end of file diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt index c19d7c48..876b64c6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt @@ -12,14 +12,14 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.example.lambda_bbb_events.MainActivity import com.example.lambda_bbb_events.R -import com.example.lambda_bbb_events.model.notification.Notification +import com.example.lambda_bbb_events.model.notifications.Notification import com.example.lambda_bbb_events.model.repository.NotificationRepository import com.example.lambda_bbb_events.model.local.NotificationHistoryStore -import com.example.lambda_bbb_events.model.notification.NotificationHistory +import com.example.lambda_bbb_events.model.notifications.NotificationHistory import java.util.UUID import com.example.lambda_bbb_events.model.local.NotificationCategoryStore -import com.example.lambda_bbb_events.model.notification.NotificationCategory -import com.example.lambda_bbb_events.model.notification.NotificationMode +import com.example.lambda_bbb_events.model.notifications.NotificationCategory +import com.example.lambda_bbb_events.model.notifications.NotificationMode /** * Builds notification and delivery as wel as preferences and history diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt index b43e8fcc..69ac0743 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt @@ -1,8 +1,8 @@ package com.example.lambda_bbb_events.model.local import android.content.Context -import com.example.lambda_bbb_events.model.notification.NotificationCategory -import com.example.lambda_bbb_events.model.notification.NotificationMode +import com.example.lambda_bbb_events.model.notifications.NotificationCategory +import com.example.lambda_bbb_events.model.notifications.NotificationMode import java.util.concurrent.TimeUnit /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt index deb363a3..b618a0f9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt @@ -1,7 +1,7 @@ package com.example.lambda_bbb_events.model.local import android.content.Context -import com.example.lambda_bbb_events.model.notification.NotificationHistory +import com.example.lambda_bbb_events.model.notifications.NotificationHistory import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.callbackFlow import android.content.SharedPreferences diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt index 9e47479e..3239d35a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt @@ -40,8 +40,9 @@ data class WaitlistEntry ( init { require(numberOfGuests >= 1) { "numberOfGuests must be at least 1" } } + /** - * Updates the waitlist entry status to "declined". + * Updates the waitlist entry status to [WaitlistStatus.DECLINED]. */ fun declineEntry() { status = WaitlistStatus.DECLINED diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt index ff5ce92d..01510b5c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt @@ -22,7 +22,7 @@ import com.google.firebase.Timestamp * Represents a private conversation between a camper and one other person: a campsite * owner or a specific administrator. * - * There is one conversation per pair of people, no matter how many of the owner's + * There is one conversation per a pair of people, no matter how many of the owner's * campsites the camper is enrolled in, so each contact appears once. Each conversation * contains multiple messages stored in a Firestore subcollection. * @@ -65,6 +65,7 @@ class Conversation( * Whether [personId] is one of the two people in this conversation. * * @param personId Device ID to check. + * @return `true` if the person is a participant, `false` if otherwise. */ fun hasParticipant(personId: String): Boolean { return personId.isNotBlank() && @@ -74,6 +75,8 @@ class Conversation( /** * Whether this conversation uses the one-per-pair ID scheme. Conversations from before * it were kept per campsite and shared by all administrators, and are no longer shown. + * + * @return `true` if the conversation uses the current ID, `false` if otherwise. */ fun hasCurrentId(): Boolean { val expectedId = when (type) { @@ -91,6 +94,7 @@ class Conversation( * * @param userId Device ID of the camper. * @param ownerId Device ID of the campsite owner. + * @return The generated owner conversation ID. */ fun ownerConversationId(userId: String, ownerId: String): String = "owner_${userId}_${ownerId}" @@ -100,6 +104,7 @@ class Conversation( * * @param userId Device ID of the camper. * @param adminId Device ID of the administrator. + * @return The generated administrator conversation ID. */ fun adminConversationId(userId: String, adminId: String): String = "admin_${userId}_${adminId}" diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt index 749a9c98..8b9fb15d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt @@ -1,6 +1,18 @@ package com.example.lambda_bbb_events.model.message import com.google.firebase.Timestamp +/* + * Defines messages exchanged between users, campsite owners, and administrators. + */ + +//Reference: +//Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. +//https://claude.com/claude-code +//The deleted property, canBeDeletedBy, and DELETED_TEXT were written with the help of this AI tool. +//Prompts: +//- "Also please clean up a database and offer a way for users to delete messages with a message +// deleted plus. Show also that messages are active." +//- "So to clarify I want to allow users and admins to remove messages." /** * Represents a message exchanged between users, campsite @@ -15,15 +27,6 @@ import com.google.firebase.Timestamp * @property deleted Whether the message was deleted. A deleted * message keeps its place in the conversation, * but its content is removed. - * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * The deleted property, canBeDeletedBy, and DELETED_TEXT were written with the help of this AI tool. - * Prompts: - * - "Also please clean up a database and offer a way for users to delete messages with a message - * deleted plus. Show also that messages are active." - * - "So to clarify I want to allow users and admins to remove messages." */ class Message( val messageId: String = "", @@ -40,24 +43,25 @@ class Message( * * @param personId Device ID of the person asking to delete the message. * @param isAdmin Whether that person is an administrator. + * @return `true` if the person is allowed to delete message, `false` if otherwise. */ fun canBeDeletedBy(personId: String, isAdmin: Boolean): Boolean { return !deleted && personId.isNotBlank() && (senderId == personId || isAdmin) } +// Reference: +// Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. +// https://claude.com/claude-code +// Written with the help of this AI tool. +// Prompts: +// - "Can you combine the message timestamps because it's a bit weird to put it in multiple +// places for the same time." /** * Whether this message is part of the same group as [other], so only one of them needs * to show the time: they have the same sender and were sent in the same minute. * * @param other A message next to this one in the conversation. - * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * Written with the help of this AI tool. - * Prompts: - * - "Can you combine the message timestamps because it's a bit weird to put it in multiple - * places for the same time." + * @return `true` if both messages have same sender and were sent same minute, `false` if otherwise. */ fun isGroupedWith(other: Message): Boolean { return senderId == other.senderId && diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt index 302b2cf2..f728178c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt @@ -1,5 +1,9 @@ package com.example.lambda_bbb_events.model.message +/* + * Defines messaging permissions between users and campsite owners. + */ + /** * Represents a user's messaging access for a campsite. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt index f9e2bdac..3d8277e1 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt @@ -2,6 +2,10 @@ package com.example.lambda_bbb_events.model.message import com.google.firebase.Timestamp +/* + * Stores notification preferences for individual contacts. + */ + /** * Represents a user's notification preferences for a contact. * @@ -26,10 +30,8 @@ class NotificationPreference( * or the temporary mute has not expired. */ fun isMuted(): Boolean { - if (!muted) return false - - return mutedUntil?.let { - it.compareTo(Timestamp.now()) > 0 + return muted && mutedUntil?.let { + it > Timestamp.now() } ?: true } } \ No newline at end of file diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt index a5b7d296..9fd4d72e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt @@ -1,23 +1,9 @@ -package com.example.lambda_bbb_events.model.notification +package com.example.lambda_bbb_events.model.notifications /* * Model classes for notifications. - * - * TODO Notification Actions */ - -///** TO BE WORKED ON LATER FOR FURTHER NOTIF FUNCTION -// * Buttons and functionality for notification. -// * -// * @property notifType text of action buttons of notification. -// * @property actionType Identifier for -// */ -//data class NotificationFunction( -// val notifType: String, -// val actionType: String -//) - /** * A data class for notification structure . * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt index 28cdb213..3defd033 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt @@ -1,4 +1,8 @@ -package com.example.lambda_bbb_events.model.notification +package com.example.lambda_bbb_events.model.notifications + +/* + * Defines notification categories and delivery modes. + */ /** * Represents the categories of system notifications. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt index 5a2b5981..94570a36 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt @@ -1,7 +1,16 @@ -package com.example.lambda_bbb_events.model.notification +package com.example.lambda_bbb_events.model.notifications + +/* + * Defines notification history entries saved locally for each user. + */ /** * Represents a notification saved in the user's history. + * + * @property id Unique identifier of the notification. + * @property title Title of the notification. + * @property message Body text of the notification. + * @property timestamp Time when the notification was saved, in milliseconds. */ data class NotificationHistory( val id: String, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt index 615d0e5e..d1fc83b2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt @@ -6,6 +6,9 @@ import com.google.firebase.Timestamp import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.FirebaseFirestore import kotlinx.coroutines.tasks.await +/* + * Retrieves admin notification and message logs from Firebase. + */ /** * Repository responsible for retrieving notification and message @@ -35,7 +38,7 @@ class AdminLogRepository( * * @return A list of notification logs. */ - suspend fun getNotificationLogs(): List { + fun getNotificationLogs(): List { // TODO: Retrieve notification logs once implemented. return emptyList() } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt index 70d5a3f1..2e9e8473 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt @@ -13,6 +13,10 @@ import com.google.firebase.firestore.firestore import kotlinx.coroutines.tasks.await import java.time.LocalDate +/* + * Defines Firestore campsite data models and handles campsite data conversion and storage. + */ + /** * Represents a Firestore campsite listing. * @@ -57,7 +61,11 @@ data class FirestoreCampsite( val createdAt: Long = 0L ) -/** Represents campsite availability with string date keys for Firestore serialization. */ +/** + * Represents campsite availability with string date keys for Firestore serialization. + * + * @property dates The campsite's available dates and their booking counts. + */ data class FirestoreAvailabilitySchedule( var dates: MutableMap = mutableMapOf() ) @@ -65,6 +73,8 @@ data class FirestoreAvailabilitySchedule( /** * Converts a [Campsite] into its Firestore representation. Availability dates are stored * as ISO-8601 strings since Firestore cannot store [LocalDate] keys. + * + * @return The Firestore representation of the campsite. */ fun Campsite.toFirestore() = FirestoreCampsite( campsiteId = campsiteId, @@ -92,6 +102,7 @@ fun Campsite.toFirestore() = FirestoreCampsite( * Converts a [FirestoreCampsite] back into a [Campsite]. * * @param id The ID of the campsite, defaults to the stored campsite ID. + * @return The campsite represented by this Firestore object. * @throws java.time.format.DateTimeParseException if an availability date is malformed. */ fun FirestoreCampsite.toCampsite(id: String = campsiteId) = Campsite( @@ -118,18 +129,43 @@ fun FirestoreCampsite.toCampsite(id: String = campsiteId) = Campsite( /** * Handles the data in the Firestore database for the [Campsite] class. + * + * @param db The Firestore database instance. */ class CampsiteRepository( db: FirebaseFirestore = Firebase.firestore ) : Repository("campsites", db) { + /** + * Gets the ID of a campsite. + * + * @param item The campsite. + * @return The campsite ID. + */ override fun idOf(item: Campsite) = item.campsiteId + /** + * Converts a Firestore document into a campsite. + * + * @param document The Firestore document to convert. + * @return The campsite, or null if it cannot be converted. + */ override fun fromDocument(document: DocumentSnapshot): Campsite? = document.toObject(FirestoreCampsite::class.java)?.toCampsite(document.id) + /** + * Converts a campsite into its Firestore representation. + * + * @param item The campsite to convert. + * @return The Firestore representation of the campsite. + */ override fun toDocument(item: Campsite): Any = item.toFirestore() + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("CampsiteRepository", "listener error", error) } @@ -148,7 +184,12 @@ class CampsiteRepository( */ suspend fun deleteCampsite(campsiteID: String) = delete(campsiteID) - /** Deletes a campsite and queues deletion of its lotteries in the same Firestore batch. */ + /** + * Deletes a campsite and queues deletion of its lotteries in the same Firestore batch. + * + * @param campsiteId The ID of the campsite to delete. + * @param lotteryRepository The repository used to queue lottery deletions. + */ suspend fun deleteCampsiteWithLotteries( campsiteId: String, lotteryRepository: LotteryRepository @@ -241,6 +282,8 @@ class CampsiteRepository( /** * Grabs all campsites that exist and returns them keyed by campsite ID. + * + * @return A map of campsite IDs to their corresponding campsites. */ suspend fun getAllCampsites(): MutableMap { val campsites = mutableMapOf() diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt index ba4ec98b..0dfe0cfc 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt @@ -15,13 +15,17 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.tasks.await +/* + * Handles creating, retrieving, and observing conversations in Firestore. + */ + /* * Reference: * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. * https://claude.com/claude-code * This whole file was written with the help of this AI tool. * Prompts: - * - "Now on the notification page as well. Please also remove the profile duplication bug. Also + * - "Now on the notification page as well. Please also remove the profile duplication bug. Also, * please fix the way the admins work since it seems all admins share an account. One more thing * is to fix the notification page so that the spacing looks right." * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate @@ -29,7 +33,6 @@ import kotlinx.coroutines.tasks.await * - "Okay so there are no conversations yet so can I have admins be able to message users from * the profile admin screen" */ - /** * Manages conversations stored in Firebase Firestore. * @@ -37,7 +40,7 @@ import kotlinx.coroutines.tasks.await * campers and campsite owners or individual administrators. Only conversations that use * the one-per-pair ID scheme are returned, see [Conversation.hasCurrentId]. * - * @param db Firestore database instance. + * @property db Firestore database instance. */ class ConversationRepository( private val db: FirebaseFirestore = Firebase.firestore @@ -360,7 +363,7 @@ class ConversationRepository( * Observes conversations matching a Firestore query. * * Removes the snapshot listener when the Flow - * collection is cancelled. + * collection is canceled. * * @param query Firestore query defining conversations. * @return Flow containing conversations ordered by recent activity. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt index 0ce50b57..06ca8d03 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt @@ -9,17 +9,35 @@ import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.firestore import kotlinx.coroutines.tasks.await +/* + * Image functions such as storing, retrieving and deleting metadata and chunks in Firestore. + */ + /** * Handles the data in the Firestore database for images. Each image's [ImageMetaData] is * stored as a document, and its [ImageChunk]s are stored in that document's `chunks` * subcollection. + * + * @param db The Firestore database instance. */ class ImageRepository( db: FirebaseFirestore = Firebase.firestore ) : Repository("images", db) { + /** + * Gets the ID of an image. + * + * @param item The image metadata. + * @return The image ID. + */ override fun idOf(item: ImageMetaData) = item.imageId + /** + * Converts a Firestore document into image metadata. + * + * @param document The Firestore document to convert. + * @return The image metadata, or null if conversion fails. + */ override fun fromDocument(document: DocumentSnapshot): ImageMetaData? = document.toObject(ImageMetaData::class.java) @@ -39,7 +57,13 @@ class ImageRepository( super.delete(id) } - /** Saves image metadata and the chunks that make up the encoded image. */ + /** + * Saves image metadata and the chunks that make up the encoded image. + * + * @param metadata The image metadata to save. + * @param chunks The image chunks to upload. + * @return true if the upload succeeds, false if otherwise. + */ suspend fun uploadImage( metadata: ImageMetaData, chunks: List @@ -59,7 +83,12 @@ class ImageRepository( } } - /** Loads an image's chunks in priority order, returning an empty list if the read fails. */ + /** + * Loads an image's chunks in priority order, returning an empty list if the read fails. + * + * @param imageId The ID of the image. + * @return The image chunks, ordered by priority. + */ suspend fun getImageChunks( imageId: String ): List { @@ -70,10 +99,7 @@ class ImageRepository( for (document in documents) { // Skip chunks that are missing their image data - val blob = document.getBlob("imageBytes") - if (blob == null) { - continue - } + val blob = document.getBlob("imageBytes") ?: continue chunks.add( ImageChunk( @@ -91,7 +117,12 @@ class ImageRepository( } } - /** Loads the stored metadata for [imageId], if available. */ + /** + * Loads the stored metadata for [imageId], if available. + * + * @param imageId The ID of the image. + * @return The image metadata, or null if it fails. + */ suspend fun getImageMetadata( imageId: String ): ImageMetaData? { @@ -103,7 +134,13 @@ class ImageRepository( } } - /** Loads the ordered chunks for an image with stored metadata. */ + /** + * Loads the ordered chunks for an image with stored metadata. + * + * @param imageId The ID of the image. + * @return The image chunks, ordered by priority. + * @throws IllegalStateException if the metadata is missing or some chunks are missing. + */ suspend fun getImage( imageId: String ): List { @@ -119,7 +156,12 @@ class ImageRepository( return chunks } - /** Deletes the image and its chunks, returning whether the operation succeeded. */ + /** + * Deletes the image and its chunks, returning whether the operation succeeded. + * + * @param imageId The ID of the image to delete. + * @return true if the deletion succeeds, false otherwise. + */ suspend fun deleteImage( imageId: String ): Boolean { diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt index 72fb81b5..31db2ea4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt @@ -23,9 +23,10 @@ import java.util.Date * Manages lottery and waitlist data in Firestore. */ - /** * Handles the data in the Firestore database for the [Lottery] class. + * + * @param db The Firestore database instance. */ class LotteryRepository( db: FirebaseFirestore = Firebase.firestore @@ -35,8 +36,20 @@ class LotteryRepository( startListening() } + /** + * Gets the ID of a lottery. + * + * @param item The lottery. + * @return The lottery ID. + */ override fun idOf(item: Lottery) = item.lotteryId + /** + * Converts a Firestore document into a lottery. + * + * @param document The Firestore document to convert. + * @return The lottery, or null if conversion fails. + */ override fun fromDocument(document: DocumentSnapshot): Lottery? = document.toObject(Lottery::class.java) @@ -158,7 +171,12 @@ class LotteryRepository( return notified } - /** Adds deletion operations for the campsite's lotteries to the caller's Firestore batch. */ + /** + * Adds deletion operations for the campsite's lotteries to the caller's Firestore batch. + * + * @param batch The Firestore batch to add the deletion operations to. + * @param campsiteId The ID of the campsite whose lotteries are being deleted. + */ internal suspend fun queueCampsiteLotteryDeletions( batch: WriteBatch, campsiteId: String @@ -514,7 +532,7 @@ class LotteryRepository( val entry = transaction.get(entryDocument.reference) .toObject(WaitlistEntry::class.java) - ?: return@runTransaction Unit + ?: return@runTransaction if (entry.entrantId != entrantId) { return@runTransaction Unit diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt index 2049db53..dc831e26 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt @@ -17,6 +17,10 @@ import com.google.firebase.firestore.firestore import kotlinx.coroutines.tasks.await import java.util.Date +/* + * Handles storing, retrieving, and deleting messages within a conversation. + */ + /** * Handles message data stored within a conversation * in the Firestore database. @@ -24,7 +28,7 @@ import java.util.Date * Synchronizes messages with Firestore and maintains * a local cache of conversation messages. * - * @param conversationId Unique identifier of the conversation. + * @property conversationId Unique identifier of the conversation. * @param db Firestore database instance. */ class MessageRepository( @@ -85,7 +89,7 @@ class MessageRepository( * Changed with the help of this AI tool. * Prompts: * - "Now on the notification page as well. Please also remove the profile duplication bug. - * Also please fix the way the admins work since it seems all admins share an account. One + * Also, please fix the way the admins work since it seems all admins share an account. One * more thing is to fix the notification page so that the spacing looks right." * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate * chats per admin". @@ -161,15 +165,6 @@ class MessageRepository( * @param requesterId Device ID of the person deleting it. * @param isAdmin Whether that person is an administrator. * @throws IllegalStateException If the message does not exist or the person may not delete it. - * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * Written with the help of this AI tool. - * Prompts: - * - "Also please clean up a database and offer a way for users to delete messages with a - * message deleted plus. Show also that messages are active." - * - "So to clarify I want to allow users and admins to remove messages." */ suspend fun deleteMessage( messageId: String, @@ -227,19 +222,18 @@ class MessageRepository( * * @param entrantId Device ID of the entrant. * @param ownerId Device ID of the campsite owner. - * @return True if the entrant remains eligible for owner messaging. - * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * Written with the help of this AI tool. - * Prompts: - * - "Now on the notification page as well. Please also remove the profile duplication bug. - * Also please fix the way the admins work since it seems all admins share an account. One - * more thing is to fix the notification page so that the spacing looks right." - * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate - * chats per admin". + * @return True if the entrant remains eligible for owner messaging */ +// Reference: +// Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. +// https://claude.com/claude-code +// Written with the help of this AI tool. +// Prompts: +// - "Now on the notification page as well. Please also remove the profile duplication bug. +// Also, please fix the way the admins work since it seems all admins share an account. One +// more thing is to fix the notification page so that the spacing looks right." +// - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate +// chats per admin". suspend fun hasEligibleOwnerAccess( entrantId: String, ownerId: String diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt index e8918584..27844efe 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt @@ -6,13 +6,17 @@ import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.firestore +/* + * Manages a user's campsite messaging access records in Firestore. + */ + /** * Manages messaging access records associated with a user. * * Synchronizes campsite messaging access with Firestore * and provides information about available contacts. * - * @param userId Device ID of the user. + * @param userId Unique ID of the user. * @param db Firestore database instance. */ class MessagingAccessRepository( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt index 21d3164d..1ed778f2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt @@ -7,13 +7,17 @@ import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.firestore +/* + * Manages a user's notification preferences in Firestore. + */ + /** * Manages notification preferences associated with a user. * * Supports temporary muting, indefinite muting, * and enabling notifications from specific contacts. * - * @param userId Device ID of the current user. + * @param userId Unique ID of the current user. * @param db Firestore database instance. */ class NotificationPreferenceRepository( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt index 99b57a4c..5e584948 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt @@ -8,7 +8,7 @@ import android.content.Context import androidx.core.app.NotificationManagerCompat /* - * creates notification channel so controller can build upon it + * Creates notification channels and posts notifications through the Android push notifications. */ /** @@ -57,7 +57,6 @@ class NotificationRepository( * @param notification The built notification from controller. */ // suppress warning in repository as checks happen in controller - /** Posts [notification] using [id] after the caller has checked notification permissions. */ @SuppressLint("MissingPermission") fun showNotification(id: Int, notification: Notification) { NotificationManagerCompat.from(context).notify(id, notification) diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt index 0f3d7987..d393c416 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt @@ -10,6 +10,10 @@ import com.google.firebase.firestore.ListenerRegistration import com.google.firebase.firestore.firestore import kotlinx.coroutines.tasks.await +/* + * Provides common Firestore operations and caching for repository subclasses. + */ + /** * Base class for every repository backed by a single Firestore collection. * @@ -22,7 +26,7 @@ import kotlinx.coroutines.tasks.await * * @param T The model class stored in the collection. * @param collectionName The name of the Firestore collection. - * @param db The Firestore instance to use. + * @property db The Firestore instance used by repository. */ abstract class Repository( collectionName: String, @@ -180,6 +184,8 @@ abstract class Repository( /** * Inserts an item into the cache, replacing any cached item with the same ID. + * + * @param item item to put in cache */ protected fun putInCache(item: T) { val id = idOf(item) @@ -195,6 +201,8 @@ abstract class Repository( /** * Removes the item with the given ID from the cache. + * + * @param id The ID of the item to remove from cache */ protected fun removeFromCache(id: String) { synchronized(_cache) { @@ -211,17 +219,22 @@ abstract class Repository( /** * Converts a document into an item, or returns `null` if it is not a valid item. + * + * @param document document to convert to an item or 'null' if it is not a valid item */ private fun convert(document: DocumentSnapshot): T? { - try { - return fromDocument(document) + return try { + fromDocument(document) } catch (e: Exception) { - return null + null } } /** * Converts every document into an item, skipping documents that are not valid items. + * + * @param documents List of documents to convert to an item, skips documents that + * cannot be converted to item */ private fun convertAll(documents: List): List { val items = mutableListOf() diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt index d8920313..3ed7efc3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt @@ -15,9 +15,12 @@ import com.google.firebase.firestore.firestore import kotlinx.coroutines.CancellationException import kotlinx.coroutines.tasks.await import java.time.LocalDate -import java.time.ZoneId import java.util.Date +/* + * Manages campsite reservations in Firestore and maintains messaging eligibility. + */ + /** * Handles reservation data and cached records using Firestore. * @@ -34,9 +37,21 @@ class ReservationRepository( startListening() } + /** + * Gets the ID of a reservation. + * + * @param item The reservation. + * @return The reservation ID. + */ override fun idOf(item: Reservation) = item.reservationId + /** + * Converts a Firestore document into a reservation. + * + * @param document The Firestore document to convert. + * @return The reservation, or null if conversion fails. + */ override fun fromDocument( document: DocumentSnapshot ): Reservation? = @@ -149,7 +164,7 @@ class ReservationRepository( "Lottery not found." ) - // Prevent reservations for cancelled lotteries. + // Prevent reservations for canceled lotteries. check(lottery.status != LotteryStatus.CANCELLED) { "This lottery has been cancelled." } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt index 17d26970..5c058494 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt @@ -14,6 +14,8 @@ import com.google.firebase.firestore.firestore /** * Handles the data in the Firestore database for the [ReviewReaction] class. + * + * @param db The Firestore database instance. */ class ReviewReactionRepository( db: FirebaseFirestore = Firebase.firestore @@ -23,11 +25,28 @@ class ReviewReactionRepository( startListening() } + /** + * Gets the ID of a review reaction. + * + * @param item The review reaction. + * @return The reaction ID. + */ override fun idOf(item: ReviewReaction) = item.reactionId + /** + * Converts a Firestore document into a review reaction. + * + * @param document The Firestore document to convert. + * @return The review reaction, or null if conversion fails or if the reaction is invalid. + */ override fun fromDocument(document: DocumentSnapshot): ReviewReaction? = document.toObject(ReviewReaction::class.java)?.takeIf { it.isValid() } + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("ReviewReactionRepository", "listener error", error) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt index 8f33c938..3400f5cf 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt @@ -14,6 +14,8 @@ import com.google.firebase.firestore.firestore /** * Handles the data in the Firestore database for the [ReviewReply] class. + * + * @param db The Firestore database instance. */ class ReviewReplyRepository( db: FirebaseFirestore = Firebase.firestore @@ -23,23 +25,44 @@ class ReviewReplyRepository( startListening() } + /** + * Gets the ID of a review reply. + * + * @param item The review reply. + * @return The reply ID. + */ override fun idOf(item: ReviewReply) = item.replyId + /** + * Converts a Firestore document into a review reply. + * + * @param document The Firestore document to convert. + * @return The review reply, or null if conversion fails or the reply is invalid. + */ override fun fromDocument(document: DocumentSnapshot): ReviewReply? = document.toObject(ReviewReply::class.java)?.takeIf { it.isValid() } + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("ReviewReplyRepository", "listener error", error) } - /** Makes a new, unused ID for a reply. */ + /** + * Makes a new, unused ID for a reply. + * + * @return A new reply ID. + */ fun newReplyId(): String = collectionRef.document().id /** * Gets every reply to a review from the cache. * * @param reviewId The ID of the review. - * @return The replies, in no particular order. + * @return The replies to the review */ fun getRepliesFor(reviewId: String): List = cached.filter { it.reviewId == reviewId } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt index 59bf74f1..7740595a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt @@ -22,6 +22,8 @@ import kotlin.math.roundToInt * Campsites store their average rating and number of reviews, so every change to a review also * updates its campsite. Both are written in one transaction, so they always agree, even when * several users review a campsite at the same time. + * + * @param db The Firestore database instance. */ class ReviewRepository( db: FirebaseFirestore = Firebase.firestore @@ -31,11 +33,28 @@ class ReviewRepository( startListening() } + /** + * Gets the ID of a review. + * + * @param item The review. + * @return The review ID. + */ override fun idOf(item: Review) = item.reviewId + /** + * Converts a Firestore document into a review. + * + * @param document The Firestore document to convert. + * @return The review, or null if conversion fails or if the review is invalid. + */ override fun fromDocument(document: DocumentSnapshot): Review? = document.toObject(Review::class.java)?.takeIf { it.isValid() } + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("ReviewRepository", "listener error", error) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt index 1976064f..df83a729 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt @@ -28,6 +28,8 @@ class WrongAdminPasswordException : Exception("The admin password was not accept /** * Handles the data in the Firestore database for the [User] class. + * + * @param db The Firestore database instance */ class UserRepository( db: FirebaseFirestore = Firebase.firestore @@ -40,12 +42,19 @@ class UserRepository( val users: List get() = cached + /** + * Gets the device ID of a user. + * + * @param item The user. + * @return The user's device ID. + */ override fun idOf(item: User) = item.deviceId /** * Converts a Firestore document into the appropriate User subtype * based on its role field. * + * @param document The Firestore document to be converted * @return The deserialized User, or null if the role is unknown. */ override fun fromDocument(document: DocumentSnapshot): User? = @@ -56,6 +65,11 @@ class UserRepository( else -> null } + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("UserRepository", "listener error", error) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt index 2f8ceff2..8ebd6c33 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt @@ -21,6 +21,8 @@ import kotlinx.coroutines.tasks.await /** * Handles the data in the Firestore database for the [WaitlistEntry] class. + * + * @param db The Firestore database instance. */ class WaitlistEntryRepository( db: FirebaseFirestore = Firebase.firestore @@ -30,11 +32,28 @@ class WaitlistEntryRepository( startListening() } + /** + * Gets the ID of a waitlist entry. + * + * @param item The waitlist entry. + * @return The entry ID. + */ override fun idOf(item: WaitlistEntry) = item.entryId + /** + * Converts a Firestore document into a waitlist entry. + * + * @param document The Firestore document to convert. + * @return The waitlist entry, or null if conversion fails. + */ override fun fromDocument(document: DocumentSnapshot): WaitlistEntry? = document.toObject(WaitlistEntry::class.java) + /** + * Logs an error that occurs while listening for Firestore updates. + * + * @param error The Firestore error. + */ override fun onListenError(error: FirebaseFirestoreException) { Log.e("WaitlistEntryRepo", "listener error", error) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt index 52e1c709..e8e05583 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt @@ -65,9 +65,7 @@ data class Reservation( */ @Exclude fun isMessagingEligible(): Boolean { - if (!isActive()) return false - - return try { + return isActive() && try { !LocalDate.parse(endDate).isBefore(LocalDate.now()) } catch (e: DateTimeParseException) { false diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt index 3c3559b4..5a61a1a8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt @@ -28,6 +28,8 @@ data class Review( /** * Whether the review has the right ID for its campsite and reviewer, a rating in range, * and a comment that is not too long. + * + * @return 'true' if the review is valid, and 'false' if otherwise. */ @Exclude fun isValid(): Boolean { @@ -38,7 +40,9 @@ data class Review( } companion object { + /** The minimum rating a review can have. */ const val MIN_RATING = 1 + /** The maximum rating a review can have. */ const val MAX_RATING = 5 /** The longest comment a review can have, in characters. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt index b4581203..d431adc8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt @@ -20,7 +20,11 @@ data class ReviewReaction( val reactorId: String = "", val emoji: String = "" ) { - /** Whether the reaction has the right ID for its review and user, and an allowed emoji. */ + /** + * Whether the reaction has the right ID for its review and user, and an allowed emoji. + * + * @return 'true' if reaction is valid, and 'false' if otherwise. + */ @Exclude fun isValid(): Boolean { return reviewId.isNotBlank() && reactorId.isNotBlank() && diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt index 5343c52f..04c7a701 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt @@ -23,7 +23,11 @@ data class ReviewReply( val text: String = "", val repliedAt: Date = Date() ) { - /** Whether the reply has its IDs, and text that is not blank or too long. */ + /** + * Whether the reply has its IDs, and text that is not blank or too long. + * + * @return 'true' if the reply is valid, and 'false' if otherwise. + */ @Exclude fun isValid(): Boolean { return replyId.isNotBlank() && reviewId.isNotBlank() && authorId.isNotBlank() && diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt index bfb783bc..1a43d71f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt @@ -28,6 +28,7 @@ data class AndroidAppIdentity(val packageName: String, val certificateSha1: Stri /** * Reads the identity of the running app. * + * @param context The Android context used to read the app's signing certificate. * @return The identity, or `null` if the app's signature cannot be read. */ fun of(context: Context): AndroidAppIdentity? { @@ -51,7 +52,12 @@ data class AndroidAppIdentity(val packageName: String, val certificateSha1: Stri return info.signatures?.firstOrNull() } - /** Formats the SHA-1 of [bytes] the way Google expects it. */ + /** + * Formats the SHA-1 of [bytes] the way Google expects it. + * + * @param bytes The certificate bytes to hash. + * @return The SHA-1 hash in uppercase hexadecimal. + */ internal fun sha1Hex(bytes: ByteArray): String = MessageDigest.getInstance("SHA-1").digest(bytes).joinToString("") { "%02X".format(it) } } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt index 280cd0d1..18f1cce7 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt @@ -9,7 +9,9 @@ package com.example.lambda_bbb_events.model.services * * Other failures, such as being offline, are not the key's fault and do not switch. * - * @param fallback Decides which service to use, and is told when Google fails. + * @property fallback Decides which service to use, and is told when Google fails. + * @property google The Google place search service. + * @property photon The Photon place search service. */ class FallbackPlaceSearch( private val fallback: MapFallback = MapFallback.shared, @@ -17,6 +19,15 @@ class FallbackPlaceSearch( private val photon: PlaceSearch = PhotonPlaceSearch() ) : PlaceSearch { + /** + * Searches for place suggestions using the selected provider. + * + * @param query The place name or search text. + * @param nearLatitude The latitude to search near. + * @param nearLongitude The longitude to search near. + * @param sessionToken The session token for the search. + * @return The matching place suggestions. + */ override suspend fun suggest( query: String, nearLatitude: Double, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt index 024087f9..f925554a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt @@ -2,12 +2,14 @@ package com.example.lambda_bbb_events.model.services import android.util.Log import com.google.firebase.messaging.FirebaseMessaging -import com.example.lambda_bbb_events.BuildConfig import com.google.firebase.Firebase -import com.google.firebase.FirebaseApp import com.google.firebase.firestore.FieldValue import com.google.firebase.firestore.firestore +/* + * Registers and saves the device's Firebase Cloud Messaging token. + */ + /** * Retrieves the Firebase Cloud Messaging registration token * for the current device. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt index 2e4b7438..7537721b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt @@ -1,12 +1,16 @@ package com.example.lambda_bbb_events.model.services import android.util.Log -import com.example.lambda_bbb_events.model.notification.Notification +import com.example.lambda_bbb_events.model.notifications.Notification import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow +/* + * Receives Firebase Cloud Messaging messages and handles token updates. + */ + /** * Receives incoming Firebase Cloud Messaging messages * and handles registration token updates. @@ -20,10 +24,16 @@ class FirebaseNotificationService : FirebaseMessagingService() { extraBufferCapacity = 16 ) + /** A flow of incoming notifications received by the service. */ val incomingNotifications = _incomingNotifications.asSharedFlow() } + /** + * Handles an incoming Firebase Cloud Messaging message. + * + * @param message The message received from Firebase. + */ override fun onMessageReceived(message: RemoteMessage) { super.onMessageReceived(message) @@ -45,6 +55,11 @@ class FirebaseNotificationService : FirebaseMessagingService() { Log.d("FCM", "Notification received") } + /** + * Saves the new Firebase Cloud Messaging registration token. + * + * @param token The updated FCM registration token. + */ override fun onNewToken(token: String) { super.onNewToken(token) val deviceId = android.provider.Settings.Secure.getString( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt index 4e6053d6..207cb4c9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt @@ -14,8 +14,14 @@ import com.example.lambda_bbb_events.model.repository.ImageRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +/* + * Prepares images for storage and loads them back for display. + */ + /** * Prepares images for storage and loads them back for display. + * + * @property imageRepository The repository used to store and retrieve image data. */ class ImageProcessor( private val imageRepository: ImageRepository = ImageRepository() @@ -29,6 +35,10 @@ class ImageProcessor( * [targetWidth] by [targetHeight] pixel area. A `null` or non-positive target places * no limit on that dimension. * + * @param sourceWidth The original image width in pixels. + * @param sourceHeight The original image height in pixels. + * @param targetWidth The target width, or null for no width limit. + * @param targetHeight The target height, or null for no height limit. * @return The sample size, or 1 if neither target is given. */ fun sampleSizeFor(sourceWidth: Int, sourceHeight: Int, targetWidth: Int?, targetHeight: Int?): Int { @@ -51,7 +61,10 @@ class ImageProcessor( } /** + * Scales an image down to fit within the maximum dimensions. * + * @param image The image to scale. + * @return The scaled image. */ fun downscaleImage(image: Bitmap): Bitmap { val maxWidth = 1440 @@ -62,7 +75,11 @@ class ImageProcessor( } /** + * Splits an image into JPEG chunks. * + * @param imageId The ID of the image. + * @param bitmap The image to split. + * @return The image chunks, ordered by priority. */ fun splitImage(imageId: String, bitmap: Bitmap): List { if (bitmap.width <= 0 || bitmap.height <= 0) { @@ -93,6 +110,8 @@ class ImageProcessor( * * @param chunks The chunks of a single image. * @param sampleSize Decodes every chunk at 1/[sampleSize] of its size. Must be a power of 2. + * @return The reconstructed image. + * */ fun rebuildImage( chunks: List, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt index b154af18..14ada1d8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt @@ -21,13 +21,17 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.launch +/* + * Listens for incoming chat messages and triggers Android notifications. + */ + /** * Listens for incoming chat messages while the application * is running and triggers Android notifications. * - * @param messageController Controller for messaging operations. - * @param notificationController Controller for message notifications. - * @param db Firestore database instance. + * @property messageController Controller for messaging operations. + * @property notificationController Controller for message notifications. + * @property db Firestore database instance. */ class IncomingMessageListener( private val messageController: MessageController, @@ -39,7 +43,7 @@ class IncomingMessageListener( * Observes conversations associated with the current user * and starts listening for new messages. * - * Listeners are removed when the coroutine is cancelled. + * Listeners are removed when the coroutine is canceled. * * @param context Android application context. * @param isAdmin Whether the current user is an administrator. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt index 4197a65c..a148bd6f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt @@ -2,11 +2,15 @@ package com.example.lambda_bbb_events.model.services import com.example.lambda_bbb_events.model.lottery.Lottery +/* + * The function for drawing lottery winners and losers. + */ /** * Draws lottery winners and losers * * @param lottery Lottery to be drawn + * @return A list containing the winners followed by the losers. */ fun draw_winners(lottery: Lottery): MutableList< MutableList >{ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt index bd3c4bd6..dbb6051e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt @@ -10,6 +10,10 @@ import androidx.core.graphics.scale import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +/* + * Decodes photos selected by the user into bitmaps. + */ + /** * Reads a photo the user picked into a bitmap. Reading a large photo is slow, so it is done * off the main thread to keep the screen responsive. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt index ea6d6070..1a9da9b3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt @@ -33,6 +33,15 @@ private val LIMIT_STATUSES = setOf(429, 403) */ class PhotonPlaceSearch : PlaceSearch { + /** + * Searches OpenStreetMap for place suggestions using Photon. + * + * @param query The place name or search text. + * @param nearLatitude The latitude to search near. + * @param nearLongitude The longitude to search near. + * @param sessionToken The session token for the search. + * @return The matching place suggestions. + */ override suspend fun suggest( query: String, nearLatitude: Double, @@ -61,6 +70,13 @@ class PhotonPlaceSearch : PlaceSearch { } } + /** + * Gets the details of a selected place suggestion. + * + * @param suggestion The place suggestion to retrieve. + * @param sessionToken The session token for the search. + * @return The details of the selected place. + */ // Photon's suggestions already have their details, so this does not need a request override suspend fun getPlace(suggestion: PlaceSuggestion, sessionToken: String): PlaceDetails = suggestion.details ?: throw IOException("The place has no location") @@ -69,6 +85,9 @@ class PhotonPlaceSearch : PlaceSearch { /** * Reads the places in a Photon response. Places without a name or location are skipped, and so * are places that would look the same as an earlier one. + * + * @param response The JSON response from Photon. + * @return The parsed place suggestions. */ internal fun parsePhotonPlaces(response: JSONObject): List { val places = mutableListOf() diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt index 9786c180..453393bf 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt @@ -60,6 +60,8 @@ data class PlaceSuggestion( /** * A place's location and address. * + * @property latitude The latitude of the place. + * @property longitude The longitude of the place. * @property address The full address. May be empty. * @property postalCode The postal code, or empty if the place does not have one. */ @@ -103,6 +105,7 @@ interface PlaceSearch { * @throws PlaceSearchSwitchedException if the place is from a service no longer used. * @throws PlaceSearchLimitException if the usage limit is reached. * @throws IOException if the request fails for another reason, or the place has no location. + * @return The location and address of the place. */ @Throws(IOException::class) suspend fun getPlace(suggestion: PlaceSuggestion, sessionToken: String): PlaceDetails @@ -111,8 +114,8 @@ interface PlaceSearch { /** * Finds places by name with Google. * - * @param apiKey The Maps API key, which must allow the Places API (New). - * @param app Sent with each request, which a key restricted to Android apps requires. Leave it + * @property apiKey The Maps API key, which must allow the Places API (New). + * @property app Sent with each request, which a key restricted to Android apps requires. Leave it * `null` for a key without that restriction. */ class GooglePlaceSearch( @@ -120,6 +123,15 @@ class GooglePlaceSearch( private val app: AndroidAppIdentity? = null ) : PlaceSearch { + /** + * Searches for place suggestions using Google's Places API. + * + * @param query What the user has typed. + * @param nearLatitude Latitude to prefer places near. + * @param nearLongitude Longitude to prefer places near. + * @param sessionToken Identifies the current search. + * @return The matching place suggestions. + */ override suspend fun suggest( query: String, nearLatitude: Double, @@ -146,6 +158,13 @@ class GooglePlaceSearch( return parseSuggestions(response) } + /** + * Gets the location and address of a recommended place. + * + * @param suggestion The place. + * @param sessionToken The token used for the search that recommended the place. + * @return The location and address of the place. + */ override suspend fun getPlace(suggestion: PlaceSuggestion, sessionToken: String): PlaceDetails { val response = request( url = "$PLACES_URL/${encode(suggestion.placeId)}?sessionToken=${encode(sessionToken)}", @@ -159,6 +178,7 @@ class GooglePlaceSearch( /** * Sends a request to the Places API off the main thread. * + * @param url The url of connection * @param fields The parts of the response that are needed, which Google requires. * @param body Sent as a POST request, or `null` to send a GET request. */ @@ -204,6 +224,7 @@ class GooglePlaceSearch( * @param status The response's HTTP status. * @param error The response's text. Wrong keys have the same status as other bad requests, so * they are recognized by the reason Google gives, such as "API_KEY_INVALID". + * @return The appropriate exception for the failed request. */ internal fun googleFailure(status: Int, error: String): IOException = when { status == TOO_MANY_REQUESTS -> PlaceSearchLimitException() @@ -215,6 +236,9 @@ internal fun googleFailure(status: Int, error: String): IOException = when { /** * Reads the places in an autocomplete response. Entries without an ID or name are skipped. + * + * @param response The JSON response from Google. + * @return The parsed place suggestions. */ internal fun parseSuggestions(response: JSONObject): List { val places = mutableListOf() @@ -238,6 +262,8 @@ internal fun parseSuggestions(response: JSONObject): List { /** * Reads the place in a place details response. * + * @param response The JSON response from Google. + * @return The place's location and address. * @throws IOException if the place has no location. */ internal fun parsePlace(response: JSONObject): PlaceDetails { diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt index fa1eb33b..7be47292 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt @@ -4,8 +4,8 @@ import android.util.Log import com.example.lambda_bbb_events.controller.NotificationController import com.example.lambda_bbb_events.model.lottery.WaitlistStatus import com.example.lambda_bbb_events.model.reservation.ReservationStatus -import com.example.lambda_bbb_events.model.notification.Notification -import com.example.lambda_bbb_events.model.notification.NotificationCategory +import com.example.lambda_bbb_events.model.notifications.Notification +import com.example.lambda_bbb_events.model.notifications.NotificationCategory import com.google.firebase.Firebase import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.MetadataChanges @@ -24,9 +24,9 @@ import kotlinx.coroutines.launch * Displays Android notifications according to the user's * notification category preferences. * - * @param notificationController Controller responsible for + * @property notificationController Controller responsible for * displaying system notifications. - * @param db Firestore database instance. + * @property db Firestore database instance. */ class SystemNotificationListener( private val notificationController: NotificationController, @@ -36,7 +36,7 @@ class SystemNotificationListener( /** * Starts listening for system notification events. * - * Listeners are removed when the coroutine is cancelled. + * Listeners are removed when the coroutine is canceled. * * @param userId Device ID of the current user. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt index d3b05c60..4cb34bb5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt @@ -1,7 +1,5 @@ package com.example.lambda_bbb_events.model.user -//import com.example.lambda_bbb_events.model.Image //maybe used later - /* * Defines admin within the user model. */ @@ -9,12 +7,12 @@ package com.example.lambda_bbb_events.model.user /** * Admins are users who can review logs and remove users, campsites, and images. * - * @property deviceId The unique ID of the user's device. - * @property name The user's real name, may be visible to other users. - * @property email The user's email address, not visible to others. - * @property phone The user's phone number, not visible to others. - * @property profilePictureImageId The user's profile picture imageId. - * @property notificationsEnabled Whether the user wants to receive notifications. + * @param deviceId The unique ID of the user's device. + * @param name The user's real name, may be visible to other users. + * @param email The user's email address, not visible to others. + * @param phone The user's phone number, not visible to others. + * @param profilePictureImageId The user's profile picture image ID. + * @param notificationsEnabled Whether the user wants to receive notifications. */ class Admin( deviceId: String = "", diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt index d420e7b6..6aa179b9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt @@ -1,8 +1,5 @@ package com.example.lambda_bbb_events.model.user - -//import com.example.lambda_bbb_events.model.Image maybe used later - /* * Defines owner within the user model. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt index 42343028..7c9b03f2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt @@ -1,7 +1,5 @@ package com.example.lambda_bbb_events.model.user -//import com.example.lambda_bbb_events.model.Image maybe used later - /* * Defines entrant within the user model. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt index ea12a4d0..cfeee644 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt @@ -9,8 +9,13 @@ package com.example.lambda_bbb_events.model.user * Defines the roles available to users in the application. */ enum class UserRole { + /** A user who uses the app as a customer, searching for campsites and making reservations. */ ENTRANT, + + /** A user who made campsite listings. */ OWNER, + + /** A user who has admin permission to manage the application and campsites. */ ADMIN } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/store/CampsiteStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/store/CampsiteStore.kt index 7f457f19..3a1c7733 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/store/CampsiteStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/store/CampsiteStore.kt @@ -13,7 +13,17 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlin.coroutines.cancellation.CancellationException -/** Maintains the observable campsite cache and coordinates persistence with the repositories. */ +/* + * Maintains the observable campsite cache and coordinates persistence with the repositories. + */ + +/** + * Maintains the observable campsite cache and coordinates persistence with the repositories. + * + * @property campsiteRepo Repository for campsite data. + * @property scope Coroutine scope used for background operations. + * @property lotteryRepository Repository for lottery data. + */ class CampsiteStore( val campsiteRepo: CampsiteRepository = CampsiteRepository(), private val scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO), @@ -47,7 +57,28 @@ class CampsiteStore( } } - /** Adds a campsite to the cache and schedules its creation in the repository. */ + /** + * Adds a campsite to the cache and schedules its creation in the repository. + * + * @param campsiteId The ID of the campsite. + * @param ownerId The device ID of the owner. + * @param campsiteName The campsite's name. + * @param description The campsite description. + * @param address The campsite address. + * @param latitude The campsite's latitude. + * @param longitude The campsite's longitude. + * @param maxOccupancy The maximum number of guests. + * @param rulesPolicies The campsite's rules and policies. + * @param amenities The campsite's amenities. + * @param tags The campsite's tags. + * @param imageIds The campsite's images. + * @param rating The campsite's average rating. + * @param ratingCount The number of ratings. + * @param availability The campsite's availability schedule. + * @param active Whether the campsite is active. + * @param returnMessage Holds an error message if creation fails. + * @return `true` if the campsite is added successfully, `false` if otherwise. + */ fun addCampsite( campsiteId: String = "", ownerId: String = "", // CampsiteOwner deviceId @@ -98,7 +129,13 @@ class CampsiteStore( return true } - /** Deletes the campsite and its lotteries before removing it from the cache. */ + /** + * Deletes the campsite and its lotteries before removing it from the cache. + * + * @param campsiteId The ID of the campsite to delete. + * @param returnMessage Holds an error message if deletion fails. + * @return `true` if the campsite is deleted successfully, `false` otherwise. + */ suspend fun removeCampsite( campsiteId: String, returnMessage: MutableState @@ -131,7 +168,14 @@ class CampsiteStore( } } - /** Replaces the cached listing and schedules its persistence. */ + /** + * Replaces the cached listing and schedules its persistence. + * + * @param campsiteID The ID of the campsite to update. + * @param campsite The updated campsite. + * @param returnMessage Holds a status or error message. + * @return `true` if the update is successful, `false` if otherwise. + */ fun updateCampsite(campsiteID: String, campsite: Campsite, returnMessage: MutableState): Boolean { try { campsites.remove(campsiteID) @@ -164,7 +208,12 @@ class CampsiteStore( campsites[campsiteId] = campsite.copy(imageIds = photos) } - /** Looks up a campsite using [ownerId] as the cache key and throws if the key is absent. */ + /** + * Looks up a campsite using [ownerId] as the cache key and throws if the key is absent + * + * @param ownerId The ID used to look up the campsite. + * @return The campsite associated with the ID. + */ fun getByOwner(ownerId: String): Campsite { return campsites[ownerId] ?: throw IllegalArgumentException("Campsite not found") } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt index 31bc047d..064d9daa 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt @@ -36,6 +36,10 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.common.SearchBar import com.example.lambda_bbb_events.view.ui.components.filter.HomeCampsiteFilter +/* + * Displays and filters campsite listings in the admin screen. + */ + /** * Displays all user campsites created in the app. Can search with search bar. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt index 6c7447f9..eb0ffcc7 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt @@ -30,6 +30,10 @@ import com.example.lambda_bbb_events.view.ui.components.admin.AdminScreenTitleWi import com.example.lambda_bbb_events.view.ui.components.admin.AdminToolTile import com.example.lambda_bbb_events.view.ui.components.admin.NoAccessMessage +/* + * Displays the admin home screen and provides navigation to admin tools. + */ + /** * Displays the home screen for admins. Contains admin tools and recent activity sections. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt index ec9793d3..1aecb740 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt @@ -47,6 +47,9 @@ import com.example.lambda_bbb_events.view.ui.components.common.SearchBar import com.example.lambda_bbb_events.view.ui.components.common.StoredImage import com.example.lambda_bbb_events.view.ui.components.profile.ShowAlertDialog import kotlinx.coroutines.launch +/* + * Displays and manages campsite and user images for administrator moderation. + */ /** * The image data for an image in the gallery. @@ -54,6 +57,8 @@ import kotlinx.coroutines.launch * @property imageId The ID of the image. * @property label The label under the image. * @property isUserPicture `true` if profile picture, `false` if campsite photo. + * @property campsiteId The ID of the campsite containing the image. + * @property userId The ID of the user associated with the profile picture. * @property focusX Offset of the image in the X direction (left/right). * @property focusY Offset of the image in the Y direction (up/down). */ @@ -67,7 +72,12 @@ private data class GalleryImage( val focusY: Float = 0.5f ) -/** Displays campsite images for administrator review and moderation. */ +/** + * Displays campsite images for administrator review and moderation. + * + * @param navController Handles screen navigation. + * @param controllers Manages the app controllers. + */ @Composable fun AdminImagesScreen( navController: NavController, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt index 8f15637f..4f8daee6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt @@ -23,6 +23,10 @@ import com.example.lambda_bbb_events.view.ui.components.logs.LogSearchBar import com.example.lambda_bbb_events.view.ui.components.logs.LogTabSelector import kotlinx.coroutines.CancellationException +/* + * Displays administrative notification and message logs. + */ + /** * Displays notification and message logs for administrators. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt index dfe6ad1c..167232ff 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt @@ -70,7 +70,7 @@ import kotlinx.coroutines.launch * It is not offered on the admin's own profile. * * Promoting is only offered for users who are not admins yet, and needs the admin password. - * Afterwards the screen stays open and shows the new role. + * Afterwards, the screen stays open and shows the new role. * * Removing also deletes the user's active lotteries and archives their campsites, then goes * back to the previous screen. @@ -80,15 +80,14 @@ import kotlinx.coroutines.launch * @param navController Handles screen navigation. * @param controllers All the app controllers, for reading and changing the user. * @param userId The device ID of the user to show. - * - * Reference: - * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. - * https://claude.com/claude-code - * The Message button was added with the help of this AI tool. - * Prompts: - * - "Okay so there are no conversations yet so can I have admins be able to message users from - * the profile admin screen" */ +//Reference: +//Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. +//https://claude.com/claude-code +//The Message button was added with the help of this AI tool. +//Prompts: +//- "Okay so there are no conversations yet so can I have admins be able to message users from +// the profile admin screen" @Composable fun AdminProfileDetailsScreen( navController: NavController, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt index b9e050a6..0683fc92 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt @@ -20,6 +20,8 @@ import androidx.navigation.NavController * Displays the role switcher, title and the notifications button. * * @param navController Handles screen navigation. + * @param title The title displayed on the screen. + * @param showNotifications Whether to display the notifications button. */ @Composable fun AdminScreenTitleWithRoleSwitcher( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt index 3730e9cf..ada71cf1 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt @@ -27,6 +27,10 @@ import androidx.compose.ui.unit.sp import com.example.lambda_bbb_events.controller.AdminLotteryController import kotlinx.coroutines.launch +/* + * Allows administrators to manually run all lotteries after confirmation. + */ + /** Logcat tag for run-lotteries failures. */ private const val LOG_TAG = "RunLotteries" @@ -86,7 +90,7 @@ fun RunLotteriesButton( * Asks the admin to confirm running every lottery now. * * @param onConfirm Called when the admin confirms. - * @param onDismiss Called when the dialog is cancelled. + * @param onDismiss Called when the dialog is canceled. */ @Composable private fun RunLotteriesConfirmDialog( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt index ae10ff1f..261c1636 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt @@ -36,12 +36,10 @@ import java.util.Locale * @param startDate The selected start date, or null. * @param endDate The selected end date, or null. * @param onDateRangeChange Callback for updating the date range. - * @param modifier Customizes the calendar layout. * @param initialMonth The initially displayed month. * @param selectable `true` (for entrant) lets the user pick a date range. `false` (owner) shows * the booked dates only. */ -@OptIn(ExperimentalLayoutApi::class) @Composable fun CampsiteAvailabilityCalendar( unavailableDates: Set, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt index ab148d3f..647412bc 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt @@ -14,7 +14,7 @@ import java.util.Calendar * @param context The context used to display the date picker dialog. * @param onDateSelected A lambda function that is called when a date is selected. */ -fun PopUpShowDatePicker(context: Context, onDateSelected: (String) -> Unit) { +fun popUpShowDatePicker(context: Context, onDateSelected: (String) -> Unit) { val calendar = Calendar.getInstance() DatePickerDialog( context, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt index b253d0cd..d2267bd5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt @@ -18,6 +18,10 @@ import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.view.ui.components.common.CampsiteThumbnail import com.example.lambda_bbb_events.view.ui.components.rating.formatRating +/* + * Defines a campsite card used in expanded campsite list. + */ + /** * Displays a campsite in an expanded campsite list. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagComponents.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagComponents.kt deleted file mode 100644 index 52942491..00000000 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagComponents.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.lambda_bbb_events.view.ui.components.campsite - -/* - * Provides a reusable editor for adding and removing campsite tags. - * and displays existing tags as removable chips. - */ - diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt index cd62db3d..83338729 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt @@ -15,6 +15,11 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.campsite.Campsite +/* + * Defines a vertically arranged section of campsite cards with a title and a "See All" action + * that allows the user to see all cards in selection. + */ + /** * Displays a section of vertically arranged campsite cards. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt index 4c954cd4..df4cd980 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt @@ -10,6 +10,10 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.R +/* + * Displays the Lambda Camping app logo. + */ + /** * Displays the Lambda Camping logo: a tent shaped like the letter lambda under a night sky. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt index 5c51eb51..31096913 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt @@ -68,7 +68,7 @@ enum class ImageFraming { /** * Shows exactly what the campsite's thumbnail shows, the same shape cropped around the - * same focus point, with a blurred copy filling the space around it. + * same focus point, with a blurred copy filling the surrounding space. */ THUMBNAIL } @@ -79,6 +79,8 @@ private val sharedImageProcessor = ImageProcessor() /** * Loads a stored image no wider or taller than [maxSize] pixels, such as for editing it. * + * @param imageId The ID of the image to load. + * @param maxSize The maximum width and height of the image in pixels. * @return The image, or `null` if it could not be loaded. */ suspend fun loadStoredImage(imageId: String, maxSize: Int): Bitmap? { @@ -91,7 +93,7 @@ suspend fun loadStoredImage(imageId: String, maxSize: Int): Bitmap? { * The image is decoded at the size it is drawn at, and a themed loading indicator or * error icon fills the same space until it is ready. [modifier] should give a bounded size. * - * By default the image is cropped to fill the space, keeping its focus point in view. See + * By default, the image is cropped to fill the space, keeping its focus point in view. See * [ImageFraming] for the other ways it can fit. * * @param imageId The ID of the image to display. @@ -382,7 +384,7 @@ private fun CarouselButton( /** * Displays a user's profile picture as a circle, or a default icon if they have none. The - * picture fills the circle, cropped around its centre. + * picture fills the circle, cropped around its center. * * @param imageId The ID of the user's profile picture, blank if they have none. * @param size The diameter of the picture. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt index e3840a2d..46ce4bfe 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt @@ -26,6 +26,13 @@ import androidx.compose.ui.unit.dp /** * Displays a single-line input field. + * + * @param value Current input value. + * @param onValueChange Callback for text changes. + * @param placeholder Placeholder displayed when empty. + * @param modifier Modifier applied to the input field. + * @param keyboardOptions Keyboard type and actions for the input field. + * @param leadingIcon Optional icon displayed at the start of the field. */ @Composable fun FormTextField( @@ -57,6 +64,8 @@ fun FormTextField( /** * Gets the colors shared by the app's form text fields. + * + * @return The colors used by the form text fields. */ @Composable fun formTextFieldColors(): TextFieldColors = OutlinedTextFieldDefaults.colors( @@ -120,6 +129,11 @@ fun FormTextFieldWithTitle( /** * Displays a multi-line input field for longer text. + * + * @param value Current input value. + * @param onValueChange Callback for text changes. + * @param placeholder Placeholder displayed when empty. + * @param modifier Modifier applied to the input field. */ @Composable fun FormTextFieldMultiLine( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt index 14d0b21d..9abf5745 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt @@ -7,17 +7,24 @@ import androidx.compose.foundation.text.input.insert import com.example.lambda_bbb_events.model.formatting.CountryCode import com.example.lambda_bbb_events.model.formatting.formatLocalNumber +/* + * Defines transformations for phone number fields. + */ + /** * Keeps only digits in a phone number field, up to [maxLength] of them. * * Runs on everything typed or pasted, so "(780) 555-0123" is kept as "7805550123". * - * @param maxLength The most digits the number can have. + * @property maxLength The most digits the number can have. */ class PhoneDigitsInputTransformation( private val maxLength: Int ) : InputTransformation { + /** + * Removes non-digit characters and limits the number to [maxLength] digits. + */ override fun TextFieldBuffer.transformInput() { val typed = asCharSequence().toString() val digits = typed.filter { it.isDigit() }.take(maxLength) diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt index 74573965..9780f671 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt @@ -49,10 +49,11 @@ private val MARKER_SIZE = 28.dp /** * Gets the alignment that keeps a photo's focus point in view when the photo is cropped to - * fill a space. A focus of (0.5, 0.5) is the centre of the photo. + * fill a space. A focus of (0.5, 0.5) is the center of the photo. * * @param focusX How far across the photo the focus point is, from 0 to 1. * @param focusY How far down the photo the focus point is, from 0 to 1. + * @return The alignment that keeps the photo's focus point in view. */ fun focusAlignment(focusX: Float, focusY: Float): Alignment { // Alignment uses -1 for the left or top edge and 1 for the right or bottom edge diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt index 76807660..dc6f5625 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt @@ -22,6 +22,10 @@ import androidx.compose.ui.unit.sp import androidx.navigation.NavController import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Displays a reusable screen title with optional navigation and notification buttons. + */ + /** * Displays a screen title with optional back and notification buttons. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt index d291357e..e439e234 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt @@ -16,8 +16,8 @@ import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.controller.NotificationController import com.example.lambda_bbb_events.controller.NotificationPreferenceController import com.example.lambda_bbb_events.model.message.NotificationPreference -import com.example.lambda_bbb_events.model.notification.NotificationCategory -import com.example.lambda_bbb_events.model.notification.NotificationMode +import com.example.lambda_bbb_events.model.notifications.NotificationCategory +import com.example.lambda_bbb_events.model.notifications.NotificationMode import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture import com.example.lambda_bbb_events.view.ui.components.notification.MuteOption import com.example.lambda_bbb_events.view.ui.components.notification.NotificationMuteDialog diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt index 540d6491..c97c065d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.controller.NotificationController -import com.example.lambda_bbb_events.model.notification.NotificationHistory +import com.example.lambda_bbb_events.model.notifications.NotificationHistory import java.text.DateFormat import java.util.Date diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt index 363392b3..ba8e7af2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt @@ -33,7 +33,7 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigat import com.example.lambda_bbb_events.view.ui.components.profile.ToggleButton import com.example.lambda_bbb_events.view.ui.components.common.quickToast import kotlinx.coroutines.launch -import com.example.lambda_bbb_events.model.notification.Notification +import com.example.lambda_bbb_events.model.notifications.Notification /* Provides togglable button to turn on or turn off notifications