From 31d250efa674e3f39621e7566866ab672a28cb6c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 18 Dec 2016 23:50:19 +0100 Subject: [PATCH] updating some things related to dialog background colors --- .../commons/dialogs/ConfirmationAdvancedDialog.kt | 5 +++-- .../simplemobiletools/commons/dialogs/ConfirmationDialog.kt | 5 +++-- .../com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt | 4 +++- .../com/simplemobiletools/commons/extensions/Context.kt | 4 +--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt index a89978fee..ca063d231 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationAdvancedDialog.kt @@ -15,9 +15,10 @@ class ConfirmationAdvancedDialog(context: Context, message: String = "", message init { val baseConfig = BaseConfig.newInstance(context) + val backgroundColor = baseConfig.backgroundColor val view = LayoutInflater.from(context).inflate(R.layout.dialog_message, null) view.message.text = if (message.isEmpty()) context.resources.getString(messageId) else message - view.message.setTextColor(baseConfig.backgroundColor.getContrastColor()) + view.message.setTextColor(backgroundColor.getContrastColor()) val builder = AlertDialog.Builder(context) .setView(view) @@ -30,7 +31,7 @@ class ConfirmationAdvancedDialog(context: Context, message: String = "", message show() getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor) getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(primaryColor) - window.setBackgroundDrawable(context.getDialogBackgroundColor(baseConfig)) + window.setBackgroundDrawable(context.getDialogBackgroundColor(backgroundColor)) } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt index 3d20642f9..bd5e1abea 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ConfirmationDialog.kt @@ -25,9 +25,10 @@ class ConfirmationDialog(context: Context, message: String = "", messageId: Int init { val baseConfig = BaseConfig.newInstance(context) + val backgroundColor = baseConfig.backgroundColor val view = LayoutInflater.from(context).inflate(R.layout.dialog_message, null) view.message.text = if (message.isEmpty()) context.resources.getString(messageId) else message - view.message.setTextColor(baseConfig.backgroundColor.getContrastColor()) + view.message.setTextColor(backgroundColor.getContrastColor()) val builder = AlertDialog.Builder(context) .setView(view) @@ -42,7 +43,7 @@ class ConfirmationDialog(context: Context, message: String = "", messageId: Int show() getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor) getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(primaryColor) - window.setBackgroundDrawable(context.getDialogBackgroundColor(baseConfig)) + window.setBackgroundDrawable(context.getDialogBackgroundColor(backgroundColor)) } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt index ca172780d..43439c20b 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/WhatsNewDialog.kt @@ -4,15 +4,16 @@ import android.app.Activity import android.app.AlertDialog import android.view.LayoutInflater import com.simplemobiletools.commons.R +import com.simplemobiletools.commons.extensions.getDialogBackgroundColor import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.models.Release import kotlinx.android.synthetic.main.dialog_whats_new.view.* - class WhatsNewDialog(val activity: Activity, val releases: List) { var dialog: AlertDialog? = null init { + val baseConfig = BaseConfig.newInstance(activity) val view = LayoutInflater.from(activity).inflate(R.layout.dialog_whats_new, null) view.whats_new_content.text = getNewReleases() @@ -26,6 +27,7 @@ class WhatsNewDialog(val activity: Activity, val releases: List) { setCanceledOnTouchOutside(true) show() getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor) + window.setBackgroundDrawable(context.getDialogBackgroundColor(baseConfig.backgroundColor)) } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index dc672fe72..f4105c38e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -6,7 +6,6 @@ import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import android.widget.Toast import com.simplemobiletools.commons.R -import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.PREFS_KEY fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, id, length).show() @@ -15,8 +14,7 @@ fun Context.toast(msg: String, length: Int = Toast.LENGTH_SHORT) = Toast.makeTex fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE) -fun Context.getDialogBackgroundColor(baseConfig: BaseConfig): Drawable { - val backgroundColor = baseConfig.backgroundColor +fun Context.getDialogBackgroundColor(backgroundColor: Int): Drawable { return ColorDrawable(if (backgroundColor.getContrastColor() == Color.WHITE) { getColor(R.color.dark_dialog_background) } else {