![]() |
VOOZH | about |
A Shayari app built in Android Studio consists of various Shayaries and categories of it using Firebase for database purposes, also you can add as many Shayaries and categories of it, indirectly to the firebases the user can access and also have share functionality on WhatsApp as well. A sample video is given below to get an idea about what we are going to do in this article.
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Note: Select Kotlin as the programming language.
Step 2: Set up the development environment
Add View binding inside the android{} block in build.gradle(app) file
buildFeatures {
viewBinding = true
}Here is what the build.gradle(module: app) should look like
Step 3: Create a new Firebase Project
Add Firebase Firestore dependency in build.gradle(app) file
You can also refer this article if you prefer using GUI. Adding Firebase to Android Application.
implementation("com.google.firebase:firebase-firestore:25.1.0")
implementation("com.google.firebase:firebase-firestore-ktx:25.1.0")Dont forget to activate Firebase Firestore inside the Firebase Console!
Step 4: Adding resources
We will be adding some colors inside the application. Head to app > res > values > colors.xml.
Write the following code in it:
We will also be needing some icon images inside our Application
You can find all the resources here: Resources
Refer this article to add images inside your project: How to add Images in the Android Project.
Step 5: Design the app’s user interface
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
This activity is to display the number of Categories of Shayaries available inside the Firestore database. It will display all the categories which users can select and see All the Shayaries inside that category.
activity_start.xml
This is the launch activity of our Application. It will have a Start button which will lead to Main Activity, a Rating button one "More" Button.
activity_all_shayari.xml
After Selecting a particular Category from MainActivity, this activity will be shown which will contain all the shayaries of that particular category!
All these shayaries will be stored inside the Firestore database.
item_category.xml
This is the layout for the recycler view inside activity_main.xml. It has a TextView which will contain a category name.
item_shayari.xml
This is the layout for displaying Shayaries inside all_shayari_activity.xml. This layout contains A TextView to show Shayaries, a share icon, a copy icon and a whatsapp icon.
Step 5: Creating Adapters for the two Recycler Views
Adapters in RecyclerViews is a class which binds data with the layout inside the UI. The adapter acts as a bridge between the data source (such as a list or an array) and the RecyclerView's UI elements.
AllShayariAdapter.kt
Step 6: Create a Model for Shayari
Data model classes are crucial as they give a proper structured data to RecyclerView Adapters and Firebase Firestore operations so that databinding and Database operations become easier
Step 7: Finally Write code in Activities
AllShayariActivity.kt
In this activity, we will be retrieving all the shayaries in a particular category that is provided to us through an Intent when a user selects a category from MainActivity.kt. This activity will handle displaying, sharing and copying of shayari.
MainActivity.kt
This activity will retrieve all the categories from Firestore and display it. Users can click on any category to see all the shayaries of that category.
StartActivity.kt
Don't forget to populate your Database before testing!
Click Here to Access the Full Code for the Application