0% found this document useful (0 votes)
16 views48 pages

Document From Manishkumar

The document describes an Android app called Pi Chat that uses artificial intelligence to have natural conversations. It was built using Android Studio and is based on OpenAI's GPT-3.5 model. The app allows customization of conversations and saving of favorites.

Uploaded by

Manish Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views48 pages

Document From Manishkumar

The document describes an Android app called Pi Chat that uses artificial intelligence to have natural conversations. It was built using Android Studio and is based on OpenAI's GPT-3.5 model. The app allows customization of conversations and saving of favorites.

Uploaded by

Manish Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

H. J.

THIM TRUST'S
THEEM COLLEGE OF ENGINEERING

A
CAPSTONE PROJECT
REPORT ON
“CHATGPT APP CLONE USING ANDROID
DEVELOPMENT”
PROJECT WORK SUBMITTED IN PARTIAL FULFILLMENT
OF
THE REQUIREMENTS FOR THE AWARD OF DIPLOMA.
SUBMITTED BY

Mr. ANIS KHAN


Mr. MANISH KUMAR
Mr. HIMANSHU SATOTE
Mr. MOHAMMAD MEMON

UNDER THE GUIDANCE OF


PROF. SARIKA PATIL

DEPARTMENT OF COMPUTER ENGINEERING


MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION
ACADEMIC YEAR (2023-2024)
DEPARTMENT OF COMPUTER ENGINEERING

THEEM COLLEGE OF ENGINEERING (1635)


Boisar – Chillar Road, Boisar (E), 401501

Certificate
This is to certify that the report has been submitted by following students

1.Anis khan 2216350122


2.Manish Kumar 2216350120
3.Himanshu Satote 2216350103
4.Mohammad Memon 2116350092

This project work has been completed by Final Year Students Of course Computer
Department having title Health Care Management System during the academic year
2023-2024. This project was completed in a group consisting of four people under the
guidance of the Faculty Guide.

Signature of signature of signature of

Faculty Guide HOD Principal


(Prof. Sarika Patil) (Prof. Mrunali Kokate) (Dr. Sayyad Layak)

Name & Signature of External Examiner


DECLARATION

We declare that this written submission represents our ideas in our own words
and where others’ ideas or words have been included. We have adequately cited
and referenced the original sources. We also declared that we adhered to all
principals of academics honestly and integrity have not misrepresented or
fabricated or falsified any idea/data/fact sources in our submission. We
understand that any violation of the above will be cause for disciplinary action by
the institute and can also evoke penal action from the source which has thus not
been properly cited from whom proper permission has not been taken when
needed.

1.ANIS KHAN
2.MANISH KUMAR
3.HIMANSHU SATOTE
4.MOHAMMAD MEMON
ACKNOWLEDGEMENT

The success and final outcome of this project required a lot of guidance
and assistance from many people, and we are extremely privileged to have all this
along the completion of our project. All that we have accomplished is only due to
such supervision and assistance and we would not forget to thank them.

We owe our deep gratitude to our project guide Prof. Sarika Patil who
took keen interest in our project work and guided us all along, till the completion
of our project by providing all the necessary information for developing a good
system.

We respect and thank Prof. Mrunali Kokate, Project Coordinator and


Prof. Mrunali Kokate, HOD, Computer Engineering, for providing us an
opportunity to do the project work on CHATGPT APP CLONE USING
ANDROID DEVELOPMENT and giving us all support and guidance, which
made us complete the project duly. We are extremely thankful to him for
providing such guidance support and guidance, although he had a busy schedule
managing the corporate affairs.

We would not forget to remember Dr. Sayyad Layak, Principal, Theem


College of Engineering(1635). Boisar, for his encouragement and more over for
his timely support and guidance till the completion of our project work.

We are thankful that we are fortunate enough to get constant


encouragement, support and guidance from all teaching staffs which helped us in
successfully completing our project work. Also, we would like to extend our
sincere esteems to all staff in laboratory for their timely support.

___________
ANIS KHAN

______________
MANISH KUMAR

_________________
HIMANSHU SATOTE

_________________
MOHAMMAD MEMON
TABLE OF CONTENTS

SR.NO TITLE
1. ABSTRACT
INTRODUCTION
2. SYSTEM INTRODUCTION
3. TOOLS INTRODUCTION
4. TECHNOLOGY INTRODUCTION
MODULES
5. ANDROID APP MODULE
6. FEATURE MODULE
7. LIBRARY MODULE
ABOUT THE PROJECT
8. PROBLEM STATEMENT
9. ABOUT PROJECT
10. SYATEM FEATURE
SYSTEM IMPLEMENTATAION
11. SETUP PROCESS
12. HOW TO INSTALL
13. PROJECT STRUCTURE SETTINGS
SOURCE CODE
14. CODE
CONCLUSION
ABSTRACT

The Pi Chat app is an innovative Android application designed to provide users with a
personalized conversational experience. Built on the GPT-3.5 architecture, a large language
model trained by OpenAI, this app is capable of understanding natural language input and
generating contextually relevant and engaging responses.

The app is highly user-friendly and can be easily customized to suit individual preferences.
Users have the option to choose from a variety of conversational styles and themes, allowing
them to personalize the app according to their liking. Additionally, the app includes a feature
that enables users to save their favourite conversations for future reference, making it
convenient to revisit and continue discussions.

With an intuitive and clean interface, the Pi Chat app offers a seamless navigation experience
for users on their Android devices. Overall, the Pi Chat app represents a significant
advancement in artificial intelligence and mobile app development, providing users with a
unique and entertaining conversational experience tailored to their preferences.
INTRODUCTION

What is Android Studio?


Android Studio serves as the official Integrated Development Environment (IDE) specifically
designed for Android app development. It encompasses a wide array of tools and features aimed
at streamlining the development process and enhancing developer productivity. Some key
features of Android Studio include:
Code Analysis: Android Studio provides static code analysis capabilities, which help identify
potential bugs, performance issues, and code inefficiencies.
Code Assistance: The IDE offers intelligent code completion, suggestions, and auto-correction,
making coding faster and more efficient.
Emulator: Android Studio includes a fast and feature-rich emulator for testing apps on different
Android device configurations.
Build System: Android Studio utilizes Gradle as its build system, allowing for flexible project
configurations and dependency management.
Google Cloud Platform Integration: The IDE seamlessly integrates with Google Cloud
Platform services, facilitating backend development and cloud-based features.
GitHub Integration: Android Studio provides built-in support for version control systems like
Git, enabling collaborative development and code management.

What is Pi Chat?
Pi Chat represents an innovative conversational AI model developed by OpenAI, leveraging
advanced machine learning techniques. It is based on the GPT (Generative Pre-trained
Transformer) architecture, which has been trained on vast amounts of text data to understand
and generate natural language responses. Key features of Pi Chat include:
Language Understanding: Pi Chat can comprehend natural language inputs from users, ranging
from simple queries to complex conversations, through its trained language model.
Response Generation: Using its trained model, Pi Chat generates contextually relevant and
human-like responses, ensuring engaging and meaningful interactions.
Contextual Awareness: The AI model of Pi Chat maintains contextual awareness during
conversations, allowing for coherent and relevant dialogue flows.
Customization: Pi Chat can be customized and fine-tuned to cater to specific use cases,
industries, or user preferences, enhancing its adaptability and utility.
TOOLS USED

1. Android Studio
Android Studio is the official Integrated Development Environment (IDE) for android
application development. Android Studio provides more features that enhance our productivity
while building Android apps.

Features of Android Studio:


o It has a flexible Gradle-based build system.
o It has a fast and feature-rich emulator for app testing
o Android Studio has a consolidated environment where we can develop for all Android
devices
o Apply changes to the resource code of out running app without restarting the app
o It provides build in supports for Google Cloud Platform. It makes it easy to Into Google
Cloud Messaging and App Engine

Android Studio Project Structure


The Android Studio Project Contains one or more modules with resource files and source code
files. These include different types of modules-
 Android app modules
 Library modules
 Google App Engine modules
These build files are visible to the top-level under Gradle Scripts. And the app module contains
the following folders

 manifests: It contains the AndroidManifest.xml file


 java: It contains the source code of Java files, including the JUnit test code
 res: It contains all non-code resources, UI strings, XML layouts, and bitmap images

Gradle build system


Gradle build used as the foundation of the build system m Android Studio. It uses more
Android-specific capabilities provided by the Android plugin for Gradle Thus build system
runs independently from the command line and integrated tool from the Android Studio menu.
We can use build features for the following purpose
o Configure customise, and extend the build process
o We can create multiple APKs from our app, with different features using the same
project and modules
o Reuse resource and code across source sets

2. GOOGLE SERVICES

 Google Sign in Integration Services


 Google API Services

Google Sign-in Integration Services

To integrate Google sign-in functionality into your ChatGPT clone application for Android
development, you can use Google Sign in for Android, which is a library provided by Google
that makes it easy to integrate Google sign in functionality into your Android app

Here are the steps you can follow:

Step1: Create a new project in the Firebase console, if you haven't already. Follow the
instructions provided by Firebase to set up your project.

Step2: Add the Firebase Android configuration file to your app. You can do this by following
the instructions provided by Firebase

Step3: Add the Google Play services library to your app. You can do this by adding the
following dependency to your app's build. Gradle file

Step4: Create a GoogleApiClient object in your app's on Create () method

Step5: Add a Google sign-in button to your app's layout file


Step6: In your app's on Create () method, at an OnClickListener for the spin button

Step7: Implement the OnClickListener interface in your activity

Step8: In on the Click () method, start the sign in Bow

Step9: Handle the result of the sign-inflow in the Activity Rault) method

Step10: Finally, implement the handlesigninResult () method to handle the result of the sign-
in flow

GOOGLE API SERVICES

To use Google APIs in your ChatGPT clone application for Android development, you need to
follow the following steps:

Step1: Go to the Google Cloud Console and create a new project

Step2: Enable the APIs that you want to your project. To do this, go to Be API & Services"
section of the console, and chick on "Larry in the left sidebar Them. such for the API that you
want to me (e.g. Google Maps, Google Translate, etc.) and enable it for your project.

Step3: Create an API key for your port to do this, go to the "Ale & Servies action of the console,
and click on "Credentials in the left sidebar. Then click on the "Crate credentials button and
west "API key You can choose between unrestricted or restricted API key. A restricted API key
let you at the age of the APT key to specify applications or websites, while an unrestricted API
key can be man by any application or website

step4: Add the API key to your Chatigit clone application. To do this, add the following code
to your AndroidManifest.xml file

Step5: le the Google API were in your ChatGPT clone application You can save the Apls in
your application by calling the appropriate API cathode is your male. Put example, if you want
to use the Google Maps API to display a map in your application you can add a Map View and
then the Google Map lever to add markers, polylines, etc. to the map

Here are a few examples of how to use some common Google APIs in your ChatGPT clone
application:

Google Maps API: Use the Map View to display a map in your application. You can then use
the Google Map object to add markers, polylines, etc. to the map
Google Places API: Use the AutocompleteTextView to provide autocomplete suggestions for
places as the user types. You can also use the Places API to Search for places based on a user's
location or a search query

Google Translate API: Use the Translate API to translate text from one language to another

Google Cloud Vision API: Use the Vision API to analyze images and detect objects, faces,
text, and other features.

3. Open Al API Services

1. GPT-3 API: This API provides access to OpenAI's flagship language model, GPT-3. It can
generate natural language text, translate languages, answer questions, and more

2. DALLE API: This API allows users to generate images from natural language descriptions.
It is based on Open Al’s DALLE model, which can create a wide range of images

3. Codes API: This API provides a natural language interface to Open Al’s GPT 3 model for
coding related tasks. It can assist with coding, debugging, and even generate code from plain
English descriptions

4. CLIP API: This API is based on Open Al’s Contrastive Language-Image Pretraining (CLIP)
model, which can understand the relationship between images and language It can be used for
tasks like image search and classification

5. Open Al API: This API provides access to several other OpenAl models, including GPT-2
and the image captioning model
MODULES
A module is a collection of source files and build settings that let you divide your project into
discrete units of functionality Your project can have one or many modules, and one module can
use another module as a dependency. You can independently build, test, and debug each module

Android Studio offers a few distinct types of modules

Android app module

Provides a container for your app's sources code, resource files, and app-level settings. such as
the module-level build file and Android Manifest file. When you create a new project, the
default app module is named "app"

In the Create New Module window, Android Studio offers the following types of app modules

 Phone & Tablet Module


 Automotive Module
 Wear OS Module
 Android TV Module
 Benchmark Module

Feature module

Represents a modularized feature of your app that can take advantage of Flay Feature Delivery
For example with feature modules, you can provide your users with certain features of your
app on demand or as instant experiences through Google Play Instant

Android Studio offers the following types of feature modules

 Dynamic Feature Module: - Dynamic feature modules allow you to separate certain
features and resources from the base module of your app and include them in your app
bundle. Through Dynamic Delivery, users can later download and install those
components on demand after they've already installed the base APK of your app.

 Instant Dynamic Feature Library Module: - Dynamic Feature Modules (DFMs) in


Android development are a powerful tool for modularising your app, reducing size, and
enabling on-demand delivery.
Library module
Provides a container for your reusable code, which you can use as a dependency in other app
modules or import into other projects. Structurally, a library module in the same as an app
module, but when built, it creates a code archive file instead of an APK so it can't be installed
on a device.

Android Studio offers the following type of library modules:

Android Library: This type of library can contain all file types supported in an Android
project except native C++ code, including Java and Kotlin source code, resources, and manifest
files. The build result is an Android Archive (AAR) file that you can add as a dependency for
your Android app modules

Android Native Library: This type of library can contain all Be types supported in an Android
project similar to an Android Library However Android Native Libraries also can contain
native C++ sourer code The build result is an Android Archive (AAR) file that you can add as
a dependency for your Android app modules

Java or Kotlin Library: This type of library contains only Kotlin or Java source files. The
build result is a Java Archive (JAR) file that you can add as a dependency for your Android
app modules or other Kotlin or Java projects
ABOUT THE PROJECT

The Pi Chat app project aims to create an intuitive and interactive conversational AI platform
for Android devices. Key components and aspects of the project include:
o User Interface Design: Designing a user-friendly and visually appealing interface for
the Pi Chat app, including chat bubbles, input fields, multimedia support, and
interactive elements.

o Messaging Platform Integration: Integrating Pi Chat with popular messaging


platforms such as Facebook Messenger, Slack, or Telegram, enabling seamless user
interactions across multiple channels.

o Natural Language Processing (NLP): Leveraging advanced NLP techniques to


preprocess user inputs, extract intents and entities, and enhance the understanding and
accuracy of Pi Chat's responses.

o Machine Learning and Training: Training the Pi Chat model on diverse datasets to
improve language understanding, response generation, context retention, and
conversational capabilities.

o Deployment and Distribution: Deploying the Pi Chat app on Google Play Store or
other distribution platforms, ensuring scalability, performance optimization, and
continuous updates.

o User Feedback and Iteration: Collecting user feedback, analysing usage patterns, and
iterating on the app's features, functionalities, and AI model to enhance user satisfaction
and engagement.

o Security and Privacy: Implementing robust security measures, encryption standards,


data anonymization, and privacy policies to protect user data and ensure compliance
with regulatory requirements
PROBLEM STATEMENT

The Pi Chat project addresses several challenges and objectives related to conversational AI
and mobile app development:

 Conversational Experience: Creating an engaging, natural, and context-aware


conversational experience for users, simulating human-like interactions and responses.

 Language Understanding: Ensuring accurate comprehension of user inputs, intents,


sentiments, and contextual nuances to generate relevant and meaningful responses.

 Response Generation: Generating coherent, contextually relevant, and grammatically


correct responses using machine learning models and language generation techniques.

 Personalization and Customization: Allowing users to personalize their chat


experience, customize preferences, set conversational styles, and access tailored
content.

 Multi-Platform Support: Supporting cross-platform compatibility and integration


with messaging platforms, web interfaces, or IoT devices for seamless user interactions.

 Scalability and Performance: Optimizing the app's performance, scalability, and


resource utilization, particularly in handling concurrent user interactions, large datasets,
and real-time responses.

 Ethical AI: Addressing ethical considerations, bias mitigation, fairness, transparency,


and responsible AI practices in designing and deploying conversational AI solutions.
SYSTEM FEATURES

Key features of the Pi Chat app system include:

User Authentication: Secure user authentication mechanisms to control access to the


chatbot.

Messaging Platform Integration: Seamless integration with messaging platforms for


user interactions.

Natural Language Processing (NLP): Advanced NLP capabilities for language


understanding and response generation.

Machine Learning and Training: Training the Pi Chat model for improved
conversational capabilities and response quality.

Analytics and Reporting: Analytics tools to monitor usage, performance, and user
interactions.

Security and Privacy: Implementation of robust security measures and adherence to


privacy regulations.

Continuous Development: Continuous refinement, updates, and feature


enhancements based on user feedback and technological advancements.
SYSTEM IMPLEMENTATION

The implementation process for the Pi Chat app project encompasses various stages,
methodologies, and best practices:
 Requirements Elicitation and Analysis: Conducting stakeholder interviews, user
surveys, market research, and requirements gathering sessions to define project
objectives, scope, functionalities, and user stories.
 Architecture and Design: Designing system architecture, data models, UI/UX
wireframes, interaction flows, component diagrams, and API integrations based on
identified requirements and design principles.
 Development and Coding: Writing clean, modular, and scalable code using best
practices, coding standards, design patterns, and version control systems. Implementing
features, functionalities, algorithms, and AI models as per specifications.
 Testing and Quality Assurance: Performing rigorous testing, including unit testing,
integration testing, regression testing, usability testing, and AI model evaluation.
Identifying bugs, issues, edge cases, and performance bottlenecks for resolution.
 Deployment and Release: Deploying the Pi Chat app on staging environments, beta
testing groups, production servers, or app stores. Managing deployment pipelines,
configuration settings, release cycles, and version updates.
 User Training and Onboarding: Providing user guides, tutorials, help documentation,
tooltips, and onboarding experiences to educate users, familiarize them with app
features, and enhance user adoption.
 Monitoring and Maintenance: Monitoring app performance, user feedback, crash
reports, analytics data, and system logs. Conducting regular maintenance, bug fixes,
security patches, and updates to ensure app reliability, availability, and security.
This comprehensive approach ensures the successful development, deployment, and
ongoing enhancement of the Pi Chat app, providing users with an immersive,
intelligent, and interactive conversational AI platform on Android devices.
How To Install Android Studio:
Step 1: Go To the Official Website of the Android Studio
Step 2: Click on the Download Android Studio Button
Click on the "I have read and agree with the above terms and conditions" checkbox followed
by the download button.
Click on the Save file button in the appeared prompt box and the file will start downloading.
Step 3: After the downloading has finished, open the file from downloads and run it. It will
prompt the following dialog box.
Click on next. In the next prompt, it'll ask for a path for installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the image shown
below.
Click on next.
Step 5: Once "Finish" is clicked, it will ask whether the previous settings need to be imported
[if the android studio had been installed earlier], or not. It is better to choose the 'Don't import
Settings option
Step 6: Once "Finish" is clicked, it will ask whether the previous settings need to be imported
[if the android studio had been installed earlier), or not. It is better to choose the Don't import
Settings option
Meanwhile, it will be finding the available SDK components.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box
Click on Next
Choose Standard and click on Next. Now choose the theme, whether the Light theme or the
Dark one. The light one is called the IntelliJ theme whereas the dark theme is called Dracula
Choose as required.
Click on the Next button.
Step 8: Now it is time to download the SDK components
Click on Finish Components begin to download let it complete
The Android Studio has been successfully configured. Now it's time to launch and build apps.
Chek on the Finish button to launch it
Step 9: Click on Start a new Android Studio project to build a new app
Project structure settings
To change various settings for your Android Studio project, open the Project Structure dialog
by clicking File > Project Structure. It contains the following sections:

Project: Sets the version for Gradle and the Android Gradle plugin and the repository location
name.
SDK Location: Sets the location of the JDK, Android SDK, and Android NDK that your
project uses.
Variables: Lets you edit variables that are used within your build scripts.
Modules: Lets you edit module-specific build configurations, including the target and
minimum SDK, the app signature, and library dependencies. Each module's settings page is
divided into the following tabs:
Properties: Specifies the versions of the SDK and build tools to use to compile the module.
Signing: Specifies the certificate to use to sign your app.
Dependencies: Lists the library, file, and module dependencies for this module. You can add,
modify, and delete dependencies from this pane. For more information about module
dependencies, see Configure build variants.
Preview: If you're using a version catalog, be aware of the issue that dependencies added
through the Project Structure dialog are added to the module's build. Gradle file, not the
catalog. To learn more about Gradle Version Catalogs support in Android Studio, see
the preview release note.

Build Variants: Lets you configure different flavors and build types for your project.
Flavors: Lets you create multiple build flavors, where each flavor specifies a set of
configuration settings, such as the module's minimum and target SDK version and the version
code and version name.
For example, you might define one flavor that has a minimum SDK of 21 and a target SDK of
29, and another flavor that has a minimum SDK of 24 and a target SDK of 33.
Build Types: Lets you create and modify build configurations, as described in Configure build
variants. By default, every module has debug and release build types, and you can define more
as needed.
SOURCE CODE

MAIN ACTIVITY

package com.infiapp.webapp

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Configuration
import android.os.*
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.ImageView
import android.widget.Switch
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.navigation.ui.AppBarConfiguration
import com.google.android.gms.ads.*
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
import com.google.android.material.navigation.NavigationView
import com.infiapp.webapp.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity(),


NavigationView.OnNavigationItemSelectedListener {
private lateinit var binding: ActivityMainBinding
private lateinit var appBarConfiguration: AppBarConfiguration
var mDrawerToggle: ActionBarDrawerToggle? = null
private lateinit var dialog: Dialog
var timer:CountDownTimer? = null
private var mInterstitialAd: InterstitialAd? = null
private var counter:Int=0
private var sharedPreferences:SharedPreferences?=null

private var view1: View? = null


private var view2:View? = null
private var view3:View? = null
private var view4:View? = null
private var view5:View? = null
private var view6:View? = null
private var view7:View? = null
private var view8:View? = null
private var view9:View? = null
private var view10:View? = null
private var view11:View? = null
private var view12:View? = null
private var view13:View? = null
private var view14:View? = null
private var view15:View? = null
private var view16:View? = null
private var view17:View? = null
private var view18:View? = null
private var view19:View? = null
private var view20:View? = null
private var img1: ImageView? = null
private var img2:ImageView? = null
private var img3:ImageView? = null
private var img4:ImageView? = null
private var img5:ImageView? = null
private var img6:ImageView? = null
private var img7:ImageView? = null
private var img8:ImageView? = null
private var img9:ImageView? = null
private var img10:ImageView? = null
private var img11:ImageView? = null
private var img12:ImageView? = null
private var img13:ImageView? = null
private var img14:ImageView? = null
private var img15:ImageView? = null
private var img16:ImageView? = null
private var img17:ImageView? = null
private var img18:ImageView? = null
private var img19:ImageView? = null
private var img20:ImageView? = null
private var shared: Shared? = null
private var mContext: Context? = null

@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("ResourceType")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.hide()

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

loadBannerAd()

loadInterAd()
binding.textview.text = "Home"

val menuItem: MenuItem = binding.navView.menu.findItem(R.id.nav_darkmode) //


This is the menu item that contains your switch
val drawerSwitch = menuItem.actionView.findViewById<View>(R.id.drawer_switch)
as Switch
val sharedPreferences = getSharedPreferences("sharedPrefs", MODE_PRIVATE)
val editor = sharedPreferences.edit()

mContext = this
shared = Shared(this)

val nightModeFlags: Int = shared!!.getDarkTheme()

Log.e("111111", "onCreate: "+nightModeFlags

val LIGHT_MODE = "LightMode"


val NIGHT_MODE = "NightMode"

drawerSwitch.setOnCheckedChangeListener { _, isChecked ->

if (isChecked) {

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
editor.putBoolean(LIGHT_MODE, false)
editor.putBoolean(NIGHT_MODE, true)
editor.apply()
//recreate activity to make changes visible

} else {

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
editor.putBoolean(LIGHT_MODE, true)
editor.putBoolean(NIGHT_MODE, false)
editor.apply()
}
Log.e("1111", "onCreate: "+isChecked )
}

reference()
binding.navView.setNavigationItemSelectedListener(this)

binding.webView.webViewClient = MyWebViewClient(this)
binding.webView.loadUrl(resources.getString(R.string.main_url))
binding.webView.settings.javaScriptEnabled = true

binding.navigation.setOnClickListener {
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
binding.drawerLayout.closeDrawer(GravityCompat.START)
} else {
binding.drawerLayout.openDrawer(GravityCompat.START)
}
}
binding.search.setOnClickListener {
binding.webView.webViewClient = MyWebViewClient(this)
binding.webView.loadUrl(resources.getString(R.string.home_url))
}
}

private fun loadBannerAd() {


MobileAds.initialize(this) {}

val adRequest = AdRequest.Builder().build()

binding.adView.loadAd(adRequest)

binding.adView.adListener = object: AdListener() {


override fun onAdClicked() {
}

override fun onAdClosed() {

override fun onAdFailedToLoad(adError : LoadAdError


}

override fun onAdImpression() {


}

override fun onAdLoaded() {

override fun onAdOpened() {


}
}
}
open fun setupDrawerToggle() {
val toggle = ActionBarDrawerToggle(this, binding.drawerLayout,
R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
binding.drawerLayout.addDrawerListener(toggle)
toggle.syncState()
}

@RequiresApi(Build.VERSION_CODES.M)
override fun onNavigationItemSelected(item: MenuItem): Boolean {

when (item.getItemId()) {
R.id.nav_home -> {

showInterAd(this)
binding.textview.setText(resources.getString(R.string.menu_home))
binding.webView.visibility=View.VISIBLE
binding.aboutUsText.visibility=View.GONE
binding.colorLinear.visibility=View.GONE
binding.webView.webViewClient = MyWebViewClient(this)
binding.webView.loadUrl(resources.getString(R.string.home_url))
}
R.id.nav_message -> {

showInterAd(this)
binding.textview.setText(resources.getString(R.string.menu_message))
binding.webView.visibility=View.VISIBLE
binding.aboutUsText.visibility=View.GONE
binding.colorLinear.visibility=View.GONE
binding.webView.webViewClient = MyWebViewClient(this)
binding.webView.loadUrl(resources.getString(R.string.message_url))
}
R.id.nav_filter -> {

showInterAd(this)
binding.textview.setText(resources.getString(R.string.menu_filter))
binding.webView.visibility=View.VISIBLE
binding.aboutUsText.visibility=View.GONE
binding.colorLinear.visibility=View.GONE
binding.webView.webViewClient = MyWebViewClient(this)
binding.webView.loadUrl(resources.getString(R.string.filter_url))
}
R.id.nav_changecolor -> {
val sharedPreferences = getSharedPreferences("sharedPrefs", MODE_PRIVATE)
val isDarkModeOn = sharedPreferences.getBoolean("isDarkModeOn", false)
if (isDarkModeOn) {

val builder = AlertDialog.Builder(this,R.style.CustomAlertDialog)


.create()
val view = layoutInflater.inflate(R.layout.alert_dialog,null)
val button = view.findViewById<Button>(R.id.dialogDismiss_button)
builder.setView(view)
button.setOnClickListener {
builder.dismiss()
}
builder.setCanceledOnTouchOutside(false)
builder.show()
} else {
showInterAd(this)

binding.textview.setText(resources.getString(R.string.menu_change_theme_color))
binding.webView.visibility=View.GONE
binding.aboutUsText.visibility=View.GONE
binding.colorLinear.visibility=View.VISIBLE
binding.search.visibility=View.VISIBLE
binding.search.setImageDrawable(getDrawable(R.drawable.check_24))
binding.search.setOnClickListener {
reference()
onClick()
val intent = Intent(applicationContext, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
startActivity(intent)
}
}
}
R.id.nav_darkmode->{
}
R.id.nav_aboutus-> {
showInterAd(this)
binding.textview.setText(resources.getString(R.string.menu_about_us))
binding.aboutUsText.visibility=View.VISIBLE
binding.webView.visibility=View.GONE
binding.search.visibility=View.GONE
binding.colorLinear.visibility=View.GONE
}
R.id.nav_exit-> {
backPress()
}
}
binding.drawerLayout.closeDrawer(GravityCompat.START)
return true
}
private fun reference() {
view1 = findViewById<View>(R.id.view1)
view2 = findViewById<View>(R.id.view2)
view3 = findViewById<View>(R.id.view3)
view4 = findViewById<View>(R.id.view4)
view5 = findViewById<View>(R.id.view5)
view6 = findViewById<View>(R.id.view6)
view7 = findViewById<View>(R.id.view7)
view8 = findViewById<View>(R.id.view8)
view9 = findViewById<View>(R.id.view9)
view10 = findViewById<View>(R.id.view10)
view11 = findViewById<View>(R.id.view11)
view12 = findViewById<View>(R.id.view12)
view13 = findViewById<View>(R.id.view13)
view14 = findViewById<View>(R.id.view14)
view15 = findViewById<View>(R.id.view15)
view16 = findViewById<View>(R.id.view16)
view17 = findViewById<View>(R.id.view17)
view18 = findViewById<View>(R.id.view18)
view19 = findViewById<View>(R.id.view19)
view20 = findViewById<View>(R.id.view20)

img1 = findViewById<View>(R.id.img1) as ImageView


img2 = findViewById<View>(R.id.img2) as ImageView
img3 = findViewById<View>(R.id.img3) as ImageView
img4 = findViewById<View>(R.id.img4) as ImageView
img5 = findViewById<View>(R.id.img5) as ImageView
img6 = findViewById<View>(R.id.img6) as ImageView
img7 = findViewById<View>(R.id.img7) as ImageView
img8 = findViewById<View>(R.id.img8) as ImageView
img9 = findViewById<View>(R.id.img9) as ImageView
img10 = findViewById<View>(R.id.img10) as ImageView
img11 = findViewById<View>(R.id.img11) as ImageView
img12 = findViewById<View>(R.id.img12) as ImageView
img13 = findViewById<View>(R.id.img13) as ImageView
img14 = findViewById<View>(R.id.img14) as ImageView
img15 = findViewById<View>(R.id.img15) as ImageView
img16 = findViewById<View>(R.id.img16) as ImageView
img17 = findViewById<View>(R.id.img17) as ImageView
img18 = findViewById<View>(R.id.img18) as ImageView
img19 = findViewById<View>(R.id.img19) as ImageView
img20 = findViewById<View>(R.id.img20) as ImageView

img1!!.visibility = View.VISIBLE
init()

val sharedPreferences = getSharedPreferences("sharedPrefs", MODE_PRIVATE)


val isDarkModeOn = sharedPreferences.getBoolean("isDarkModeOn", false)
if (!isDarkModeOn)
setActionBar()

}
private fun init() {
if(shared!!.getSetThemeColor().contentEquals("BG")) {
setTickBG()
} else if (shared!!.getSetThemeColor().contentEquals("TEAL")) {
setTickTEAL()
} else if (shared!!.getSetThemeColor().contentEquals("BLUE")) {
setTickBLUE()
} else if (shared!!.getSetThemeColor().contentEquals("DEEP_ORANGE")) {
setDeeporange() }
else if (shared!!.getSetThemeColor().contentEquals("YELLOW")) {
setTickYellow() }
else if (shared!!.getSetThemeColor().contentEquals("INDIGO")) {
setTickINDiGO() }
else if (shared!!.getSetThemeColor().contentEquals("GREEN")) {
setTickGreen() }
else if (shared!!.getSetThemeColor().contentEquals("ORANGE")) {
setTickOrange()
} else if (shared!!.getSetThemeColor().contentEquals("CYN")) {
setTickCyn()
} else if (shared!!.getSetThemeColor().contentEquals("PINK")) {
setTickPink()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR2")) {
setTickColor2()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR3")) {
setTickColor3()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR4")) {
setTickColor4()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR5")) {
setTickColor5()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR6")) {
setTickColor6()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR7")) {
setTickColor7()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR8")) {
setTickColor8()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR9")) {
setTickColor9()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR10")) {
setTickColor10()
} else if (shared!!.getSetThemeColor().contentEquals("COLOR11")) {
setTickColor11()}
}
private fun setTickBG() {
img1!!.visibility = View.VISIBLE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickTEAL() {
img1!!.visibility = View.GONE
img2!!.visibility = View.VISIBLE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickBLUE() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.VISIBLE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setDeeporange() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.VISIBLE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickGreen() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.VISIBLE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickYellow() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.VISIBLE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickINDiGO() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.VISIBLE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickOrange() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.VISIBLE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickCyn() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.VISIBLE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickPink() {
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.VISIBLE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor2(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.VISIBLE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor3(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.VISIBLE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor4(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.VISIBLE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor5(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.VISIBLE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor6(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.VISIBLE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor7(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.VISIBLE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor8(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.VISIBLE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor9(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.VISIBLE
img19!!.visibility = View.GONE
img20!!.visibility = View.GONE
}
private fun setTickColor10(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.VISIBLE
img20!!.visibility = View.GONE
}
private fun setTickColor11(){
img1!!.visibility = View.GONE
img2!!.visibility = View.GONE
img3!!.visibility = View.GONE
img4!!.visibility = View.GONE
img5!!.visibility = View.GONE
img6!!.visibility = View.GONE
img7!!.visibility = View.GONE
img8!!.visibility = View.GONE
img9!!.visibility = View.GONE
img10!!.visibility = View.GONE
img11!!.visibility = View.GONE
img12!!.visibility = View.GONE
img13!!.visibility = View.GONE
img14!!.visibility = View.GONE
img15!!.visibility = View.GONE
img16!!.visibility = View.GONE
img17!!.visibility = View.GONE
img18!!.visibility = View.GONE
img19!!.visibility = View.GONE
img20!!.visibility = View.VISIBLE

private fun setActionBar() {


if (shared!!.getSetThemeColor().contentEquals("BG")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
1))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R1))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK1)
}
} else if (shared!!.getSetThemeColor().contentEquals("TEAL")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.TEAl))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.TEAl))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_TEAL) } }
else if (shared!!.getSetThemeColor().contentEquals("BLUE")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.BLUE))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.BLUE
))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_BLUE) }
}
else if (shared!!.getSetThemeColor().contentEquals("DEEP_ORANGE")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.ORANG
E))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.ORAN
GE))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_DEEP_ORANGE)
}
} else if (shared!!.getSetThemeColor().contentEquals("YELLOW")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.yellow))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.yellow
))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor = ContextCompat.getColor(mContext!!,R.color.yellow)
}
} else if (shared!!.getSetThemeColor().contentEquals("INDIGO")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.INDIG
O))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.INDI
GO))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor = ContextCompat.getColor(mContext!!,R.color.INDIGO)
}
} else if (shared!!.getSetThemeColor().contentEquals("GREEN")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.GREEN
))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.GREE
N))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor = ContextCompat.getColor(mContext!!,R.color.GREEN)
}
} else if (shared!!.getSetThemeColor().contentEquals("ORANGE")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.ORANG
E))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.ORAN
GE))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_ORANGE)
}
} else if (shared!!.getSetThemeColor().contentEquals("CYN")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.CYN))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.CYN))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_CYN)
}
} else if (shared!!.getSetThemeColor().contentEquals("PINK")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.PINK))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.PINK)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.DARK_PINK)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR2")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
2))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R2))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK2)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR3")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
3))
binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R3))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK3)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR4")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
4))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R4))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK4)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR5")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
5))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R5))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK5)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR6")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
6))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R6))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK6)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR7")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
7))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R7))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK7)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR8")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
8))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R8))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK8)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR9")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
9))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R9))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK9)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR10")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
10))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R10))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK10)
}
}
else if (shared!!.getSetThemeColor().contentEquals("COLOR11")) {

binding.toolbar.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLOR
11))

binding.navView.setBackgroundColor(ContextCompat.getColor(mContext!!,R.color.COLO
R11))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor =
ContextCompat.getColor(mContext!!,R.color.COLORDARK11)
}
}
onClick()
}
private fun onClick() {
view1?.setOnClickListener {
view1!!.visibility=View.VISIBLE
shared?.SetThemeColor("BG")
setTickBG()
//setActionBar()

}
view2?.setOnClickListener {
view1!!.visibility=View.VISIBLE
shared?.SetThemeColor("TEAL")
setTickTEAL()
//setActionBar()
}
view3?.setOnClickListener {
view3!!.visibility=View.VISIBLE
shared?.SetThemeColor("BLUE")
setTickBLUE()
//setActionBar()
}
view4?.setOnClickListener {
view4!!.visibility=View.VISIBLE
shared?.SetThemeColor("DEEP_ORANGE")
setDeeporange()
//setActionBar()
}
view5?.setOnClickListener {
view5!!.visibility=View.VISIBLE
shared?.SetThemeColor("GREEN")
setTickGreen()
// setActionBar()
}
view6?.setOnClickListener {
view6!!.visibility=View.VISIBLE
shared?.SetThemeColor("YELLOW")
setTickYellow()
// setActionBar()
}
view7?.setOnClickListener {
view7!!.visibility=View.VISIBLE
shared?.SetThemeColor("INDIGO")
setTickINDiGO()
// setActionBar()
}
view8?.setOnClickListener {
view8!!.visibility=View.VISIBLE
shared?.SetThemeColor("ORANGE")
setTickOrange()
// setActionBar()
}
view9?.setOnClickListener {
view9!!.visibility=View.VISIBLE
shared?.SetThemeColor("CYN")
setTickCyn()
// setActionBar()
}
view10?.setOnClickListener {
view10!!.visibility=View.VISIBLE
shared?.SetThemeColor("PINK")
setTickPink()
// setActionBar()
}
view11?.setOnClickListener {
view11!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR2")
setTickColor2()
// setActionBar()
}
view12?.setOnClickListener {
view12!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR3")
setTickColor3()
// setActionBar()
}
view13?.setOnClickListener {
view13!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR4")
setTickColor4()
// setActionBar()
}
view14?.setOnClickListener {
view14!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR5")
setTickColor5()
// setActionBar()
}
view15?.setOnClickListener {
view15!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR6")
setTickColor6()
// setActionBar()
}
view16?.setOnClickListener {
view16!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR7")
setTickColor7()
// setActionBar()
}
view17?.setOnClickListener {
view17!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR8")
setTickColor8()
// setActionBar()
}
view18?.setOnClickListener {
view18!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR9")
setTickColor9()
// setActionBar()
}
view19?.setOnClickListener {
view19!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR10")
setTickColor10()
// setActionBar()
}
view20?.setOnClickListener {
view20!!.visibility=View.VISIBLE
shared?.SetThemeColor("COLOR11")
setTickColor11()
// setActionBar()
}
}
fun showInterAd(context: Context) {
sharedPreferences = context?.getSharedPreferences("sharedPrefs",
AppCompatActivity.MODE_PRIVATE)
counter = sharedPreferences!!.getInt("count", 0)
counter += 1

val editor: SharedPreferences.Editor = sharedPreferences!!.edit()


editor.putInt("count", counter)
editor.apply()

if (counter == 5) {

editor.putInt("count", 0)
editor.apply()

if (mInterstitialAd != null) {
mInterstitialAd!!.show(this)
mInterstitialAd!!.fullScreenContentCallback = object :
FullScreenContentCallback() {

override fun onAdDismissedFullScreenContent() {


Log.e("111111", "onAdDismissedFullScreenContent: ")
super.onAdDismissedFullScreenContent()
loadInterAd()
}

override fun onAdFailedToShowFullScreenContent(p0: AdError) {


Log.e("111111", "onAdFailedToShowFullScreenContent: ")
super.onAdFailedToShowFullScreenContent(p0)
mInterstitialAd = null
}

override fun onAdImpression() {


Log.e("111111", "onAdImpression: ")
super.onAdImpression()
}

override fun onAdShowedFullScreenContent() {


Log.e("111111", "onAdShowedFullScreenContent: ")
super.onAdShowedFullScreenContent()
}
}

}
else
{
Log.e("111111", "showInterAd: fail")
}
}
}

fun loadInterAd() {

var adRequest = AdRequest.Builder().build()


InterstitialAd.load(this,getString(R.string.interstitial_ad_unit_id), adRequest, object :
InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
mInterstitialAd = null

}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
Log.e("111111", "onAdLoaded: ")
mInterstitialAd = interstitialAd
}
})
}

private fun backPress() {

//custom Alert Dialog


val builder = AlertDialog.Builder(this,R.style.CustomAlertDialog)
.create()
val view = layoutInflater.inflate(R.layout.exit_alert_dialog,null)
val buttonYes = view.findViewById<TextView>(R.id.btn_yes)
val buttonNo=view.findViewById<TextView>(R.id.btn_no)
builder.setView(view)
buttonYes.setOnClickListener {
ActivityCompat.finishAffinity(this)
}
buttonNo.setOnClickListener {
builder.dismiss()
}
builder.setCanceledOnTouchOutside(false)
builder.show()

}
@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("ResourceType")

override fun onBackPressed() {


if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
binding.drawerLayout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}

if (binding.webView!!.canGoBack()) {
binding.webView.goBack()
} else {
super.onBackPressed()
}
}

class MyWebViewClient(mainActivity: MainActivity) : WebViewClient() {


@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldOverrideUrlLoading(
view: WebView?, request: WebResourceRequest?
): Boolean {
val url: String = request?.url.toString();
view?.loadUrl(url)
return false
}

override fun shouldOverrideUrlLoading(webView: WebView, url: String): Boolean {


webView.loadUrl(url)
return true
} }
}
OUTPUT
CONCLUSION

Pi Chat offers similar capabilities to ChatGPT API for building conversational AI


applications. In this project, you can utilize Pi Chat API to construct a chatbot
that comprehends natural language queries and replies in a conversational
manner.

Development involves creating conversational logic, processing user queries,


generating appropriate responses, and maintaining conversational flow.
Techniques like sentiment analysis, entity recognition, and context-awareness are
key. Additionally, integrating machine learning can enhance the chatbot's
performance over time.

To enhance engagement, consider features like multimedia support, external API


integration, and personalized recommendations based on user preferences and
interactions. Incorporating user interface elements such as buttons, carousels, and
quick replies can also improve interactivity.

Thorough testing is crucial to ensure the chatbot meets user requirements.


Techniques like automated testing, user testing, and A/B testing can evaluate
performance and identify areas for enhancement.

In conclusion, building a Pi Chat clone app project offers a rewarding experience


by leveraging AI and natural language processing to create engaging, useful, and
personalized conversational experiences. Ethical considerations should be
paramount, and rigorous testing ensures the chatbot meets expectations and
provides value to users, further advancing AI and natural language processing.

You might also like