I'm creating a library (using Kotlin) and have a requirement to create a String extension that searches an ArrayList and returns a value. As the extension will be called many times I only want to load the ArrayList once and reuse it, so my approach so far is this:
Create the String extension, this is working, no issues.
The extension calls a function in a singleton which returns the results, this approach is working as I'm manually creating the ArrayList in the init of the singleton. The final solution needs to read a .csv file from the res/raw folder which will then create the ArrayList and this is where my problems start.
I'm struggling to find examples of reading a .csv file, currently I have a solution (test application, not a library) that reads the .csv from /app/src/main/assets using the following line of code:
applicationContext.assets.open("test.csv").bufferedReader().use {}
Is this the best approach for reading a file, /res/raw seems more logical?
Assuming that my current approach is OK as soon as I move this code into my library and use it in the singleton I hit issues relating to context. I do not want the extension to have to pass context to the singleton, ideally I would like the init of the singleton to be able to fetch the context.
So in summary... I'm trying to find a way of my Singleton in a library to have access to the context so that the .csv file can be loading into an ArrayList once only.