From d363fcd25e65510a0dd156e78a602ffcf0857e1e Mon Sep 17 00:00:00 2001 From: Ido-Barnea Date: Wed, 20 Apr 2022 18:00:36 +0300 Subject: [PATCH] - Changed setLoadingProgressBarColor() name to setProgressBarColor() - Added setDialogColorTheme() which changes the color of all dialog elements --- .../main/java/com/barnea/dialoger/Dialoger.kt | 16 +++++++++++++++- .../java/com/barnea/dialoger/MainActivity.kt | 9 +++------ build.gradle | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Dialoger/src/main/java/com/barnea/dialoger/Dialoger.kt b/Dialoger/src/main/java/com/barnea/dialoger/Dialoger.kt index 931b3be..9388ac5 100644 --- a/Dialoger/src/main/java/com/barnea/dialoger/Dialoger.kt +++ b/Dialoger/src/main/java/com/barnea/dialoger/Dialoger.kt @@ -138,6 +138,20 @@ class Dialoger( return this } + /** + * Changes the color of all dialog elements + * @param color the chosen color id + * @return Dialoger object + */ + fun setDialogColorTheme(color: Int): Dialoger { + setTitleColor(color) + setDescriptionColor(color) + setButtonBackgroundColor(color) + setProgressBarColor(color) + + return this + } + /** * @param color the chosen color id * @return Dialoger object @@ -187,7 +201,7 @@ class Dialoger( * @param color the chosen color id * @return Dialoger object */ - fun setLoadingProgressBarColor(color: Int): Dialoger { + fun setProgressBarColor(color: Int): Dialoger { getDialogProgressBar().indeterminateDrawable.setTintList(intToColorStateList(color)) return this } diff --git a/app/src/main/java/com/barnea/dialoger/MainActivity.kt b/app/src/main/java/com/barnea/dialoger/MainActivity.kt index 68eab89..19048e1 100644 --- a/app/src/main/java/com/barnea/dialoger/MainActivity.kt +++ b/app/src/main/java/com/barnea/dialoger/MainActivity.kt @@ -2,7 +2,6 @@ package com.barnea.dialoger import android.os.Bundle import android.os.Handler -import android.view.Gravity import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -13,8 +12,8 @@ class MainActivity : AppCompatActivity() { val dialog = Dialoger(this, Dialoger.TYPE_LOADING) .setTitle("This is a loading dialog...") - .setDescription("We couldn\\'t find the address, and we are not sure anyone will be able to. ever. Maybe try writing it again?") - .setLoadingProgressBarColor(R.color.purple_200) + .setDescription("This might take a while...") + .setProgressBarColor(R.color.purple_200) .show() // dismiss the dialog after 3 seconds @@ -22,12 +21,10 @@ class MainActivity : AppCompatActivity() { dialog.dismiss() Dialoger(this, Dialoger.TYPE_MESSAGE) + .setDialogColorTheme(R.color.green) .setTitle("New Dialog!") - .setTitleColor(R.color.green) .setDescription("This was an amazing success!") - .setDescriptionColor(R.color.green) .setButtonText("ALLONS-Y!") - .setButtonBackgroundColor(R.color.green) .setButtonOnClickListener { Toast.makeText(this, "dialog button clicked", Toast.LENGTH_SHORT).show() } diff --git a/build.gradle b/build.gradle index 0ccd671..3605be2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.1.2' apply false - id 'com.android.library' version '7.1.2' apply false + id 'com.android.application' version '7.1.3' apply false + id 'com.android.library' version '7.1.3' apply false id 'org.jetbrains.kotlin.android' version '1.6.10' apply false }