Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 All @@ -19,14 +23,18 @@ import com.cornellappdev.transit.ui.theme.SecondaryText
import com.cornellappdev.transit.ui.theme.Style

/**
* Text area of detailed place header with favorites star
* Text area of detailed place header with favorites star, and optional
* annotated text and widget.
*
* [rightAnnotatedString] takes precedence over [widget].
*/
@Composable
fun DetailedPlaceHeaderSection(
title: String,
subtitle: String?,
leftAnnotatedString: AnnotatedString? = null,
rightAnnotatedString: AnnotatedString? = null,
widget: @Composable BoxScope.() -> Unit = {},
onFavoriteClick: () -> Unit,
isFavorite: Boolean
) {
Expand Down Expand Up @@ -78,6 +86,12 @@ fun DetailedPlaceHeaderSection(
}
}

if (rightAnnotatedString == null) {
Box(Modifier.align(BottomEnd)) {
widget()
}
}

FavoritesStar(onFavoriteClick, isFavorite)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.cornellappdev.transit.R
import com.cornellappdev.transit.models.Place
Expand All @@ -38,7 +40,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 All @@ -47,7 +48,8 @@ fun DetailedPlaceSheetContent(
onBackButtonPressed: () -> Unit,
navigateToPlace: (Place) -> Unit,
onFavoriteStarClick: (Place) -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
distanceStringToPlace: (Double?, Double?) -> String
) {
Column(
modifier = modifier
Expand Down Expand Up @@ -95,7 +97,11 @@ fun DetailedPlaceSheetContent(
isFavorite = ecosystemPlace.toPlace() in favorites,
onFavoriteClick = {
onFavoriteStarClick(ecosystemPlace.toPlace())
}
},
distanceString = distanceStringToPlace(
ecosystemPlace.latitude,
ecosystemPlace.longitude
)
)
}

Expand All @@ -110,8 +116,17 @@ fun DetailedPlaceSheetContent(
}

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

is UpliftGym -> {
//TODO
navigateToPlace(
ecosystemPlace.toPlace()
)
}
}
}
Expand Down Expand Up @@ -184,21 +201,52 @@ fun DetailedPlaceSheetContent(
}
}

@Preview(showBackground = true)
@Composable
private fun DetailedPlaceSheetContentPreview() {
DetailedPlaceSheetContent(
Library(
private class ExamplePlaceProvider : PreviewParameterProvider<DetailedEcosystemPlace> {
override val values = sequenceOf(
Eatery(
id = 1,
name = "Okenshields",
menuSummary = null,
imageUrl = null,
location = "Willard Straight Hall",
campusArea = "Central",
onlineOrderUrl = null,
latitude = null,
longitude = null,
paymentAcceptsMealSwipes = null,
paymentAcceptsBrbs = null,
paymentAcceptsCash = null,
events = null
), Library(
id = 1,
location = "Olin Library",
address = "Ho Plaza",
latitude = 1.0,
longitude = 1.0
),
UpliftGym(
name = "Helen Newman",
id = "",
facilityId = "",
hours = emptyList(),
latitude = 0.0,
longitude = 0.0,
upliftCapacity = null,
imageUrl = null
)
)
}

@Preview(showBackground = true)
@Composable
private fun DetailedPlaceSheetContentPreview(@PreviewParameter(ExamplePlaceProvider::class) place: DetailedEcosystemPlace) {
DetailedPlaceSheetContent(
place,
favorites = emptySet(),
onBackButtonPressed = {},
navigateToPlace = {},
onFavoriteStarClick = {},
modifier = Modifier.background(Color.White)
modifier = Modifier.background(Color.White),
distanceStringToPlace = { _, _ -> "" }
)
}
Loading