From 3dfdd45aaf93b8efcf12600ebc65de2269995e94 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 4 Jul 2022 08:48:47 +0200 Subject: [PATCH] improve snackbar colors --- .../libretube/preferences/AboutFragment.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt index f5cf6bcca..5fe36d3bf 100644 --- a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt +++ b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt @@ -5,6 +5,7 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.text.Html +import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -49,7 +50,8 @@ class AboutFragment : Fragment() { binding.piped.setOnClickListener { openLinkFromHref(PIPED_GITHUB_URL) } - binding.piped.setOnLongClickListener { val text = context?.getString(R.string.piped_summary)!! + binding.piped.setOnLongClickListener { + val text = context?.getString(R.string.piped_summary)!! showSnackBar(text) true } @@ -57,7 +59,8 @@ class AboutFragment : Fragment() { binding.donate.setOnClickListener { openLinkFromHref(DONATE_URL) } - binding.donate.setOnLongClickListener { val text = context?.getString(R.string.donate_summary)!! + binding.donate.setOnLongClickListener { + val text = context?.getString(R.string.donate_summary)!! showSnackBar(text) true } @@ -74,7 +77,6 @@ class AboutFragment : Fragment() { binding.license.setOnClickListener { showLicense() } - binding.license.setOnLongClickListener { val text = context?.getString(R.string.license_summary)!! showSnackBar(text) @@ -91,6 +93,8 @@ class AboutFragment : Fragment() { private fun showSnackBar(text: String) { val snackBar = Snackbar .make(binding.root, text, Snackbar.LENGTH_LONG) + snackBar.setBackgroundTint(getThemeColor(R.attr.colorSurface)) + snackBar.setTextColor(getThemeColor(R.attr.colorPrimary)) snackBar.show() } @@ -115,4 +119,10 @@ class AboutFragment : Fragment() { .create() .show() } + + private fun getThemeColor(colorCode: Int): Int { + val value = TypedValue() + context!!.theme.resolveAttribute(colorCode, value, true) + return value.data + } }