Welcome back.
We finished the predict mileage function and the validate features.
Also we finished the car mileage predictor class.
Now let's make use of this class and execute the functions.
Open the car mileage predictor screen.
And inside this composable let's create some variables.
So here val predictor equals remember and car mileage predictor class.
And what we need to pass is a context.
So for that let's create a val app.
Context equals to context.
And if it is not null then go and get the current local context.
Pass it here to the car mileage predictor.
Also we need to create an instance of prediction results bar.
Remember it's a mutable state of float.
We need to get the result as a float and make it null.
Then var is loading.
Check if it is loading or not.
So we need to check if the model is calculating and loading or not, just in case displaying a circular
progress bar or not.
Okay, we have the validation errors and car features.
Okay.
Scroll down to the button.
And here the prediction button.
We need to work here.
Here in the onClick.
We need to start by creating a new variable called validation equals to predictor dot validate features
and pass the car features variable.
So here the predictor is an instance of the predictor car mileage predictor class and validate features
is the function that we use we we created in the previous video.
Okay.
We need to pass a car feature variable I pass the car features mutable state.
Now set the validation errors to validation dot errors.
So get from this function the errors list and store it inside the validation errors variable.
Here, let me check if validation is valid.
I told you that this validation is of type uh validate results and this takes two parameters is valid
and errors.
If it is valid it's a boolean.
No errors go and return true if there is any error, return false.
So if there is, there is no errors.
The validation errors list is empty.
This is the logic get is loading to true.
Set it to true.
Prediction.
A result equals to predict dot, predict mileage and pass the card features and is loading.
Set it to false.
Here we are checking if everything every input is valid.
Then go and set the validation to true and if it is true, go and execute the predict mileage function.
Okay, so we used this function validate features to check for all valid inputs.
If all valid inputs are okay and no errors.
So the that validate results returns as valid to true and errors empty.
Then go and execute this function.
Predict mileage and pass the card features as a parameter.
Okay, this is the logic behind using this function.
Then enabled.
If it is not loading then set it to loading so it's opposite to loading if it is loading.
So disable the button.
If it is not loading anything go and enable this button okay.
Inside it.
What we need to do.
We can set a circular progress indicator for uh for displaying that we are making calculation and the
TensorFlow model is working.
So if is loading.
What we need to do create a circular progress indicator.
Said the modifier.
Set the color and make a spacer ATP text.
Set it to predicting and else if it is not, go and display predict mileage.
Then create.
Outside this button we need to display our predictions result.
So let me create a spacer modifier.
Then the predictions result.
If it is not null, go and create an mpg parameter and pass it to the prediction results card.
Okay, so if there is a prediction result, go and display it in the in the prediction result card.
Okay this is our application.
Now let's test our amazing application.