Problems covered in this chapter |
|
The class GlobalAppStore.kt is an utility class in which various constants and methods are defined that can be accessed from anywhere. At the moment, this class is not very extensive, but this will change in the course of the tutorial:
The TAG variable contains the class name (i.e. ”GlobalAppStore” in the class above). This variable is set in many classes throughout the tutorial and has proved useful when using the log methods (e.g. Log.d(TAG, ”This is a log message …”).
In the variable mainUserId we store the ID of the person who is set as the main user in the settings. Since this ID is needed in many places in an extensive CRUD app for pre-filling the person drop-down box, it is advisable to store its value in GlobalAppStore.
Similarly, the application context, which must be accessed in various fragments and ViewModels (e.g. for file operations, etc.), is stored in the global variable appCtx.
The constants APP_PREFIX, APP_FILEPATH_PREFIX and APP_DB_NAME define string constants that are needed throughout the app and are therefore defined here.