The core directory contains code and abstract classes that are extended by other activities in the Matar Android app.
Core Directory
--core(directory)
--base(directory)
--ActBase.kt(file)(ActBase is an abstract class serving as blueprints for other classes)
--BaseActivity.kt(file)()
--FragBase.kt(file)
--DataResult.kt(file)
--ResultWrapper.kt(file)
This class is meant to be extended by other activities in your Android app. Here's a breakdown of what this class does:
Imports: It imports necessary packages and classes that are used in the class.
Class Declaration: It declares a generic class ActBase that extends LocalizationActivity. The generic type actBinding is expected to be a ViewBinding class specific to the child activity that extends this base class.
Properties:
binding: This property is used to hold the instance of the view binding for the child activity.
analyticsViewModel
preferenceManager
onCreate() Method: This method is an Android lifecycle method that gets called when the activity is created. In this method:
An instance of the activity's content view is set to the root view of the binding.
Abstract Methods:
setViewBinding()
: This abstract method is meant to be implemented by child activities to provide the appropriate view binding for that activity.
bindObjects()
openFragment() Method: This method is used to replace a fragment within the activity's fragment container. It takes three parameters:
fragment: The fragment to be displayed.
**fragmentName **: A tag or name for the fragment.
**fragmentContainerId **: The ID of the container where the fragment should be displayed. It replaces the current fragment with the specified fragment using a transaction.
An abstract base class named BaseActivity in an Android application serve as a foundation for other activities in your app. Let's break down what this class does:
Inheritance: BaseActivity inherits from another class named LocalizationActivity.
Properties:
dialog
bind
preferencesManager
analyticsViewModel
firebaseViewModel
onCreate Method: This is an override of the onCreate method from the Android Activity class. It sets up the activity by:
Setting the content view using data binding.
Calling
Initializing the
Creating an instance of
showDialog and hideDialog Methods: These methods allow you to show and hide dialog boxes, respectively. They use the dialog property.
onViewReady and getLayout Methods: These are abstract methods that you must implement in subclasses. onViewReady is called in onCreate after setting up the view, and getLayout should return the layout resource ID for the activity layout.
showToast Method: A utility method for displaying toast messages.
isValidEmail Method: A utility method for checking if a given string is a valid email address using a regular expression.
openFragment Method: This method allows you to replace the fragment in the activity's layout with a new one. It uses the FragmentManager to perform the transaction.
hideKeyboard Extension Function: An extension function for hiding the soft keyboard. It takes a View as an argument and uses the InputMethodManager to hide the keyboard.
Subclasses of BaseActivity can implement the onViewReady and getLayout methods to customize their behavior. Also, analytics and Firebase functionality can be integrated for tracking user interactions into the app.
FragBase is an abstract class that extends Fragment, making it a base class for other fragments in your Android app.
The class is parameterized with actBinding, which is expected to be a subtype of ViewBinding. This allows you to use view binding to interact with your fragment's layout.
Inside the class, two view models are declared and initialized using viewModels(). These view models are analyticsViewModel and firebaseViewModel, which are presumably used for handling analytics and Firebase-related functionality in your app.
A lateinit property binding of type actBinding is declared. This property will be used to store the view binding instance for the fragment's layout.
The onCreateView function is overridden. This function is called when the fragment is created and is responsible for inflating the fragment's layout, binding views, and returning the root view.
Inside onCreateView, setViewBinding() is called to initialize the binding property with the appropriate view binding instance for the fragment.
The bindObjects(), bindListener(), and bindMethod() functions are called within onCreateView. These are abstract functions that must be implemented by subclasses of FragBase. They are meant for initializing objects, setting up listeners, and binding methods related to the fragment's functionality.
FragBase can provide** ** implementations for setViewBinding(), bindObjects(), bindListener(), and bindMethod(), which allows you to customize the behavior and layout of your fragment.