styled snackbar

This commit is contained in:
Bnyro 2022-08-14 17:23:20 +02:00
parent 47f5ef1ebc
commit 03b2e8e937
5 changed files with 53 additions and 45 deletions

View File

@ -13,8 +13,8 @@ import com.github.libretube.WEBLATE_URL
import com.github.libretube.WEBSITE_URL
import com.github.libretube.databinding.ActivityAboutBinding
import com.github.libretube.extensions.BaseActivity
import com.github.libretube.extensions.showSnackBar
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
class AboutActivity : BaseActivity() {
private lateinit var binding: ActivityAboutBinding
@ -29,8 +29,7 @@ class AboutActivity : BaseActivity() {
openLinkFromHref(WEBSITE_URL)
}
binding.website.setOnLongClickListener {
val text = getString(R.string.website_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.website_summary)
true
}
@ -38,8 +37,7 @@ class AboutActivity : BaseActivity() {
openLinkFromHref(PIPED_GITHUB_URL)
}
binding.piped.setOnLongClickListener {
val text = getString(R.string.piped_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.piped_summary)
true
}
@ -47,8 +45,7 @@ class AboutActivity : BaseActivity() {
openLinkFromHref(WEBLATE_URL)
}
binding.translate.setOnLongClickListener {
val text = getString(R.string.translate_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.translate_summary)
true
}
@ -56,8 +53,7 @@ class AboutActivity : BaseActivity() {
openLinkFromHref(DONATE_URL)
}
binding.donate.setOnLongClickListener {
val text = getString(R.string.donate_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.donate_summary)
true
}
@ -65,8 +61,7 @@ class AboutActivity : BaseActivity() {
openLinkFromHref(GITHUB_URL)
}
binding.github.setOnLongClickListener {
val text = getString(R.string.contributing_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.contributing_summary)
true
}
@ -74,8 +69,7 @@ class AboutActivity : BaseActivity() {
showLicense()
}
binding.license.setOnLongClickListener {
val text = getString(R.string.license_summary)
showSnackBar(text)
binding.root.showSnackBar(R.string.license_summary)
true
}
}
@ -86,16 +80,6 @@ class AboutActivity : BaseActivity() {
startActivity(intent)
}
private fun showSnackBar(text: String) {
val snackBar = Snackbar
.make(binding.root, text, Snackbar.LENGTH_LONG)
// prevent the text from being partially hidden
snackBar.setTextMaxLines(3)
snackBar.show()
}
private fun showLicense() {
val licenseString = assets
?.open("gpl3.html")

View File

@ -5,9 +5,9 @@ import android.os.Bundle
import com.github.libretube.R
import com.github.libretube.databinding.ActivityNointernetBinding
import com.github.libretube.extensions.BaseActivity
import com.github.libretube.extensions.showSnackBar
import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.ThemeHelper
import com.google.android.material.snackbar.Snackbar
class NoInternetActivity : BaseActivity() {
private lateinit var binding: ActivityNointernetBinding
@ -21,9 +21,7 @@ class NoInternetActivity : BaseActivity() {
if (ConnectionHelper.isNetworkAvailable(this)) {
ThemeHelper.restartMainActivity(this)
} else {
val snackBar = Snackbar
.make(binding.root, R.string.turnInternetOn, Snackbar.LENGTH_LONG)
snackBar.show()
binding.root.showSnackBar(R.string.turnInternetOn)
}
}
binding.noInternetSettingsImageView.setOnClickListener {

View File

@ -0,0 +1,26 @@
package com.github.libretube.extensions
import android.view.View
import android.widget.FrameLayout
import com.github.libretube.R
import com.google.android.material.snackbar.Snackbar
fun View.showSnackBar(text: Int) {
val snackBar = Snackbar.make(this, text, Snackbar.LENGTH_SHORT)
snackBar.setTextMaxLines(3)
snackBar.animationMode = Snackbar.ANIMATION_MODE_SLIDE
val params = snackBar.view.layoutParams as FrameLayout.LayoutParams
val sideMargin = 70
params.setMargins(
sideMargin,
params.topMargin,
sideMargin,
sideMargin + 50
)
snackBar.view.layoutParams = params
snackBar.view.background = resources.getDrawable(R.drawable.snackbar_shape, null)
snackBar.show()
}

View File

@ -7,9 +7,10 @@ import com.github.libretube.BuildConfig
import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.UpdateDialog
import com.github.libretube.extensions.showSnackBar
import com.github.libretube.update.UpdateChecker
import com.github.libretube.util.ConnectionHelper
import com.github.libretube.views.MaterialPreferenceFragment
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -85,32 +86,25 @@ class MainSettings : MaterialPreferenceFragment() {
// checking for update: yes -> dialog, no -> snackBar
update?.setOnPreferenceClickListener {
CoroutineScope(Dispatchers.IO).launch {
if (!ConnectionHelper.isNetworkAvailable(requireContext())) {
(activity as SettingsActivity).binding.root.showSnackBar(R.string.unknown_error)
return@launch
}
// check for update
val updateInfo = UpdateChecker.getLatestReleaseInfo()
if (updateInfo?.name == null) {
// request failed
val settingsActivity = activity as SettingsActivity
val snackBar = Snackbar
.make(
settingsActivity.binding.root,
R.string.unknown_error,
Snackbar.LENGTH_SHORT
)
snackBar.show()
(activity as SettingsActivity).binding.root.showSnackBar(R.string.unknown_error)
} else if (BuildConfig.VERSION_NAME != updateInfo.name) {
// show the UpdateAvailableDialog if there's an update available
val updateAvailableDialog = UpdateDialog(updateInfo)
updateAvailableDialog.show(childFragmentManager, UpdateDialog::class.java.name)
updateAvailableDialog.show(
childFragmentManager,
UpdateDialog::class.java.name
)
} else {
// otherwise show the no update available snackBar
val settingsActivity = activity as SettingsActivity
val snackBar = Snackbar
.make(
settingsActivity.binding.root,
R.string.app_uptodate,
Snackbar.LENGTH_SHORT
)
snackBar.show()
(activity as SettingsActivity).binding.root.showSnackBar(R.string.app_uptodate)
}
}
true

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?attr/colorSurface" />
<corners android:radius="10dp" />
</shape>