Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.inject.Singleton
@Singleton
class LocationRepository @Inject constructor(private val routesNetworkApi: RoutesNetworkApi) {

//Source: Uplift
// Source: Uplift Android

private lateinit var fusedLocationClient: FusedLocationProviderClient
private val _currentLocation: MutableStateFlow<Location?> = MutableStateFlow(null)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.cornellappdev.transit.models.ecosystem

import com.cornellappdev.transit.models.Place
import com.cornellappdev.transit.models.PlaceType
import com.cornellappdev.transit.util.TimeUtils.dayOrder
import com.cornellappdev.transit.util.TimeUtils.toPascalCaseString
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
Expand Down Expand Up @@ -27,27 +30,8 @@ data class Eatery(
@Json(name = "events") val events: List<Event>?
) : DetailedEcosystemPlace {

/**
* Value to represent the custom order of days in a week (with Sunday as
* the first day due to a particular design choice). Used for sorting purposes
*/
private val dayOrder = mapOf(
"Sunday" to 1,
"Monday" to 2,
"Tuesday" to 3,
"Wednesday" to 4,
"Thursday" to 5,
"Friday" to 6,
"Saturday" to 7
)

/**
* @Return a list of associated dayOfWeek and hours pairs in [DayOperatingHours] representing
* each day of the week and the corresponding times that an eatery is open. The list is sorted
* by day with the custom dayOrder (Sunday first).
*/
fun formatOperatingHours(): List<DayOperatingHours> {
val dailyHours = operatingHours()
override fun operatingHours(): List<DayOperatingHours> {
val dailyHours = getOperatingHours()

// Convert map to list and sort by custom day order
return dailyHours.entries
Expand All @@ -66,7 +50,7 @@ data class Eatery(
/**
* @Return a map of each day of the week to its list of operating hours
*/
private fun operatingHours(): Map<DayOfWeek, MutableList<String>> {
private fun getOperatingHours(): Map<DayOfWeek, MutableList<String>> {
val dailyHours = mutableMapOf<DayOfWeek, MutableList<String>>()

events?.forEach { event ->
Expand All @@ -87,6 +71,14 @@ data class Eatery(

return dailyHours
}

override fun toPlace(): Place = Place(
latitude = this.latitude ?: 0.0,
longitude = this.longitude ?: 0.0,
name = this.name,
detail = this.location,
type = PlaceType.APPLE_PLACE
)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cornellappdev.transit.models.ecosystem

import com.cornellappdev.transit.models.Place

/**
* Specific places such as eateries or gyms
*/
interface EcosystemPlace {

/**
* Convert from a specific ecosystem place to the generic [Place] class
*/
fun toPlace(): Place
}


/**
* Interface for working with places in ecosystem with special details, i.e. hours or capacity
*/
sealed interface DetailedEcosystemPlace: EcosystemPlace {

/**
* @Return a list of associated dayOfWeek and hours pairs in [DayOperatingHours] representing
* each day of the week and the corresponding times that an eatery is open. The list is sorted
* by day with the custom dayOrder (Sunday first).
*/
fun operatingHours(): List<DayOperatingHours>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cornellappdev.transit.models.ecosystem

import com.cornellappdev.transit.models.Place
import com.cornellappdev.transit.models.PlaceType
import com.cornellappdev.transit.networking.ApiResponse
import com.squareup.moshi.Json

Expand All @@ -22,7 +24,15 @@ data class Printer(
@Json(name = "description") var description: String,
@Json(name = "latitude") var latitude: Double,
@Json(name = "longitude") var longitude: Double
)
) : EcosystemPlace {
override fun toPlace(): Place = Place(
latitude = this.latitude,
longitude = this.longitude,
name = this.location,
detail = this.description,
type = PlaceType.APPLE_PLACE
)
}

/**
* Class representing a Cornell library
Expand All @@ -33,4 +43,18 @@ data class Library(
@Json(name = "address") var address: String,
@Json(name = "latitude") var latitude: Double,
@Json(name = "longitude") var longitude: Double
) : DetailedEcosystemPlace
) : DetailedEcosystemPlace {

override fun operatingHours(): List<DayOperatingHours> {
//TODO: Implement
return emptyList()
}

override fun toPlace(): Place = Place(
latitude = this.latitude,
longitude = this.longitude,
name = this.location,
detail = this.address,
type = PlaceType.APPLE_PLACE
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.cornellappdev.transit.models.ecosystem

import android.icu.util.Calendar
import com.cornellappdev.transit.models.Place
import com.cornellappdev.transit.models.PlaceType
import com.cornellappdev.transit.util.TimeUtils.dayString
import com.cornellappdev.transit.util.getGymLocationString
import kotlin.math.roundToInt

/**
Expand Down Expand Up @@ -38,7 +42,37 @@ data class UpliftGym(
val upliftCapacity: UpliftCapacity?,
val latitude: Double,
val longitude: Double,
) : DetailedEcosystemPlace
) : DetailedEcosystemPlace {

override fun operatingHours(): List<DayOperatingHours> {

// Sunday is enforced to be first indexed day
val indexedHours = hours.takeLast(1) + hours.dropLast(1)

val dayOperatingHours = indexedHours.mapIndexed { index, dayHours ->
dayHours?.let {
DayOperatingHours(
dayOfWeek = dayString[index] ?: "",
hours = dayHours.map { timeInterval ->
timeInterval.toString()

})
} ?: DayOperatingHours(dayOfWeek = dayString[index] ?: "", hours = listOf("Closed"))
}


return dayOperatingHours

}

override fun toPlace(): Place = Place(
latitude = this.latitude,
longitude = this.longitude,
name = this.name,
detail = getGymLocationString(this.name),
type = PlaceType.APPLE_PLACE
)
}

/**
* A gym's capacity.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.cornellappdev.transit.ui.components.home

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.BottomEnd
import androidx.compose.ui.Alignment.Companion.TopEnd
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -82,6 +86,67 @@ fun DetailedPlaceHeaderSection(
}
}

/**
* Text area of detailed place header with favorites star on the top right and widget on the bottom right
*/
@Composable
fun DetailedPlaceHeaderSectionWithWidget(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty similar to the above DetailedPlaceHeaderSection composable in implementation, is there any way we can consolidate them or share ui code between them?

title: String,
subtitle: String?,
leftAnnotatedString: AnnotatedString? = null,
widget: @Composable BoxScope.() -> Unit,
onFavoriteClick: () -> Unit,
isFavorite: Boolean
) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = 24.dp)
) {
Column(
modifier = Modifier
.align(Alignment.CenterStart),
) {
Text(
text = title,
style = Style.detailHeading,
color = PrimaryText,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(end = 32.dp, bottom = 12.dp)
)
subtitle?.let {
Text(
text = subtitle,
style = Style.cardSubtitle,
color = SecondaryText,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(end = 32.dp, bottom = 8.dp)

)
}
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
leftAnnotatedString?.let {
Text(
text = leftAnnotatedString,
style = Style.cardSubtitle
)
}
Spacer(modifier = Modifier.weight(1f))
}
}

Box(Modifier.align(BottomEnd)) {
widget()
}
FavoritesStar(onFavoriteClick, isFavorite)
}
}

@Preview(showBackground = true)
@Composable
private fun DetailedPlaceHeaderSectionPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.cornellappdev.transit.ui.theme.SecondaryText
import com.cornellappdev.transit.ui.theme.Style
import com.cornellappdev.transit.ui.theme.TransitBlue
import com.cornellappdev.transit.util.BOTTOM_SHEET_MAX_HEIGHT_PERCENT
import com.cornellappdev.transit.util.ecosystem.toPlace

@Composable
fun DetailedPlaceSheetContent(
Expand Down Expand Up @@ -110,8 +109,13 @@ fun DetailedPlaceSheetContent(
}

is UpliftGym -> {
//TODO
Text(ecosystemPlace.name)
GymDetailsContent(
gym = ecosystemPlace,
isFavorite = ecosystemPlace.toPlace() in favorites,
onFavoriteClick = {
onFavoriteStarClick(ecosystemPlace.toPlace())
}
)
}
}
}
Expand Down Expand Up @@ -148,7 +152,9 @@ fun DetailedPlaceSheetContent(
}

is UpliftGym -> {
//TODO
navigateToPlace(
ecosystemPlace.toPlace()
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun EateryDetailsContent(
eatery.name,
eatery.campusArea,
leftAnnotatedString = homeViewModel.isOpenAnnotatedStringFromOperatingHours(
eatery.formatOperatingHours()
eatery.operatingHours()
),
onFavoriteClick = onFavoriteClick,
isFavorite = isFavorite
Expand Down Expand Up @@ -113,8 +113,8 @@ fun EateryDetailsContent(
HorizontalDivider(thickness = 1.dp, color = DividerGray)

ExpandableOperatingHoursList(
homeViewModel.isOpenAnnotatedStringFromOperatingHours(eatery.formatOperatingHours()),
homeViewModel.rotateOperatingHours(eatery.formatOperatingHours())
homeViewModel.isOpenAnnotatedStringFromOperatingHours(eatery.operatingHours()),
homeViewModel.rotateOperatingHours(eatery.operatingHours())
)

}
Expand Down
Loading