With the IDE project, build tool, and required libraries sorted out, we can start developing our app.
Since the dictionary words are stored in a JSON file, we need to parse the data before saving it to a local database.
First, we'll add the class that will represent our data. In the base package (com.packt.quickstart.dictionary
), we first add a new package called data
. There, we put the DictionaryEntry
class, which will be our data model representation:
data class DictionaryEntry(val term: String, val explanation: String)
The class has two properties: the searchable term and the term definition. It'd be also nice to have a readable string representation of this class, so we let the Kotlin compiler generate a toString
method for us with its data class.
Since the file of words is around 20 MB in size, to avoid loading that much data in the memory at once and deserializing the whole file in one go, we'll deserialize it manually, entry by entry.
For...