Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/alert/alert lists UI improvements #342

Merged
merged 18 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
37affd5
feat: remove decline button from pals alert card
agonzalez-r Dec 17, 2024
8d827d8
feat: add acceptedAlerts mutable state, accept and unaccept alert fun…
agonzalez-r Dec 17, 2024
6b828a8
feat: implement UI for accepting/un-accepting an alert
agonzalez-r Dec 17, 2024
9095440
Merge branch 'main' of https://github.com/PeriodPals/periodpals into …
agonzalez-r Dec 18, 2024
6eb70d4
fix: add `downloadFilePublic()` function to user model and view model
agonzalez-r Dec 19, 2024
f5f9940
feat: pass user view model to `AlertListsScreen`
agonzalez-r Dec 19, 2024
be47777
feat: implement fetch for the users' profile picture
agonzalez-r Dec 19, 2024
73d0213
feat: add `trimLocationText()` function to AlertComponents.kt
agonzalez-r Dec 19, 2024
28d2010
Merge branch 'main' of https://github.com/PeriodPals/periodpals into …
agonzalez-r Dec 19, 2024
e89bf6f
fix: update text and test tag for "Un-Accept" alert button
agonzalez-r Dec 19, 2024
2abd0e3
feat: make profile pictures bigger
agonzalez-r Dec 19, 2024
4a7c471
fix: add correct test tags
agonzalez-r Dec 19, 2024
1eef5e4
test: add tests for accepting/un-accepting an alert UI
agonzalez-r Dec 19, 2024
15a0697
test: add tests for `acceptAlert()` and `unacceptAlert()`
agonzalez-r Dec 19, 2024
8e14adb
Merge branch 'main' of https://github.com/PeriodPals/periodpals into …
agonzalez-r Dec 19, 2024
0c6513b
Merge branch 'main' of https://github.com/PeriodPals/periodpals into …
agonzalez-r Dec 20, 2024
7aefaa0
fix: resolve merge conflicts
agonzalez-r Dec 20, 2024
0259879
docs: clean documentation
agonzalez-r Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ fun PeriodPalsApp(
composable(Screen.ALERT_LIST) {
AlertListsScreen(
alertViewModel,
authenticationViewModel,
userViewModel,
authenticationViewModel,
locationViewModel,
gpsService,
chatViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,16 @@ private val messageValidators =
*
* @property alertModelSupabase The repository used for loading and saving alerts.
* @property userId the id linked to the current user.
* @property _alerts Mutable state holding the list of all alerts.
* @property alerts Public state exposing the list of all alerts.
* @property _myAlerts Mutable state holding the list of current users alerts.
* @property myAlerts Public state exposing the list of current users alerts.
* @property _alertsWithinRadius Mutable state holding the ordered list of all alerts within a
* specified radius.
* @property alertsWithinRadius Public state exposing the ordered list of all alerts within a
* specified radius.
* @property alertFilter Mutable state holding a filter for `filterAlerts`.
* @property _filterAlerts Mutable state holding the list of alerts filtered by `alertFilter`.
* @property filterAlerts Public state exposing the list of alerts filtered y `alertFilter`.
* @property _palAlerts Mutable state holding the list of other users alerts within selected radius.
* @property palAlerts Public state exposing the list of other users alerts within selected radius.
* @property _selectedAlert Mutable state holding the selected alert.
* @property palAlerts Public state exposing the list of other users alerts within selected radius,
* minus the accepted alerts.
* @property selectedAlert Public state exposing the selected alert.
* @property acceptedAlerts Public state exposing the list of accepted alerts.
*/
class AlertViewModel(private val alertModelSupabase: AlertModelSupabase) : ViewModel() {
companion object {
Expand Down Expand Up @@ -96,12 +91,17 @@ class AlertViewModel(private val alertModelSupabase: AlertModelSupabase) : ViewM
}
val filterAlerts: State<List<Alert>> = _filterAlerts

private var _palAlerts = derivedStateOf { _filterAlerts.value.filter { it.uid != userId.value } }
private var _palAlerts = derivedStateOf {
_filterAlerts.value.filter { it.uid != userId.value && !_acceptedAlerts.value.contains(it) }
}
val palAlerts: State<List<Alert>> = _palAlerts

private var _selectedAlert = mutableStateOf<Alert?>(null)
val selectedAlert: State<Alert?> = _selectedAlert

private var _acceptedAlerts = mutableStateOf<List<Alert>>(listOf())
val acceptedAlerts: State<List<Alert>> = _acceptedAlerts

val formState =
FormState(
fields =
Expand Down Expand Up @@ -311,4 +311,22 @@ class AlertViewModel(private val alertModelSupabase: AlertModelSupabase) : ViewM
fun selectAlert(alert: Alert) {
viewModelScope.launch { _selectedAlert.value = alert }
}

/**
* Accepts an alert and adds it to the list of accepted alerts.
*
* @param alert The alert to be accepted.
*/
fun acceptAlert(alert: Alert) {
viewModelScope.launch { _acceptedAlerts.value += alert }
}

/**
* Un-accepts an alert and removes it from the list of accepted alerts.
*
* @param alert The alert to be unaccepted.
*/
fun unAcceptAlert(alert: Alert) {
viewModelScope.launch { _acceptedAlerts.value -= alert }
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/android/periodpals/model/user/UserModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ interface UserRepository {
onFailure: (Exception) -> Unit
)

/**
* Downloads a file from the storage.
*
* @param filePath The path of the file to be downloaded.
* @param onSuccess Callback function to be called on success.
* @param onFailure Callback function to be called when there is an exception.
*/
suspend fun downloadFilePublic(
filePath: String,
onSuccess: (bytes: ByteArray) -> Unit,
onFailure: (Exception) -> Unit
)

/**
* Downloads a file from the storage.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class UserRepositorySupabase(private val supabase: SupabaseClient) : UserReposit
) {
try {
val result =
withContext(Dispatchers.Main) {
supabase.postgrest[USERS].select {}.decodeList<UserDto>()
}
withContext(Dispatchers.IO) { supabase.postgrest[USERS].select {}.decodeList<UserDto>() }
charliemangano marked this conversation as resolved.
Show resolved Hide resolved
Log.d(TAG, "loadUserProfiles: Success")
onSuccess(result)
} catch (e: Exception) {
Expand Down Expand Up @@ -138,7 +136,7 @@ class UserRepositorySupabase(private val supabase: SupabaseClient) : UserReposit
onFailure: (Exception) -> Unit,
) {
try {
withContext(Dispatchers.Main) {
withContext(Dispatchers.IO) {
charliemangano marked this conversation as resolved.
Show resolved Hide resolved
val file = supabase.storage.from("avatars").downloadPublic("$filePath.jpg")
Log.d(TAG, "downloadFile: Success")
onSuccess(file)
Expand All @@ -148,4 +146,22 @@ class UserRepositorySupabase(private val supabase: SupabaseClient) : UserReposit
onFailure(e)
}
}

override suspend fun downloadFilePublic(
agonzalez-r marked this conversation as resolved.
Show resolved Hide resolved
filePath: String,
onSuccess: (bytes: ByteArray) -> Unit,
onFailure: (Exception) -> Unit,
) {
try {
val file =
withContext(Dispatchers.IO) {
supabase.storage.from("avatars").downloadPublic("$filePath.jpg")
}
Log.d(TAG, "downloadFile: Success")
onSuccess(file)
} catch (e: Exception) {
Log.d(TAG, "downloadFile: fail to download file: ${e.message}")
onFailure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ class UserViewModel(private val userRepository: UserRepositorySupabase) : ViewMo
)
}
}

/**
* Downloads a file from the storage.
*
* @param filePath The path of the file to be downloaded.
* @param onSuccess Callback function to be called on success, passes the bytes from the
* downloaded file.
* @param onFailure Callback function to be called when there is an exception.
*/
fun downloadFilePublic(
agonzalez-r marked this conversation as resolved.
Show resolved Hide resolved
filePath: String,
onSuccess: (ByteArray) -> Unit,
onFailure: (Exception) -> Unit
) {
viewModelScope.launch {
userRepository.downloadFilePublic(
filePath,
onSuccess = { bytes ->
Log.d(TAG, "downloadFile: Success")
onSuccess(bytes)
},
onFailure = { e: Exception ->
Log.d(TAG, "downloadFile: fail to download file: ${e.message}")
onFailure(e)
})
}
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/android/periodpals/resources/C.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ object C {
const val NO_ALERTS_ICON = "noAlertsIcon"
const val NO_ALERTS_TEXT = "noAlertsText"

const val ACCEPTED_ALERTS_TEXT = "acceptedAlertsText"
const val ACCEPTED_ALERTS_DIVIDER = "acceptedAlertsDivider"

const val FILTER_FAB = "filterFab"
const val FILTER_FAB_BUBBLE = "filterFabBubble"
const val FILTER_DIALOG = "filterDialog"
Expand All @@ -66,12 +69,13 @@ object C {

object PalsAlertItem {
const val PAL_ALERT = "palsAlert"
const val PAL_ACCEPTED_ALERT = "palsAcceptedAlert"
const val PAL_NAME = "palsName"
const val PAL_MESSAGE = "palMessage"
const val PAL_DIVIDER = "palDivider"
const val PAL_BUTTONS = "palButtons"
const val PAL_ACCEPT_BUTTON = "palAcceptButton"
const val PAL_DECLINE_BUTTON = "palDeclineButton"
agonzalez-r marked this conversation as resolved.
Show resolved Hide resolved
const val PAL_UNACCEPT_BUTTON = "palUnAcceptButton"
}
}

Expand Down
Loading
Loading