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

Purchase Page - Optimal Card + Other Benefits based on Purchase type #60

Merged
merged 31 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c07e074
Implementing UI for purchase screen + placeholder for benefits page
NandiniMeh Jul 16, 2024
07739ae
purchase page
NandiniMeh Jul 16, 2024
4c9422d
view model changes - purchase benefits screen
NandiniMeh Jul 17, 2024
afdc9ec
UI enhancements
NandiniMeh Jul 18, 2024
5cca0e6
Merge remote-tracking branch 'origin/main' into nandini/purchase_page
NandiniMeh Jul 19, 2024
5b6c657
display benefits on cards on revalent purchase pages
NandiniMeh Jul 19, 2024
e4a4407
Merge branch 'main' into nandini/purchase_page
NandiniMeh Jul 23, 2024
0921c25
fixing nav errors + file renaming
NandiniMeh Jul 23, 2024
c8452da
displaying optimal card for the purchase type
NandiniMeh Jul 23, 2024
146787e
Merge branch 'main' into nandini/purchase_page
NandiniMeh Jul 23, 2024
59b42e6
display name for HomeImprovement
NandiniMeh Jul 23, 2024
e01bd0e
Enhancing UI of purchase screen
NandiniMeh Jul 23, 2024
c97386f
UI improvements - purchase page
NandiniMeh Jul 23, 2024
a5e47a3
integrating geolocation inference
NandiniMeh Jul 23, 2024
854a7c1
Added missing place type mapping data.
LideLinusZhang Jul 23, 2024
a4b5394
Updated .gitignore to prevent committing secrets.
LideLinusZhang Jul 23, 2024
1339ff8
integrating geolocation + popup UI
NandiniMeh Jul 24, 2024
64468de
Merge branch 'nandini/purchase_page' of https://github.com/LideLinusZ…
NandiniMeh Jul 24, 2024
8b15076
small UI change to popup
NandiniMeh Jul 24, 2024
19eb899
updating gitignore
NandiniMeh Jul 24, 2024
bcbc525
allow user to choose location preference before calling location API
NandiniMeh Jul 24, 2024
4bc471d
Merge branch 'main' into nandini/purchase_page
NandiniMeh Jul 24, 2024
d3fa971
fixing merge conflicts
NandiniMeh Jul 24, 2024
e1d2abd
Merge branch 'main' into nandini/purchase_page
NandiniMeh Jul 24, 2024
86c9a8a
Delete .DS_Store
LideLinusZhang Jul 24, 2024
cb44619
Merge branch 'main' into nandini/purchase_page
NandiniMeh Jul 24, 2024
748a665
Merge branch 'nandini/purchase_page' of https://github.com/LideLinusZ…
NandiniMeh Jul 24, 2024
7295af5
fix merge errors
NandiniMeh Jul 24, 2024
7dcd7e5
Merge remote-tracking branch 'refs/remotes/cs446-project/main' into n…
LideLinusZhang Jul 24, 2024
8cd1e6e
Merged upstream.
LideLinusZhang Jul 24, 2024
9a70948
Merge remote-tracking branch 'cs446-project/nandini/purchase_page' in…
LideLinusZhang Jul 24, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# macOS
.DS_Store

# Gradle files
.gradle/
build/
Expand Down Expand Up @@ -28,6 +31,7 @@ render.experimental.xml

# Google Services (e.g. APIs or Firebase)
google-services.json
secrets.properties

# Android Profiling
*.hprof
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ dependencies {
implementation libs.androidx.annotation
implementation libs.android.libraries.places.places
implementation libs.maps.android.places.places.ktx
implementation libs.accompanist.permissions

// Kotlin Dependencies
implementation platform(libs.jetbrains.kotlin.bom)
Expand Down
Binary file modified app/src/main/assets/database/predefined_credit_cards.db
Binary file not shown.
4 changes: 1 addition & 3 deletions app/src/main/java/edu/card/clarity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ package edu.card.clarity

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.registerForActivityResult
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.AndroidEntryPoint
import edu.card.clarity.presentation.MainScreen
import edu.card.clarity.ui.theme.CardClarityTheme

@AndroidEntryPoint
Expand Down
47 changes: 0 additions & 47 deletions app/src/main/java/edu/card/clarity/presentation/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.card.clarity
package edu.card.clarity.presentation

import android.annotation.SuppressLint
import androidx.compose.foundation.layout.RowScope
Expand Down
34 changes: 0 additions & 34 deletions app/src/main/java/edu/card/clarity/presentation/Purchase.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import edu.card.clarity.presentation.PurchaseScreen
import edu.card.clarity.presentation.addBenefitScreen.AddBenefitScreen
import edu.card.clarity.enums.PurchaseType
import edu.card.clarity.presentation.addCardScreen.AddCardScreen
import edu.card.clarity.presentation.addBenefitScreen.AddBenefitScreen
import edu.card.clarity.presentation.upcomingPaymentsScreen.UpcomingPaymentsScreen
import edu.card.clarity.presentation.homeScreen.HomeScreen
import edu.card.clarity.presentation.myBenefitsScreen.MyBenefitsScreen
import edu.card.clarity.presentation.myCardScreen.MyCardsScreen
import edu.card.clarity.presentation.myReceiptsScreen.MyReceiptsScreen
import edu.card.clarity.presentation.upcomingPaymentsScreen.UpcomingPaymentsScreen
import edu.card.clarity.presentation.purchaseBenefitsScreen.PurchaseOptimalBenefitsScreen
import edu.card.clarity.presentation.purchaseBenefitsScreen.PurchaseScreen
import edu.card.clarity.presentation.utils.ArgumentNames
import edu.card.clarity.presentation.utils.Destinations

Expand All @@ -33,7 +35,7 @@ fun BottomNavGraph(navController: NavHostController) {
MyReceiptsScreen()
}
composable(Destinations.PURCHASE) {
PurchaseScreen()
PurchaseScreen(navController)
}
composable(Destinations.MY_CARDS) {
MyCardsScreen(navController)
Expand Down Expand Up @@ -89,5 +91,13 @@ fun BottomNavGraph(navController: NavHostController) {

AddBenefitScreen(cardName, navController)
}
composable(
route = "${Destinations.PURCHASE_OPTIMAL_BENEFITS}/{category}",
arguments = listOf(navArgument("category") { type = NavType.StringType })
) { backStackEntry ->
val categoryString = backStackEntry.arguments?.getString("category")!!
val category = PurchaseType.valueOf(categoryString)
PurchaseOptimalBenefitsScreen(navController, category)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package edu.card.clarity.presentation.purchaseBenefitsScreen

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import edu.card.clarity.location.GeolocationInference

@Composable
fun GeolocationPopup(
geolocationInference: GeolocationInference?,
onDismiss: () -> Unit,
onConfirm: () -> Unit
) {
if (geolocationInference != null) {
AlertDialog(
onDismissRequest = onDismiss,
title = {
Text(
text = "Nearby Merchant Detected",
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.primary,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(top = 16.dp)
)
},
text = {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.padding(vertical = 16.dp)
) {
Text(
text = "We detected that you're near ",
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)
)
Text(
text = geolocationInference.merchantName,
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Would you explore benefits in ${geolocationInference.purchaseType}?",
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)
)
}
},
confirmButton = {
Button(
onClick = onConfirm,
modifier = Modifier.fillMaxWidth().padding(8.dp)
) {
Text("Yes")
}
},
dismissButton = {
Button(
onClick = onDismiss,
modifier = Modifier.fillMaxWidth().padding(8.dp)
) {
Text("No")
}
},
shape = RoundedCornerShape(16.dp),
containerColor = MaterialTheme.colorScheme.background,
tonalElevation = 8.dp
)
} else {
AlertDialog(
onDismissRequest = onDismiss,
title = {
Text(
text = "Loading",
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.primary,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth().padding(top = 16.dp)
)
},
text = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp)
) {
CircularProgressIndicator()
}
},
confirmButton = {
Button(
onClick = onDismiss,
modifier = Modifier.fillMaxWidth().padding(8.dp)
) {
Text("Dismiss")
}
},
dismissButton = {},
shape = RoundedCornerShape(16.dp),
containerColor = MaterialTheme.colorScheme.background,
tonalElevation = 8.dp
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edu.card.clarity.presentation.purchaseBenefitsScreen

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import edu.card.clarity.location.GeolocationInference
import edu.card.clarity.location.GeolocationInferenceService
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class GeolocationViewModel @Inject constructor(
private val geolocationInferenceService: GeolocationInferenceService
) : ViewModel() {

private val _geolocationInference = MutableStateFlow<List<GeolocationInference>?>(null)
val geolocationInference: StateFlow<List<GeolocationInference>?> = _geolocationInference

fun fetchGeolocationInference() {
viewModelScope.launch {
try {
val inferences = geolocationInferenceService.getPurchaseTypeInference()
Log.d("Inferences", inferences.toString())
_geolocationInference.value = inferences
} catch (e: SecurityException) {
// Handle the case where permissions were not granted
}
}
}
}
Loading