RecurringExpenseTracker icon indicating copy to clipboard operation
RecurringExpenseTracker copied to clipboard

Changing default currency

Open bartoszluka opened this issue 11 months ago • 8 comments

This PR adds the ability to change the default currency used in application:

  • [x] UI in settings to select new currency
    • [ ] Labels for different languages
    • [x] Getting a list of all the currencies from somewhere
    • [x] Searching for currency code
    • [x] Preview of the format for the currency
  • [x] Storing currency using DataStore
  • [x] Reading stored currency
  • [ ] Using it throughout the whole app
  • [ ] Beautiful UI

bartoszluka avatar Feb 24 '24 16:02 bartoszluka

Generally I like the approach. Some suggestions from my side for the current state:

  • The CurrencyPicker could be opened and handled fully inside the SettingsScreen, making sure the MainActivity itself doesn't grow further.
  • Right now you only support a list of locales with their respective currency. Can you iterate over the locales getting the currencies for all locales? Maybe it could then be filtered to get rid of duplicates.
  • There's an option to get the currency symbol and code like below, but I think showing it with an example amount can also work.
val currency = Currency.getInstance(locale)
val currencyCode = currency.getCurrencyCode()
val currencySymbol = currency.getSymbol()
  • Depending on the currencies list size having a separate screen with a search capability instead of a BottomSheet could be beneficial but that need to be tested how it feels.

DennisBauer avatar Feb 25 '24 17:02 DennisBauer

Thanks for reviewing it.

Regarding the locales, there is a method to get all of them which is like 800 of them and it slows the opening of the popup significantly. Maybe there is a way to prefetch the list somehow? Also showing just currencies might not be correct because formatting for EUR in German and Italian locales are different.

Currency symbol and overall formatting of the money amount is easy to change. My current implementation was just an example idea.

I don't really get what you're saying about CurrencyPicker being inside SettingsScreen. I think I faced an issue with correctly initializing the UserPreferencesRepository if it's not in the main activity. I'm not an expert so maybe there is a way to avoid that.

One issue I'm worrying about is displaying the value in the changed locale. This would mean every function toCurrencyString would need to access the UserPreferencesRepository and it's suspend fun. Won't this cause some issues?

bartoszluka avatar Feb 25 '24 18:02 bartoszluka

Maybe there is a way to prefetch the list somehow?

Yes I think that could be achieved by loading them inside a Coroutine when opening the settings tab.

Also showing just currencies might not be correct because formatting for EUR in German and Italian locales are different.

Probably you're right, I missed that the formatting can also be different. Just using a limited list will not work for everyone so I would prefer to have the full list. Maybe a list of the countries with the currency symbol and/or the currency name:

Germany (Euro €)
United States (Dollar $)

I don't really get what you're saying about CurrencyPicker being inside SettingsScreen. I think I faced an issue with correctly initializing the UserPreferencesRepository if it's not in the main activity. I'm not an expert so maybe there is a way to avoid that.

Can you elaborate a bit on the issue you phased? Creating the SettingsViewModel in the MainActivity is fine. I was just referring to the Composable you added in the MainActivity.

One issue I'm worrying about is displaying the value in the changed locale. This would mean every function toCurrencyString would need to access the UserPreferencesRepository and it's suspend fun. Won't this cause some issues?

Yes that part might need to be refactored e.g. by having the currency string already added to the data class which is created in the VM. There we could provide the locale the user defined and put it to the RecurringExpenseData.

DennisBauer avatar Feb 25 '24 18:02 DennisBauer

@DennisBauer I made some changes.

Yes I think that could be achieved by loading them inside a Coroutine when opening the settings tab.

Still not sure how to do this, help needed. Current implementation uses remember and gets the list of 400 or so different currencies, it's still pretty slow.

Can you elaborate a bit on the issue you phased? Creating the SettingsViewModel in the MainActivity is fine. I was just referring to the Composable you added in the MainActivity.

I moved CurrencyPicker into SettingsScreen and I didn't face any issues.

Yes that part might need to be refactored e.g. by having the currency string already added to the data class which is created in the VM. There we could provide the locale the user defined and put it to the RecurringExpenseData.

Unresolved but keeping the locale in the data seems good. This might make using different currencies for different expenses in the future easier

bartoszluka avatar Feb 26 '24 12:02 bartoszluka

Still not sure how to do this, help needed. Current implementation uses remember and gets the list of 400 or so different currencies, it's still pretty slow.

Unfortunately I don't have time during this week but can have a look at it on Sunday

I moved CurrencyPicker into SettingsScreen and I didn't face any issues.

Great.

Unresolved but keeping the locale in the data seems good. This might make using different currencies for different expenses in the future easier

Yes that way we can also get rid of the extension function.

DennisBauer avatar Feb 26 '24 19:02 DennisBauer

@bartoszluka I'm sorry, but I'm very busy at the moment, so I won't be able to check it before the weekend next week.

DennisBauer avatar Mar 08 '24 10:03 DennisBauer

@DennisBauer Have you checked this?

saltsoftdrink avatar Mar 27 '24 07:03 saltsoftdrink

@saltsoftdrink not yet, sorry. Still planning to do it.

DennisBauer avatar Mar 27 '24 08:03 DennisBauer

@DennisBauer if possible please add this feature 🙏🙂

saltsoftdrink avatar May 24 '24 01:05 saltsoftdrink

@saltsoftdrink I'm still planning to add the feature to choose the currency yourself. I would also like to add the capability to define the currency by expense. However, I'm currently working on a bigger rework of the app migrating it to Kotlin Multiplatform. This will enable the app to also run on iOS, Windows, macOS and Linux. It's not fully working yet but quite far. After that I'll focus on app features again.

DennisBauer avatar May 29 '24 19:05 DennisBauer

Sorry that it took so long to come back to this topic, but I wanted to focus on other parts of the app first. I created a PR #257 which adds a default currency selection in the settings. If set that currency will be used throughout the whole app. If not the system default is used.

DennisBauer avatar Jul 14 '24 09:07 DennisBauer

@bartoszluka Closed this PR as it is anyway outdated for quite some time and has a lot of conflicts. Feel free to take a look at my changes and suggest changes or create a foll up PR for improvements you would like to do. I'll merge my PR later today and create a new release beginning of next week. FYI: @saltsoftdrink

DennisBauer avatar Jul 14 '24 10:07 DennisBauer

No problem, it's your project. I'll take a look at your changes soon

bartoszluka avatar Jul 14 '24 10:07 bartoszluka