From 486ee090d130b2b4fe555371a83bbba30e419d45 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 4 Jul 2022 08:39:06 +0200 Subject: [PATCH] improve about fragment --- .../libretube/preferences/AboutFragment.kt | 73 +++++++++++++++---- app/src/main/res/values/drawables.xml | 3 +- 2 files changed, 59 insertions(+), 17 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 77483ce33..f5cf6bcca 100644 --- a/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt +++ b/app/src/main/java/com/github/libretube/preferences/AboutFragment.kt @@ -17,6 +17,7 @@ import com.github.libretube.util.GITHUB_URL import com.github.libretube.util.PIPED_GITHUB_URL import com.github.libretube.util.WEBSITE_URL import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.snackbar.Snackbar class AboutFragment : Fragment() { private lateinit var binding: FragmentAboutBinding @@ -39,31 +40,45 @@ class AboutFragment : Fragment() { binding.website.setOnClickListener { openLinkFromHref(WEBSITE_URL) } + binding.website.setOnLongClickListener { + val text = context?.getString(R.string.website_summary)!! + showSnackBar(text) + true + } + binding.piped.setOnClickListener { openLinkFromHref(PIPED_GITHUB_URL) } + binding.piped.setOnLongClickListener { val text = context?.getString(R.string.piped_summary)!! + showSnackBar(text) + true + } + binding.donate.setOnClickListener { openLinkFromHref(DONATE_URL) } + binding.donate.setOnLongClickListener { val text = context?.getString(R.string.donate_summary)!! + showSnackBar(text) + true + } + binding.github.setOnClickListener { openLinkFromHref(GITHUB_URL) } - binding.license.setOnClickListener { - val licenseString = view.context.assets - .open("gpl3.html").bufferedReader().use { - it.readText() - } - val licenseHtml = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Html.fromHtml(licenseString, 1) - } else { - Html.fromHtml(licenseString) - } + binding.github.setOnLongClickListener { + val text = context?.getString(R.string.contributing_summary)!! + showSnackBar(text) + true + } - MaterialAlertDialogBuilder(view.context!!) - .setPositiveButton(getString(R.string.okay)) { _, _ -> } - .setMessage(licenseHtml) - .create() - .show() + binding.license.setOnClickListener { + showLicense() + } + + binding.license.setOnLongClickListener { + val text = context?.getString(R.string.license_summary)!! + showSnackBar(text) + true } } @@ -72,4 +87,32 @@ class AboutFragment : Fragment() { val intent = Intent(Intent.ACTION_VIEW).setData(uri) startActivity(intent) } + + private fun showSnackBar(text: String) { + val snackBar = Snackbar + .make(binding.root, text, Snackbar.LENGTH_LONG) + snackBar.show() + } + + private fun showLicense() { + val assets = view?.context?.assets + val licenseString = assets + ?.open("gpl3.html") + ?.bufferedReader() + .use { + it?.readText() + } + + val licenseHtml = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Html.fromHtml(licenseString.toString(), 1) + } else { + Html.fromHtml(licenseString.toString()) + } + + MaterialAlertDialogBuilder(requireContext()) + .setPositiveButton(getString(R.string.okay)) { _, _ -> } + .setMessage(licenseHtml) + .create() + .show() + } } diff --git a/app/src/main/res/values/drawables.xml b/app/src/main/res/values/drawables.xml index ca4aca5fd..8534441e6 100644 --- a/app/src/main/res/values/drawables.xml +++ b/app/src/main/res/values/drawables.xml @@ -1,6 +1,5 @@ - - + @drawable/ic_play