![]() |
VOOZH | about |
In this tutorial, we will explore how to build a workout app in Kotlin that allows users to track their exercises, includes a countdown timer for each exercise, and displays animated GIFs for a visually engaging workout experience. We'll leverage the power of the Glide library to seamlessly load and display GIF images. By the end of this tutorial, you'll have a basic workout app that you can enhance and customize according to your needs. A sample video is given below to get an idea about what we are going to do in this article.
Step 1: Project Setup
Create a new Android project in Android Studio. Add the Glide library as a dependency in your app's build.gradle file. Set up the necessary layout files and resources for the workout activity.
implementation 'com.github.bumptech.glide:glide:4.12.0'Step 2: Exercise Data Model
Create an Exercise data class with properties such as name, description, duration, and gifUrl.Update the Exercise data class to include a gifUrl parameter
Step 3: Workout Activity
Create a WorkoutActivity class that extends AppCompatActivity.Set up the necessary UI components in the workout activity layout file. Initialize the UI components and Glide in the WorkoutActivity class. Load and display the GIF images using Glide in the startNextExercise() method.
Step 4: Design the UI
activity_workout.xml
Step 5: Exercise Tracking and Timer
Implement exercise tracking using a list of Exercise objects inside startNextExercise() function. Display the exercise details and timer in the UI.Set up a countdown timer for each exercise. Update the UI and load the next exercise when the timer finishes.
Step 6: Implement formatTime function
The formatTime function is a utility function that takes a duration in seconds and formats it into a string representation of minutes and seconds.