improve about fragment

This commit is contained in:
Bnyro 2022-07-04 08:39:06 +02:00
parent 215d5aa4de
commit 486ee090d1
2 changed files with 59 additions and 17 deletions

View File

@ -17,6 +17,7 @@ import com.github.libretube.util.GITHUB_URL
import com.github.libretube.util.PIPED_GITHUB_URL import com.github.libretube.util.PIPED_GITHUB_URL
import com.github.libretube.util.WEBSITE_URL import com.github.libretube.util.WEBSITE_URL
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
class AboutFragment : Fragment() { class AboutFragment : Fragment() {
private lateinit var binding: FragmentAboutBinding private lateinit var binding: FragmentAboutBinding
@ -39,31 +40,45 @@ class AboutFragment : Fragment() {
binding.website.setOnClickListener { binding.website.setOnClickListener {
openLinkFromHref(WEBSITE_URL) openLinkFromHref(WEBSITE_URL)
} }
binding.website.setOnLongClickListener {
val text = context?.getString(R.string.website_summary)!!
showSnackBar(text)
true
}
binding.piped.setOnClickListener { binding.piped.setOnClickListener {
openLinkFromHref(PIPED_GITHUB_URL) openLinkFromHref(PIPED_GITHUB_URL)
} }
binding.piped.setOnLongClickListener { val text = context?.getString(R.string.piped_summary)!!
showSnackBar(text)
true
}
binding.donate.setOnClickListener { binding.donate.setOnClickListener {
openLinkFromHref(DONATE_URL) openLinkFromHref(DONATE_URL)
} }
binding.donate.setOnLongClickListener { val text = context?.getString(R.string.donate_summary)!!
showSnackBar(text)
true
}
binding.github.setOnClickListener { binding.github.setOnClickListener {
openLinkFromHref(GITHUB_URL) openLinkFromHref(GITHUB_URL)
} }
binding.license.setOnClickListener { binding.github.setOnLongClickListener {
val licenseString = view.context.assets val text = context?.getString(R.string.contributing_summary)!!
.open("gpl3.html").bufferedReader().use { showSnackBar(text)
it.readText() true
} }
val licenseHtml = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(licenseString, 1)
} else {
Html.fromHtml(licenseString)
}
MaterialAlertDialogBuilder(view.context!!) binding.license.setOnClickListener {
.setPositiveButton(getString(R.string.okay)) { _, _ -> } showLicense()
.setMessage(licenseHtml) }
.create()
.show() 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) val intent = Intent(Intent.ACTION_VIEW).setData(uri)
startActivity(intent) 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()
}
} }

View File

@ -1,6 +1,5 @@
<!-- Replaces the drawables of the default exoplayer controls (see https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/res/values/drawables.xml) -->
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Replaces the drawables of the default exoplayer controls (see https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/res/values/drawables.xml) -->
<resources> <resources>
<drawable name="exo_styled_controls_play">@drawable/ic_play</drawable> <drawable name="exo_styled_controls_play">@drawable/ic_play</drawable>