Replace the Source Code and Resource Files
Next, let’s update the source code of the ZCDrive app and its resource files. To make this easy, we have given you a link to the Git repository that contains the code for the necessary modules. You will simply have to replace your files with the given files.
- Navigate to ZCDrive > app > src > main in your Android project directory from your system.
- Delete the following directories and file in the main folder:
- java/
- res/
- AndroidManifest.xml
- Download the java/ and res/ directories, and the AndroidManifest.xml file from this Git repo.
- Paste the downloaded files in the main folder.
The source code and resources for the app are now updated.
Let’s take a quick look at the code of the ZCDrive app.
Note: Please go through the source code and the comments as you read through these points to make sure you fully understand them.
- The res folder contains the app’s standard resources optimized for different device configurations in type-specific individual directories. These resources include various XML files that define the layouts, views, bitmaps, and more.
- The AndroidManifest.xml file contains crucial information about the app that is communicated to the build tools, the Android OS, and Google play. For example, it declares the app’s components, permissions, and the hardware and software requirements of the target device for the app to run on.
- The assets directory we created contains the app_configuration_development.properties file that was downloaded after registering the app in Catalyst.
- The java directory contains the actual source code of the app in the form of various Kotlin files:
- Initialization.kt: Contains the startup logic for the creation of the main activity.
- Signup.kt: Defines the logic and the layout for the signup and login activities in the app. The registerUser() method fetches the details of a new user, such as their name and email address, during the signup and creates a new user instance through Catalyst Authentication.
- MainActivity.kt: The Activity class informs the Android system to invoke specific callback methods in the Activity instance for the various stages of the app’s lifecycle. MainActivity defines methods to initiate login and signup in the app. When you build and run your app, the system launches an instance of this Activity and loads its layout.
- HomeActivity.kt: Contains methods involved in defining the app’s home activity, such as for loading the home page after the authentication check, setting values of the file items to the RecyclerView container for displaying the files, fetching the metadata of the files from the Data Store through a fileItem object and rendering them in the view, rendering the view after the files are deleted, the user logout, and more.
- UploadDialog.kt: Handles the file upload activity in the app. The file is uploaded to the configured folder in the File Store. A new row is created in the Data Store, and the file’s metadata is extracted and set to the row’s columns. An object for the fileItem class that contains the file’s metadata is then created, and the file item is rendered in the HomeActivity.
- UserFileDownloadManager.kt: Handles the file download activity in the app. When the download is initiated by the user, the file in the File Store is referred to by an instance, and it is fetched and stored in a temporary file path. fileOutputStream downloads the file from the path.
- DeleteDialog.kt: Handles the file deletion activity. A file instance is created to refer to the file in the File Store using its File ID, and the file is deleted using the file.delete() method. The row that stores the file’s metadata is also fetched using a Data Store table instance, and the row is deleted from the table.
- The LinearViewAdapter and the GridViewAdapter define the rendering of the file items in the adapters of the app’s LinearView and GridView respectively.
- PreviewFile.kt: Defines the methods for previewing a file in the app, after checking for permissions. The previewFile() method fetches the file instance from the File Store and opens a preview.
The java directory also contains sub-directories that define instrumented Android tests and independent unit tests of the app, which we will not be performing.
Last Updated 2024-04-05 23:41:34 +0530 +0530