@Composable
fun ExpensesChart() {
val paddingValues = 16.dp
val db = FirebaseFirestore.getInstance()
// Define your timeframes
val timeFrames = listOf("Weekly", "Monthly", "Yearly")
val selectedIndex = remember { mutableStateOf(0) }
// Fetch and process the expenses data
val chartEntries = remember { mutableStateOf(entriesOf()) }
val chartModelProducer = ChartEntryModelProducer(chartEntries.value)
fun fetchExpensesData(timeFrame: String) {
// TODO: Customize the query to fetch data according to the selected time frame
val query = db.collection("expenses")
.orderBy("timestamp", Query.Direction.ASCENDING)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.toFloatArray())
}
}
Column(modifier = Modifier.padding(paddingValues)) {
// Timeframe selection buttons
timeFrames.forEachIndexed { index, timeFrame ->
Button(
onClick = {
selectedIndex.value = index
fetchExpensesData(timeFrame)
},
colors = ButtonDefaults.buttonColors(
containerColor = if (selectedIndex.value == index) DarkGray else LightGray
)
) {
Text(timeFrame)
}
}
// Chart
ProvideChartStyle(chartStyle = m3ChartStyle()) {
Chart(
chart = columnChart(),
chartModelProducer = chartModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
}
}
Not enough information to infer type variable T
Overload resolution ambiguity:
public fun entriesOf(vararg yValues: Number): List defined in com.patrykandpatrick.vico.core.entry
public fun entriesOf(vararg pairs: Pair<Number, Number>): List defined in com.patrykandpatrick.vico.core.entry
Assistant
User
Variable expected on this line and
Overload resolution ambiguity:
public fun entriesOf(vararg yValues: Number): List defined in com.patrykandpatrick.vico.core.entry
public fun entriesOf(vararg pairs: Pair<Number, Number>): List defined in com.patrykandpatrick.vico.core.entry on this line
val chartEntries = remember { mutableStateOf(entriesOf()) }
Assistant
Apologies for the confusion. Since the ambiguity issue still persists, let me suggest another workaround. You can provide an empty array to one of the entriesOf function arguments explicitly, like this:
User
to fetch the different expenses in my firestore I made expenses parent collection, Kantin document, and 4 collections daily, weekly, monthly and yearly
Assistant
User
I do not have a "timestamp" field can we use the document name instead to order the query?
Assistant
Yes, you can order the query using the document name instead of the "timestamp" field. To do this, change the orderBy function in the fetchExpensesData function to the following:
.orderBy(FieldPath.documentId()) // Order by document name
Here's the updated fetchExpensesData function with the modified query:
fun fetchExpensesData(timeFrame: String) {
// Fetch data from the respective sub-collection based on the selected time frame
val query = db.collection("expenses")
.document("Kantin")
.collection(timeFrame.toLowerCase())
.orderBy(FieldPath.documentId()) // Order by document name
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
}
}
Now the query will be ordered by the document name rather than the "timestamp" field. Keep in mind that, for this to work correctly, the document names should follow a sortable format, like the ISO 8601 format for date and time strings (e.g., "2022-02-23T12:34:56").
User
I use Monday_10_Apr_2023, Week_3_Apr_2023, Apr_2023 and 2023 for the format
Assistant
Given your custom date formats, you can parse the document name into a Date object to perform further comparisons or operations. To parse the document name into a Date, you can use the SimpleDateFormat class from the Java standard library to define a pattern that matches your format.
For example, to parse the "Weekly" format "Monday_10_Apr_2023", you would create a object with the pattern "EEEE_dd_MMM_yyyy".
User
I have 4 collections, daily, weekly, monthly and yearly, in the weekly graph I want to take the data of daily from Monday to Sunday
Assistant
To achieve this, you'll need to update the function to fetch the data from the collection when the selected time frame is . You'll also need to filter the documents to include only those that belong to the current week (from Monday to Sunday).
User
scratch that, I want to make it have 4 buttons daily, weekly, monthly, yearly. daily will act as weekly, showing 7 days in the week, weekly will shows 4 weeks in a month, monthly will shows 12 months in a year
Assistant
User
the field name I want to get as the amount is total
Assistant
To fetch the total field as the amount in the fetchExpensesData function, you just need to replace amount with total when retrieving the value from the document.
Here's the updated fetchExpensesData function with total field instead of amount:
import java.util.Calendar
fun fetchExpensesData(timeFrame: String) {
val startCalendar = Calendar.getInstance()
val endCalendar = Calendar.getInstance()
// ... (rest of the existing code unchanged)
val query = db.collection("expenses")
.document("Kantin")
.collection("daily")
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Pair<Float, Date>>()
for (document in result) {
val total = document.getDouble("total")?.toFloat() ?: 0f // Fetch the 'total' field value
val date = dateFormat.parse(document.id) ?: Date()
expenses.add(total to date) // Use 'total' instead of 'amount'
}
// ... (rest of the existing code unchanged)
}
}
Now, the fetchExpensesData function will fetch the field from the documents and use it as the amount for the expenses.
User
why is the graph still showing 0 in all 4 timeframes
Assistant
The graph may still show zeroes if the data from Firestore isn't correctly fetched, parsed, or processed. Let's add some debug print statements to the fetchExpensesData function to better understand what's happening.
Add these println statements after fetching the total field, filtering the expenses, and updating the chart entries:
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Pair<Float, Date>>()
for (document in result) {
val total = document.getDouble("total")?.toFloat() ?: 0f
val date = dateFormat.parse(document.id) ?: Date()
println("Document: ${document.id}, Total: $total, Date: $date") // Debug: print document details
expenses.add(total to date)
}
expenses.retainAll { it.second >= startCalendar.time && it.second <= endCalendar.time }
println("Filtered expenses: $expenses") // Debug: print filtered expenses
expenses.sortBy { it.second }
chartEntries.value = entriesOf(*expenses.map { it.first to 0 }.toTypedArray())
println("Chart entries: ${chartEntries.value}") // Debug: print chart entries
}
Based on your provided output, the fetched documents and parsed details appear to be correct. Now let's look into the chart rendering or configuration to see if there are any issues.
Since you're using columnChart() as your chart type, make sure that the ColumnChart is configured correctly. Here, I suggest trying a LineChart instead of a ColumnChart, which should be better at rendering these data points, given the example you provided.
Replace the following line:
chart = columnChart(),
with
chart = lineChart(),
If you would still like to use a column chart, consider upgrading your chart library version to the latest release or seek help from the official documentation to ensure that it's set up and configured correctly.
Once you've updated the chart type, re-run your application and see if it properly renders the data points in each timeframe.
User
val query = db.collection("expenses")
.document("Kantin")
.collection("daily")
chartEntries.value = entriesOf(*expenses.map { it.first to 0 }.toTypedArray())
maybe the problem could be these two, why is .collection on daily?
Assistant
My apologies for the confusion. You're right; there is an issue with the hardcoding of the 'daily' collection in the fetchExpensesData function. You should be using the collection path depending on the selected time frame.
Update the fetchExpensesData function to use the collectionPath variable instead of the hardcoded 'daily' collection:
fun fetchExpensesData(timeFrame: String) {
// ... other code ...
// Define the collection path based on the time frame
val collectionPath = when (timeFrame) {
"Daily" -> "daily"
"Weekly" -> "weekly"
"Monthly" -> "monthly"
"Yearly" -> "yearly"
else -> "daily"
}
val query = db.collection("expenses")
.document("Kantin")
.collection(collectionPath) // Use the collectionPath variable here
// ... other code ...
}
This update ensures that the query uses the correct collection based on the selected time frame.
Now, re-run your application and see if it properly renders the data points in each timeframe.
User
Assistant
The error you've encountered is due to the ParseException caused by the "Weekly" format "Week_3_Apr_2023" that is not compatible with the "EEEE_dd_MMM_yyyy" date format currently used in the fetchExpensesData function.
To resolve this issue, you need to update the date format for the "Weekly" time frame. However, it's a bit challenging to parse the "Week_3_Apr_2023" format directly using SimpleDateFormat. Thus, I recommend changing the document names in the Weekly collection to a format like "Week_1_MMM_yyyy" or simply "MMM_yyyy" for easier parsing.
For demonstration purposes, let's update the function to handle a document name with format "Week_1_MMM_yyyy":
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
It seems that the entriesOf function has two overloaded versions, and the compiler is unable to decide which one to use. To resolve this ambiguity, you could explicitly call the desired version of the function by providing a single argument or a pair of arguments.
In this case, you only need a single argument (the expense amount). You can solve this by changing the following line:
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
This change creates a Pair for each expense amount, setting the second value to 0 (which will be ignored, but resolves the ambiguity issue).
Here's the complete, modified code snippet:
@Composable
fun ExpensesChart() {
val paddingValues = 16.dp
val db = FirebaseFirestore.getInstance()
// Define your timeframes
val timeFrames = listOf("Weekly", "Monthly", "Yearly")
val selectedIndex = remember { mutableStateOf(0) }
// Fetch and process the expenses data
val chartEntries = remember { mutableStateOf(entriesOf()) }
val chartModelProducer = ChartEntryModelProducer(chartEntries.value)
fun fetchExpensesData(timeFrame: String) {
// TODO: Customize the query to fetch data according to the selected time frame
val query = db.collection("expenses")
.orderBy("timestamp", Query.Direction.ASCENDING)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
}
}
Column(modifier = Modifier.padding(paddingValues)) {
// Timeframe selection buttons
timeFrames.forEachIndexed { index, timeFrame ->
Button(
onClick = {
selectedIndex.value = index
fetchExpensesData(timeFrame)
},
colors = ButtonDefaults.buttonColors(
containerColor = if (selectedIndex.value == index) DarkGray else LightGray
)
) {
Text(timeFrame)
}
}
// Chart
ProvideChartStyle(chartStyle = m3ChartStyle()) {
Chart(
chart = columnChart(),
chartModelProducer = chartModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
}
}
val chartEntries = remember { mutableStateOf(entriesOf(*arrayOf<Float>())) }
Here's the complete, modified code snippet:
@Composable
fun ExpensesChart() {
val paddingValues = 16.dp
val db = FirebaseFirestore.getInstance()
// Define your timeframes
val timeFrames = listOf("Weekly", "Monthly", "Yearly")
val selectedIndex = remember { mutableStateOf(0) }
// Fetch and process the expenses data
val chartEntries = remember { mutableStateOf(entriesOf(*arrayOf<Float>())) }
val chartModelProducer = ChartEntryModelProducer(chartEntries.value)
fun fetchExpensesData(timeFrame: String) {
// TODO: Customize the query to fetch data according to the selected time frame
val query = db.collection("expenses")
.orderBy("timestamp", Query.Direction.ASCENDING)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
}
}
Column(modifier = Modifier.padding(paddingValues)) {
// Timeframe selection buttons
timeFrames.forEachIndexed { index, timeFrame ->
Button(
onClick = {
selectedIndex.value = index
fetchExpensesData(timeFrame)
},
colors = ButtonDefaults.buttonColors(
containerColor = if (selectedIndex.value == index) DarkGray else LightGray
)
) {
Text(timeFrame)
}
}
// Chart
ProvideChartStyle(chartStyle = m3ChartStyle()) {
Chart(
chart = columnChart(),
chartModelProducer = chartModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
}
}
Now the ambiguity issue in the line val chartEntries = remember { mutableStateOf(entriesOf()) } should be resolved.
Given the structure of your Firestore, you need to modify the fetchExpensesData function to fetch the data from the respective daily, weekly, monthly, and yearly sub-collections based on the user's timeframe selection. Here's the updated function:
fun fetchExpensesData(timeFrame: String) {
// Fetch data from the respective sub-collection based on the selected time frame
val query = db.collection("expenses")
.document("Kantin")
.collection(timeFrame.toLowerCase())
.orderBy("timestamp", Query.Direction.ASCENDING)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
}
}
Make sure that the collection names in your Firestore ("daily", "weekly", "monthly", "yearly") are in lowercase, as the modified fetchExpensesData function converts the timeFrame variable to lowercase to match the respective Firestore collection name.
Here's the full, modified ExpensesChart composable function with the updated fetchExpensesData function:
@Composable
fun ExpensesChart() {
val paddingValues = 16.dp
val db = FirebaseFirestore.getInstance()
// Define your timeframes
val timeFrames = listOf("Weekly", "Monthly", "Yearly")
val selectedIndex = remember { mutableStateOf(0) }
// Fetch and process the expenses data
val chartEntries = remember { mutableStateOf(entriesOf(*arrayOf<Float>())) }
val chartModelProducer = ChartEntryModelProducer(chartEntries.value)
fun fetchExpensesData(timeFrame: String) {
// Fetch data from the respective sub-collection based on the selected time frame
val query = db.collection("expenses")
.document("Kantin")
.collection(timeFrame.toLowerCase())
.orderBy("timestamp", Query.Direction.ASCENDING)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Float>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
expenses.add(amount)
}
chartEntries.value = entriesOf(*expenses.map { it to 0 }.toTypedArray())
}
}
Column(modifier = Modifier.padding(paddingValues)) {
// Timeframe selection buttons
timeFrames.forEachIndexed { index, timeFrame ->
Button(
onClick = {
selectedIndex.value = index
fetchExpensesData(timeFrame)
},
colors = ButtonDefaults.buttonColors(
containerColor = if (selectedIndex.value == index) DarkGray else LightGray
)
) {
Text(timeFrame)
}
}
// Chart
ProvideChartStyle(chartStyle = m3ChartStyle()) {
Chart(
chart = columnChart(),
chartModelProducer = chartModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
}
}
Now, the data should be fetched from the correct Firestore sub-collection based on the selected timeframe.
SimpleDateFormat
Here's the updated fetchExpensesData function with sorting on parsed document names:
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
fun fetchExpensesData(timeFrame: String) {
// Define the date formats for each time frame
val dateFormat = when (timeFrame) {
"Weekly" -> SimpleDateFormat("EEEE_dd_MMM_yyyy", Locale.ENGLISH)
"Monthly" -> SimpleDateFormat("MMM_yyyy", Locale.ENGLISH)
"Yearly" -> SimpleDateFormat("yyyy", Locale.ENGLISH)
else -> throw IllegalArgumentException("Unsupported time frame: $timeFrame")
}
val query = db.collection("expenses")
.document("Kantin")
.collection(timeFrame.toLowerCase())
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Pair<Float, Date>>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
val date = dateFormat.parse(document.id) ?: Date()
expenses.add(amount to date)
}
// Sort the expenses by date
expenses.sortBy { it.second }
// Retain only the amounts for the chart entries
chartEntries.value = entriesOf(*expenses.map { it.first to 0 }.toTypedArray())
}
}
The code above defines a SimpleDateFormat object based on the selected time frame, parses the document name into a Date object, collects the expenses as pairs of amounts and dates, sorts the expenses by date, and finally creates the chart entries using only the amounts.
Now, your query will be sorted based on the parsed document names without relying on the "timestamp" field.
fetchExpensesData
daily
Weekly
Here's the updated fetchExpensesData function that handles the Weekly time frame by fetching data from the daily collection and filtering documents:
import java.util.Calendar
fun fetchExpensesData(timeFrame: String) {
// Define the date formats for each time frame
val dateFormat = when (timeFrame) {
"Weekly" -> SimpleDateFormat("EEEE_dd_MMM_yyyy", Locale.ENGLISH)
"Monthly" -> SimpleDateFormat("MMM_yyyy", Locale.ENGLISH)
"Yearly" -> SimpleDateFormat("yyyy", Locale.ENGLISH)
else -> throw IllegalArgumentException("Unsupported time frame: $timeFrame")
}
val collectionPath = if (timeFrame == "Weekly") "daily" else timeFrame.toLowerCase()
val query = db.collection("expenses")
.document("Kantin")
.collection(collectionPath)
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Pair<Float, Date>>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
val date = dateFormat.parse(document.id) ?: Date()
expenses.add(amount to date)
}
if (timeFrame == "Weekly") {
// Filter the documents to include only those that belong to the current week
val calendar = Calendar.getInstance().apply { firstDayOfWeek = Calendar.MONDAY }
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
val startDateOfWeek = calendar.time
calendar.add(Calendar.DATE, 6)
val endDateOfWeek = calendar.time
expenses.retainAll { it.second >= startDateOfWeek && it.second <= endDateOfWeek }
}
// Sort the expenses by date
expenses.sortBy { it.second }
// Retain only the amounts for the chart entries
chartEntries.value = entriesOf(*expenses.map { it.first to 0 }.toTypedArray())
}
}
This implementation updates the collectionPath based on the timeFrame and filters the documents based on the calculated start and end dates of the week.
Now, when the selected time frame is Weekly, the function fetches data from the daily collection and includes only the documents belonging to the current week.
To modify the implementation to support four buttons: "Daily", "Weekly", "Monthly", and "Yearly", you can update the timeFrames list and make corresponding modifications to the fetchExpensesData function.
Here's the updated implementation with four buttons:
@Composable
fun ExpensesChart() {
val paddingValues = 16.dp
val db = FirebaseFirestore.getInstance()
// Define your timeframes
val timeFrames = listOf("Daily", "Weekly", "Monthly", "Yearly")
val selectedIndex = remember { mutableStateOf(0) }
// Fetch and process the expenses data
val chartEntries = remember { mutableStateOf(entriesOf(*arrayOf<Float>())) }
val chartModelProducer = ChartEntryModelProducer(chartEntries.value)
// ... update the fetchExpensesData function here
Column(modifier = Modifier.padding(paddingValues)) {
// Timeframe selection buttons
timeFrames.forEachIndexed { index, timeFrame ->
Button(
onClick = {
selectedIndex.value = index
fetchExpensesData(timeFrame)
},
colors = ButtonDefaults.buttonColors(
containerColor = if (selectedIndex.value == index) DarkGray else LightGray
)
) {
Text(timeFrame)
}
}
// Chart
ProvideChartStyle(chartStyle = m3ChartStyle()) {
Chart(
chart = columnChart(),
chartModelProducer = chartModelProducer,
startAxis = startAxis(),
bottomAxis = bottomAxis(),
)
}
}
}
Now, update the fetchExpensesData function to handle the new four timeframes:
import java.util.Calendar
fun fetchExpensesData(timeFrame: String) {
val startCalendar = Calendar.getInstance()
val endCalendar = Calendar.getInstance()
when (timeFrame) {
"Daily" -> {
// Daily: Showing 7 days in a week
startCalendar.set(Calendar.DAY_OF_WEEK, startCalendar.firstDayOfWeek)
endCalendar.set(Calendar.DAY_OF_WEEK, startCalendar.firstDayOfWeek)
endCalendar.add(Calendar.DATE, 6)
}
"Weekly" -> {
// Weekly: Showing 4 weeks in a month
startCalendar.set(Calendar.DAY_OF_MONTH, 1)
endCalendar.set(Calendar.DAY_OF_MONTH, startCalendar.getActualMaximum(Calendar.DAY_OF_MONTH))
}
"Monthly" -> {
// Monthly: Showing 12 months in a year
startCalendar.set(Calendar.MONTH, 0)
startCalendar.set(Calendar.DAY_OF_MONTH, 1)
endCalendar.set(Calendar.MONTH, 11)
endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH))
}
"Yearly" -> {
// Remove time frame handling as the current implementation supports it
}
else -> throw IllegalArgumentException("Unsupported time frame: $timeFrame")
}
// Define the date formats for each time frame
val dateFormat = SimpleDateFormat("EEEE_dd_MMM_yyyy", Locale.ENGLISH)
val query = db.collection("expenses")
.document("Kantin")
.collection("daily")
query.get().addOnSuccessListener { result ->
val expenses = mutableListOf<Pair<Float, Date>>()
for (document in result) {
val amount = document.getDouble("amount")?.toFloat() ?: 0f
val date = dateFormat.parse(document.id) ?: Date()
expenses.add(amount to date)
}
// Filter the documents based on the calculated start and end dates
expenses.retainAll { it.second >= startCalendar.time && it.second <= endCalendar.time }
// Sort the expenses by date
expenses.sortBy { it.second }
// Retain only the amounts for the chart entries
chartEntries.value = entriesOf(*expenses.map { it.first to 0 }.toTypedArray())
}
}
In this updated implementation, the fetchExpensesData function handles all four timeframes and computes the respective start and end dates based on the selected timeframe. Then, it filters the documents based on the start and end dates and updates the chart.
Now, you should have four buttons – "Daily", "Weekly", "Monthly", and "Yearly" – with their respective functions as described.
total
Re-run your application with these debug statements and check the logs in the Logcat or run console to see the output. Whenever you click on the buttons, the log statements should print the fetched details, filtered expenses, and chart entries.
Based on the debug output, you can determine if there are any issues with fetching the data, parsing the document names into dates, or filtering the expenses by date.
If the debug print statements indicate that the data is fetched and processed correctly, then the problem might be with the chart rendering or configuration. In that case, recheck your chart configuration or consult the chart library's documentation for troubleshooting.
FATAL EXCEPTION: main
Process: com.parents.present, PID: 23224
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInitMethodAndArgsCaller.run(RuntimeInit.java:558)atcom.android.inMethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: java.text.ParseException: Unparseable date: "Week_3_Apr_2023"
at java.text.DateFormat.parse(DateFormat.java:389)
at com.parents.present.Screens.ExpensesScreenKtExpensesScreenfetchExpensesData1.invoke(ExpensesScreenExpensesScreenfetchExpensesData1.invoke(ExpensesScreen.kt:142)
at com.parents.present.Screens.ExpensesScreenKt.ExpensesScreenfetchExpensesDatalambda2(ExpensesScreen.kt:r8lambdaYU8DnTvjaAW62TmnpZ4irF6rMtQ(Unknown Source:0)
at com.parents.present.Screens.ExpensesScreenKt$$ExternalSyntheticLambda0.onSuccess(Unknown Source:2)
at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7925)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
fun fetchExpensesData(timeFrame: String) {
// Define the date formats for each time frame
val dateFormat = when (timeFrame) {
"Daily" -> SimpleDateFormat("EEEE_dd_MMM_yyyy", Locale.ENGLISH)
"Weekly" -> SimpleDateFormat("'Week_'W'_MMM_yyyy", Locale.ENGLISH) // Updated pattern to match "Week_1_MMM_yyyy"
"Monthly" -> SimpleDateFormat("MMM_yyyy", Locale.ENGLISH)
"Yearly" -> SimpleDateFormat("yyyy", Locale.ENGLISH)
else -> throw IllegalArgumentException("Unsupported time frame: $timeFrame")
}
// ... rest of the existing code ...
}
After updating the date format, please also update your Firestore document names for the "Weekly" collection accordingly. Make sure they follow the format "Week_1_MMM_yyyy" (e.g., "Week_1_Apr_2023").
After making these changes, the error should be resolved, and the chart should display the data for the Weekly time frame.
If you still want to keep the current document name format ("Week_3_Apr_2023"), you might need to write custom parsing logic to handle the week number extraction and date calculation.