mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
styled snackbar
This commit is contained in:
parent
47f5ef1ebc
commit
03b2e8e937
@ -13,8 +13,8 @@ import com.github.libretube.WEBLATE_URL
|
|||||||
import com.github.libretube.WEBSITE_URL
|
import com.github.libretube.WEBSITE_URL
|
||||||
import com.github.libretube.databinding.ActivityAboutBinding
|
import com.github.libretube.databinding.ActivityAboutBinding
|
||||||
import com.github.libretube.extensions.BaseActivity
|
import com.github.libretube.extensions.BaseActivity
|
||||||
|
import com.github.libretube.extensions.showSnackBar
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
|
|
||||||
class AboutActivity : BaseActivity() {
|
class AboutActivity : BaseActivity() {
|
||||||
private lateinit var binding: ActivityAboutBinding
|
private lateinit var binding: ActivityAboutBinding
|
||||||
@ -29,8 +29,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
openLinkFromHref(WEBSITE_URL)
|
openLinkFromHref(WEBSITE_URL)
|
||||||
}
|
}
|
||||||
binding.website.setOnLongClickListener {
|
binding.website.setOnLongClickListener {
|
||||||
val text = getString(R.string.website_summary)
|
binding.root.showSnackBar(R.string.website_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +37,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
openLinkFromHref(PIPED_GITHUB_URL)
|
openLinkFromHref(PIPED_GITHUB_URL)
|
||||||
}
|
}
|
||||||
binding.piped.setOnLongClickListener {
|
binding.piped.setOnLongClickListener {
|
||||||
val text = getString(R.string.piped_summary)
|
binding.root.showSnackBar(R.string.piped_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +45,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
openLinkFromHref(WEBLATE_URL)
|
openLinkFromHref(WEBLATE_URL)
|
||||||
}
|
}
|
||||||
binding.translate.setOnLongClickListener {
|
binding.translate.setOnLongClickListener {
|
||||||
val text = getString(R.string.translate_summary)
|
binding.root.showSnackBar(R.string.translate_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +53,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
openLinkFromHref(DONATE_URL)
|
openLinkFromHref(DONATE_URL)
|
||||||
}
|
}
|
||||||
binding.donate.setOnLongClickListener {
|
binding.donate.setOnLongClickListener {
|
||||||
val text = getString(R.string.donate_summary)
|
binding.root.showSnackBar(R.string.donate_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +61,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
openLinkFromHref(GITHUB_URL)
|
openLinkFromHref(GITHUB_URL)
|
||||||
}
|
}
|
||||||
binding.github.setOnLongClickListener {
|
binding.github.setOnLongClickListener {
|
||||||
val text = getString(R.string.contributing_summary)
|
binding.root.showSnackBar(R.string.contributing_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +69,7 @@ class AboutActivity : BaseActivity() {
|
|||||||
showLicense()
|
showLicense()
|
||||||
}
|
}
|
||||||
binding.license.setOnLongClickListener {
|
binding.license.setOnLongClickListener {
|
||||||
val text = getString(R.string.license_summary)
|
binding.root.showSnackBar(R.string.license_summary)
|
||||||
showSnackBar(text)
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,16 +80,6 @@ class AboutActivity : BaseActivity() {
|
|||||||
startActivity(intent)
|
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() {
|
private fun showLicense() {
|
||||||
val licenseString = assets
|
val licenseString = assets
|
||||||
?.open("gpl3.html")
|
?.open("gpl3.html")
|
||||||
|
@ -5,9 +5,9 @@ import android.os.Bundle
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.ActivityNointernetBinding
|
import com.github.libretube.databinding.ActivityNointernetBinding
|
||||||
import com.github.libretube.extensions.BaseActivity
|
import com.github.libretube.extensions.BaseActivity
|
||||||
|
import com.github.libretube.extensions.showSnackBar
|
||||||
import com.github.libretube.util.ConnectionHelper
|
import com.github.libretube.util.ConnectionHelper
|
||||||
import com.github.libretube.util.ThemeHelper
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
|
|
||||||
class NoInternetActivity : BaseActivity() {
|
class NoInternetActivity : BaseActivity() {
|
||||||
private lateinit var binding: ActivityNointernetBinding
|
private lateinit var binding: ActivityNointernetBinding
|
||||||
@ -21,9 +21,7 @@ class NoInternetActivity : BaseActivity() {
|
|||||||
if (ConnectionHelper.isNetworkAvailable(this)) {
|
if (ConnectionHelper.isNetworkAvailable(this)) {
|
||||||
ThemeHelper.restartMainActivity(this)
|
ThemeHelper.restartMainActivity(this)
|
||||||
} else {
|
} else {
|
||||||
val snackBar = Snackbar
|
binding.root.showSnackBar(R.string.turnInternetOn)
|
||||||
.make(binding.root, R.string.turnInternetOn, Snackbar.LENGTH_LONG)
|
|
||||||
snackBar.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.noInternetSettingsImageView.setOnClickListener {
|
binding.noInternetSettingsImageView.setOnClickListener {
|
||||||
|
@ -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()
|
||||||
|
}
|
@ -7,9 +7,10 @@ import com.github.libretube.BuildConfig
|
|||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.activities.SettingsActivity
|
import com.github.libretube.activities.SettingsActivity
|
||||||
import com.github.libretube.dialogs.UpdateDialog
|
import com.github.libretube.dialogs.UpdateDialog
|
||||||
|
import com.github.libretube.extensions.showSnackBar
|
||||||
import com.github.libretube.update.UpdateChecker
|
import com.github.libretube.update.UpdateChecker
|
||||||
|
import com.github.libretube.util.ConnectionHelper
|
||||||
import com.github.libretube.views.MaterialPreferenceFragment
|
import com.github.libretube.views.MaterialPreferenceFragment
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -85,32 +86,25 @@ class MainSettings : MaterialPreferenceFragment() {
|
|||||||
// checking for update: yes -> dialog, no -> snackBar
|
// checking for update: yes -> dialog, no -> snackBar
|
||||||
update?.setOnPreferenceClickListener {
|
update?.setOnPreferenceClickListener {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
if (!ConnectionHelper.isNetworkAvailable(requireContext())) {
|
||||||
|
(activity as SettingsActivity).binding.root.showSnackBar(R.string.unknown_error)
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
// check for update
|
// check for update
|
||||||
val updateInfo = UpdateChecker.getLatestReleaseInfo()
|
val updateInfo = UpdateChecker.getLatestReleaseInfo()
|
||||||
if (updateInfo?.name == null) {
|
if (updateInfo?.name == null) {
|
||||||
// request failed
|
// request failed
|
||||||
val settingsActivity = activity as SettingsActivity
|
(activity as SettingsActivity).binding.root.showSnackBar(R.string.unknown_error)
|
||||||
val snackBar = Snackbar
|
|
||||||
.make(
|
|
||||||
settingsActivity.binding.root,
|
|
||||||
R.string.unknown_error,
|
|
||||||
Snackbar.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
snackBar.show()
|
|
||||||
} else if (BuildConfig.VERSION_NAME != updateInfo.name) {
|
} else if (BuildConfig.VERSION_NAME != updateInfo.name) {
|
||||||
// show the UpdateAvailableDialog if there's an update available
|
// show the UpdateAvailableDialog if there's an update available
|
||||||
val updateAvailableDialog = UpdateDialog(updateInfo)
|
val updateAvailableDialog = UpdateDialog(updateInfo)
|
||||||
updateAvailableDialog.show(childFragmentManager, UpdateDialog::class.java.name)
|
updateAvailableDialog.show(
|
||||||
|
childFragmentManager,
|
||||||
|
UpdateDialog::class.java.name
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// otherwise show the no update available snackBar
|
// otherwise show the no update available snackBar
|
||||||
val settingsActivity = activity as SettingsActivity
|
(activity as SettingsActivity).binding.root.showSnackBar(R.string.app_uptodate)
|
||||||
val snackBar = Snackbar
|
|
||||||
.make(
|
|
||||||
settingsActivity.binding.root,
|
|
||||||
R.string.app_uptodate,
|
|
||||||
Snackbar.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
snackBar.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
6
app/src/main/res/drawable/snackbar_shape.xml
Normal file
6
app/src/main/res/drawable/snackbar_shape.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user