-
Notifications
You must be signed in to change notification settings - Fork 0
Deep-Linking (PARTIAL) #145
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
Changes from 6 commits
89f15fc
45a6488
d318e93
28c11cc
838dcd3
f1a2fb4
d0bc7a3
ac8b748
f994c10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package com.cornellappdev.transit.ui.components.home | ||
|
|
||
| import android.content.ActivityNotFoundException | ||
| import android.content.Intent | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
|
|
@@ -13,9 +16,11 @@ import androidx.compose.material3.Text | |
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.core.net.toUri | ||
| import com.cornellappdev.transit.R | ||
| import com.cornellappdev.transit.models.ecosystem.UpliftGym | ||
| import com.cornellappdev.transit.ui.theme.DividerGray | ||
|
|
@@ -39,6 +44,7 @@ fun GymDetailsContent( | |
| gym: UpliftGym, | ||
| isFavorite: Boolean, | ||
| onFavoriteClick: () -> Unit, | ||
| onDeepLinkClick: () -> Unit, | ||
| distanceString: String | ||
| ) { | ||
| val isOpen = getOpenStatus(gym.operatingHours()).isOpen | ||
|
|
@@ -101,7 +107,10 @@ fun GymDetailsContent( | |
| text = annotatedString, | ||
| inlineContent = inlineContent, | ||
| style = Style.heading2, | ||
| color = TransitBlue | ||
| color = TransitBlue, | ||
| modifier = Modifier.clickable( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can make this a TextButton instead of clickable text |
||
| onClick = onDeepLinkClick | ||
| ) | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(24.dp)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,11 +53,18 @@ class HomeViewModel @Inject constructor( | |
| ) : ViewModel() { | ||
|
|
||
| val libraryCardsFlow: StateFlow<ApiResponse<List<LibraryCardUiState>>> = | ||
| routeRepository.libraryFlow.map { response -> | ||
| combine( | ||
| routeRepository.libraryFlow, | ||
| locationRepository.currentLocation | ||
| ) { response, location -> | ||
| val usersLocation = location?.let { LatLng(it.latitude, it.longitude) } | ||
| when (val filteredResponse = response.withExcludedLibrariesRemoved()) { | ||
| is ApiResponse.Success -> { | ||
| val sortedLibraries = filteredResponse.data.sortedBy { | ||
| numericalDistanceToPlace(it.latitude, it.longitude, usersLocation) | ||
| } | ||
| ApiResponse.Success( | ||
| filteredResponse.data | ||
| sortedLibraries | ||
| .map { it.toLibraryCardUiState() } | ||
| ) | ||
| } | ||
|
|
@@ -117,6 +124,9 @@ class HomeViewModel @Inject constructor( | |
| gymRepository.gymFlow, | ||
| locationRepository.currentLocation | ||
| ) { printers, libraries, eateries, gyms, location -> | ||
| val userLocation = location?.let { LatLng(it.latitude, it.longitude) } | ||
|
|
||
|
|
||
| StaticPlaces( | ||
| printers = sortApiResponse( | ||
| response = if (printers is ApiResponse.Success) { | ||
|
|
@@ -125,23 +135,27 @@ class HomeViewModel @Inject constructor( | |
| printers | ||
| }, | ||
| getLatitude = { it.latitude }, | ||
| getLongitude = { it.longitude } | ||
| getLongitude = { it.longitude }, | ||
| userLocation = userLocation | ||
| ), | ||
| libraries = sortApiResponse( | ||
| response = libraries, | ||
| response = libraries.withExcludedLibrariesRemoved(), | ||
| getLatitude = { it.latitude }, | ||
| getLongitude = { it.longitude } | ||
| ).withExcludedLibrariesRemoved(), | ||
| getLongitude = { it.longitude }, | ||
| userLocation = userLocation | ||
| ), | ||
| eateries = sortApiResponse( | ||
| response = eateries, | ||
| getLatitude = { it.latitude }, | ||
| getLongitude = { it.longitude }, | ||
| userLocation = userLocation, | ||
| getIsOpen = { TimeUtils.getOpenStatus(it.operatingHours()).isOpen } | ||
| ), | ||
| gyms = sortApiResponse( | ||
| response = gyms, | ||
| getLatitude = { it.latitude }, | ||
| getLongitude = { it.longitude }, | ||
| userLocation = userLocation, | ||
| getIsOpen = { TimeUtils.getOpenStatus(it.operatingHours()).isOpen } | ||
| ) | ||
| ) | ||
|
|
@@ -453,14 +467,14 @@ class HomeViewModel @Inject constructor( | |
| /** | ||
| * Returns a numerical distance from a location to the current location if both exist, otherwise returns Double.MAX_VALUE | ||
| */ | ||
| fun numericalDistanceToPlace(latitude: Double?, longitude: Double?): Double { | ||
| val currentLocationSnapshot = currentLocation.value | ||
| return if (currentLocationSnapshot != null && latitude != null && longitude != null) { | ||
| fun numericalDistanceToPlace( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be private if only used in this vm. Can also potentially be moved into one of the util files to keep this vm leaner |
||
| latitude: Double?, | ||
| longitude: Double?, | ||
| userLocation: LatLng? | ||
| ): Double { | ||
| return if (userLocation != null && latitude != null && longitude != null) { | ||
| calculateDistance( | ||
| LatLng( | ||
| currentLocationSnapshot.latitude, | ||
| currentLocationSnapshot.longitude | ||
| ), LatLng(latitude, longitude) | ||
| userLocation, LatLng(latitude, longitude) | ||
| ) | ||
| } else { | ||
| Double.MAX_VALUE | ||
|
|
@@ -474,15 +488,16 @@ class HomeViewModel @Inject constructor( | |
| response: ApiResponse<List<T>>, | ||
| getLatitude: (T) -> Double?, | ||
| getLongitude: (T) -> Double?, | ||
| userLocation: LatLng?, | ||
| getIsOpen: ((T) -> Boolean)? = null | ||
| ): ApiResponse<List<T>> { | ||
| if (response is ApiResponse.Success) { | ||
| val sortedData = response.data.sortedWith( | ||
| if (getIsOpen != null) { | ||
| compareByDescending<T> { getIsOpen(it) } | ||
| .thenBy { numericalDistanceToPlace(getLatitude(it),getLongitude(it)) } | ||
| .thenBy { numericalDistanceToPlace(getLatitude(it),getLongitude(it), userLocation) } | ||
| } else { | ||
| compareBy { numericalDistanceToPlace(getLatitude(it),getLongitude(it)) } | ||
| compareBy { numericalDistanceToPlace(getLatitude(it),getLongitude(it), userLocation) } | ||
| } | ||
| ) | ||
| return ApiResponse.Success(sortedData) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.cornellappdev.transit.util | ||
|
|
||
| import android.content.ActivityNotFoundException | ||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.util.Log | ||
| import androidx.core.net.toUri | ||
|
|
||
| object IntentUtils { | ||
| fun Context.openDeepLink(packageName: String) { | ||
| val launchIntent = packageManager.getLaunchIntentForPackage(packageName) | ||
|
|
||
| if (launchIntent != null) { | ||
| startActivity(launchIntent) | ||
| } else { | ||
| val playStoreIntent = Intent(Intent.ACTION_VIEW, "market://details?id=$packageName".toUri()) | ||
| .setPackage("com.android.vending") | ||
| .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| try { | ||
| startActivity(playStoreIntent) | ||
| } catch (e: ActivityNotFoundException) { | ||
| val webStoreIntent = Intent(Intent.ACTION_VIEW, "https://play.google.com/store/apps/details?id=$packageName".toUri()) | ||
| .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
| try { | ||
| startActivity(webStoreIntent) | ||
| } catch (e2: ActivityNotFoundException) { | ||
| Log.e("IntentUtils","no handler for play store web URL" ,e2) | ||
| } | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can make this a TextButton instead of clickable text