diff --git a/app/build.gradle b/app/build.gradle index ce33085..bc9459a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,19 +1,22 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 30 + compileSdkVersion 31 defaultConfig { applicationId "www.sanju.motiontoast" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildFeatures { + viewBinding true + } + buildTypes { release { minifyEnabled false @@ -26,12 +29,12 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.core:core-ktx:1.3.2' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - testImplementation 'junit:junit:4.13.1' - implementation 'com.google.android.material:material:1.2.1' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.2' + testImplementation 'junit:junit:4.13.2' + implementation 'com.google.android.material:material:1.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation project(path: ':motiontoast') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 36d3f47..ab005a6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/www/sanju/motiontoastapp/MainActivity.kt b/app/src/main/java/www/sanju/motiontoastapp/MainActivity.kt index 633e0d2..0843069 100644 --- a/app/src/main/java/www/sanju/motiontoastapp/MainActivity.kt +++ b/app/src/main/java/www/sanju/motiontoastapp/MainActivity.kt @@ -5,31 +5,35 @@ import android.view.View import android.widget.CompoundButton import androidx.appcompat.app.AppCompatActivity import androidx.core.content.res.ResourcesCompat -import kotlinx.android.synthetic.main.activity_main.* import www.sanju.motiontoast.MotionToast import www.sanju.motiontoast.MotionToastStyle +import www.sanju.motiontoastapp.databinding.ActivityMainBinding class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClickListener, CompoundButton.OnCheckedChangeListener { + private lateinit var binding: ActivityMainBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = ActivityMainBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) - switch_custom_colors?.setOnCheckedChangeListener(this) - successBtn.setOnClickListener(this) - errorBtn.setOnClickListener(this) - warningBtn.setOnClickListener(this) - infoBtn.setOnClickListener(this) - deleteBtn.setOnClickListener(this) - noInternetBtn.setOnClickListener(this) + binding.switchCustomColors.setOnCheckedChangeListener(this) + binding.successBtn.setOnClickListener(this) + binding.errorBtn.setOnClickListener(this) + binding.warningBtn.setOnClickListener(this) + binding.infoBtn.setOnClickListener(this) + binding.deleteBtn.setOnClickListener(this) + binding.noInternetBtn.setOnClickListener(this) - successBtn.setOnLongClickListener(this) - errorBtn.setOnLongClickListener(this) - warningBtn.setOnLongClickListener(this) - infoBtn.setOnLongClickListener(this) - deleteBtn.setOnLongClickListener(this) - noInternetBtn.setOnLongClickListener(this) + binding.successBtn.setOnLongClickListener(this) + binding.errorBtn.setOnLongClickListener(this) + binding.warningBtn.setOnLongClickListener(this) + binding.infoBtn.setOnLongClickListener(this) + binding.deleteBtn.setOnLongClickListener(this) + binding.noInternetBtn.setOnLongClickListener(this) } private fun setToastColors(newColorsEnabled: Boolean) { diff --git a/build.gradle b/build.gradle index 523e8ae..e5cdde2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.10' + ext.kotlin_version = '1.6.10' repositories { google() - jcenter() - + mavenCentral() + } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-alpha15' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' @@ -21,8 +21,7 @@ buildscript { allprojects { repositories { google() - jcenter() - + mavenCentral() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94adb76..1709056 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-all.zip diff --git a/motiontoast/build.gradle b/motiontoast/build.gradle index b7eff8b..5785bb4 100644 --- a/motiontoast/build.gradle +++ b/motiontoast/build.gradle @@ -1,19 +1,13 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - - -apply plugin: 'com.github.dcendents.android-maven' -group 'spikeysanju' -version = '1.0' android { - compileSdkVersion 30 - buildToolsVersion "29.0.2" + compileSdkVersion 31 + buildToolsVersion "30.0.3" defaultConfig { minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 1 versionName "1.0" @@ -28,16 +22,20 @@ android { } } + buildFeatures { + viewBinding true + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'androidx.core:core-ktx:1.3.2' - implementation 'com.google.android.material:material:1.2.1' - testImplementation 'junit:junit:4.13.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10" + implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'com.google.android.material:material:1.4.0' + testImplementation 'junit:junit:4.13.2' + implementation 'androidx.constraintlayout:constraintlayout:2.1.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' } diff --git a/motiontoast/src/main/java/www/sanju/motiontoast/MotionToast.kt b/motiontoast/src/main/java/www/sanju/motiontoast/MotionToast.kt index 8d43652..c766d45 100644 --- a/motiontoast/src/main/java/www/sanju/motiontoast/MotionToast.kt +++ b/motiontoast/src/main/java/www/sanju/motiontoast/MotionToast.kt @@ -10,16 +10,16 @@ import android.os.CountDownTimer import android.view.LayoutInflater import android.view.View import android.view.animation.AnimationUtils +import android.widget.ImageView import android.widget.TextView import android.widget.Toast import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat -import kotlinx.android.synthetic.main.full_color_toast.view.* -import kotlinx.android.synthetic.main.motion_toast.view.* +import www.sanju.motiontoast.databinding.FullColorToastBinding +import www.sanju.motiontoast.databinding.MotionToastBinding -@Suppress("DEPRECATION") class MotionToast { companion object { @@ -108,29 +108,27 @@ class MotionToast { font: Typeface? ) { layoutInflater = LayoutInflater.from(context) - val layout = layoutInflater.inflate( - R.layout.motion_toast, - (context).findViewById(R.id.motion_toast_view) - ) + val binding = MotionToastBinding.inflate(layoutInflater) + val layout = binding.root when (style) { // Function for Toast Success MotionToastStyle.SUCCESS -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_check_green ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, successToastColor) ) // Pulse Animation for Icon - startPulseAnimation(context, layout) + startPulseAnimation(context, binding.customToastImage) // Background tint color for side view - layout.colorView.backgroundTintList = + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, successToastColor) // round background color @@ -140,20 +138,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, successToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.SUCCESS.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) // init toast @@ -169,18 +167,18 @@ class MotionToast { } // CTA for Toast Error MotionToastStyle.ERROR -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_error_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, errorToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, errorToastColor) val drawable = @@ -190,20 +188,20 @@ class MotionToast { PorterDuff.Mode.MULTIPLY ) layout.background = drawable - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, errorToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.ERROR.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -215,18 +213,18 @@ class MotionToast { } // CTA for Toast Warning MotionToastStyle.WARNING -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_warning_yellow ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, warningToastColor) setBackgroundAndFilter( @@ -234,20 +232,20 @@ class MotionToast { warningBackgroundToastColor, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.WARNING.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -259,19 +257,19 @@ class MotionToast { } // CTA for Toast Info MotionToastStyle.INFO -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_info_blue ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, infoToastColor) ) - startPulseAnimation(context, layout) + startPulseAnimation(context, binding.customToastImage) - layout.colorView.backgroundTintList = + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, infoToastColor) setBackgroundAndFilter( @@ -279,20 +277,20 @@ class MotionToast { infoBackgroundToastColor, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, infoToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.INFO.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -304,18 +302,18 @@ class MotionToast { } // CTA for Toast Delete MotionToastStyle.DELETE -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_delete_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, deleteToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, deleteToastColor) setBackgroundAndFilter( @@ -323,20 +321,20 @@ class MotionToast { deleteBackgroundToastColor, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, deleteToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.DELETE.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -344,24 +342,24 @@ class MotionToast { setGravity(position, toast) toast.view = layout//setting the view of custom toast layout -// layout.animate().alpha(0f).duration = 3000 +// binding.animate().alpha(0f).duration = 3000 toast.show() } // CTA for Toast No Internet MotionToastStyle.NO_INTERNET -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_no_internet ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, warningToastColor) setBackgroundAndFilter( @@ -369,20 +367,20 @@ class MotionToast { warningBackgroundToastColor, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.NO_INTERNET.getName() else title setDescriptionDetails( font, Color.BLACK, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -406,27 +404,25 @@ class MotionToast { font: Typeface? ) { layoutInflater = LayoutInflater.from(context) - val layout = layoutInflater.inflate( - R.layout.full_color_toast, - (context).findViewById(R.id.color_toast_view) - ) + val binding = FullColorToastBinding.inflate(layoutInflater) + val layout = binding.root when (style) { // Function for Toast Success MotionToastStyle.SUCCESS -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_check_green ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, successToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -435,15 +431,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.SUCCESS.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -459,19 +455,19 @@ class MotionToast { } // CTA for Toast Error MotionToastStyle.ERROR -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_error_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, errorToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -480,15 +476,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.ERROR.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -504,19 +500,19 @@ class MotionToast { } // CTA for Toast Warning MotionToastStyle.WARNING -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_warning_yellow ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -525,15 +521,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.WARNING.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -549,19 +545,19 @@ class MotionToast { } // CTA for Toast Info MotionToastStyle.INFO -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_info_blue ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, infoToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -570,15 +566,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.INFO.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -594,19 +590,19 @@ class MotionToast { } // CTA for Toast Delete MotionToastStyle.DELETE -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_delete_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, deleteToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -615,15 +611,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.DELETE.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -640,19 +636,19 @@ class MotionToast { } // CTA for Toast No Internet MotionToastStyle.NO_INTERNET -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_no_internet ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -661,15 +657,15 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor(Color.WHITE) - layout.color_toast_text.text = + binding.colorToastText.setTextColor(Color.WHITE) + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.NO_INTERNET.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -697,26 +693,24 @@ class MotionToast { font: Typeface? ) { layoutInflater = LayoutInflater.from(context) - val layout = layoutInflater.inflate( - R.layout.full_color_toast, - (context).findViewById(R.id.color_toast_view) - ) + val binding = FullColorToastBinding.inflate(layoutInflater) + val layout = binding.root when (style) { // Function for Toast Success MotionToastStyle.SUCCESS -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_check_green ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, successToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -724,20 +718,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, successToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.SUCCESS.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -753,19 +747,19 @@ class MotionToast { } // CTA for Toast Error MotionToastStyle.ERROR -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_error_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, errorToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -774,20 +768,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, errorToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.ERROR.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -803,19 +797,19 @@ class MotionToast { } // CTA for Toast Warning MotionToastStyle.WARNING -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_warning_yellow ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -824,20 +818,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.WARNING.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -853,19 +847,19 @@ class MotionToast { } // CTA for Toast Info MotionToastStyle.INFO -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_info_blue ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, infoToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -874,20 +868,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, infoToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.INFO.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -903,19 +897,19 @@ class MotionToast { } // CTA for Toast Delete MotionToastStyle.DELETE -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_delete_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, deleteToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -924,20 +918,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, deleteToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.DELETE.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -956,19 +950,19 @@ class MotionToast { } // CTA for Toast No Internet MotionToastStyle.NO_INTERNET -> { - layout.color_toast_image.setImageDrawable( + binding.colorToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_no_internet ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.color_toast_image.drawable), + DrawableCompat.wrap(binding.colorToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) // Pulse Animation for Icon val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.color_toast_image.startAnimation(pulseAnimation) + binding.colorToastImage.startAnimation(pulseAnimation) // round background color setBackgroundAndFilter( @@ -977,20 +971,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.color_toast_text.setTextColor( + binding.colorToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.color_toast_text.text = + binding.colorToastText.text = if (title.isNullOrBlank()) MotionToastStyle.NO_INTERNET.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.color_toast_description + binding.colorToastDescription ) // init toast @@ -1021,28 +1015,26 @@ class MotionToast { font: Typeface? ) { layoutInflater = LayoutInflater.from(context) - val layout = layoutInflater.inflate( - R.layout.motion_toast, - (context).findViewById(R.id.motion_toast_view) - ) + val binding = MotionToastBinding.inflate(layoutInflater) + val layout = binding.root when (style) { // Function for Toast Success MotionToastStyle.SUCCESS -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_check_green ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, successToastColor) ) // Pulse Animation for Icon - startPulseAnimation(context, layout) + startPulseAnimation(context, binding.customToastImage) // Background tint color for side view - layout.colorView.backgroundTintList = + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, successToastColor) // round background color @@ -1052,20 +1044,20 @@ class MotionToast { ) // Setting up the color for title & Message text - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, successToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.SUCCESS.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) // init toast @@ -1081,18 +1073,18 @@ class MotionToast { } // CTA for Toast Error MotionToastStyle.ERROR -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_error_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, errorToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, errorToastColor) setBackgroundAndFilter( @@ -1100,20 +1092,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, errorToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.ERROR.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -1125,18 +1117,18 @@ class MotionToast { } // CTA for Toast Warning MotionToastStyle.WARNING -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_warning_yellow ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, warningToastColor) setBackgroundAndFilter( @@ -1144,20 +1136,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.WARNING.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -1169,19 +1161,19 @@ class MotionToast { } // CTA for Toast Info MotionToastStyle.INFO -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_info_blue ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, infoToastColor) ) - startPulseAnimation(context, layout) + startPulseAnimation(context, binding.customToastImage) - layout.colorView.backgroundTintList = + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, infoToastColor) setBackgroundAndFilter( @@ -1189,20 +1181,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, infoToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.INFO.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -1214,18 +1206,18 @@ class MotionToast { } // CTA for Toast Delete MotionToastStyle.DELETE -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_delete_ ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, deleteToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, deleteToastColor) setBackgroundAndFilter( @@ -1233,20 +1225,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, deleteToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.DELETE.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) @@ -1258,18 +1250,18 @@ class MotionToast { } // CTA for Toast No Internet MotionToastStyle.NO_INTERNET -> { - layout.custom_toast_image.setImageDrawable( + binding.customToastImage.setImageDrawable( ContextCompat.getDrawable( context, R.drawable.ic_no_internet ) ) DrawableCompat.setTint( - DrawableCompat.wrap(layout.custom_toast_image.drawable), + DrawableCompat.wrap(binding.customToastImage.drawable), ContextCompat.getColor(context, warningToastColor) ) - startPulseAnimation(context, layout) - layout.colorView.backgroundTintList = + startPulseAnimation(context, binding.customToastImage) + binding.colorView.backgroundTintList = ContextCompat.getColorStateList(context, warningToastColor) setBackgroundAndFilter( @@ -1277,20 +1269,20 @@ class MotionToast { R.color.dark_bg_color, layout, context ) - layout.custom_toast_text.setTextColor( + binding.customToastText.setTextColor( ContextCompat.getColor( context, warningToastColor ) ) - layout.custom_toast_text.text = + binding.customToastText.text = if (title.isNullOrBlank()) MotionToastStyle.NO_INTERNET.getName() else title setDescriptionDetails( font, Color.WHITE, message, - layout.custom_toast_description + binding.customToastDescription ) val toast = Toast(context.applicationContext) startTimer(duration, toast) @@ -1315,9 +1307,9 @@ class MotionToast { timer.start() } - private fun startPulseAnimation(context: Activity, layout: View) { + private fun startPulseAnimation(context: Activity, customToastImage: ImageView) { val pulseAnimation = AnimationUtils.loadAnimation(context, R.anim.pulse) - layout.custom_toast_image.startAnimation(pulseAnimation) + customToastImage.startAnimation(pulseAnimation) } private fun setDescriptionDetails(