Merge pull request #1378 from Bnyro/master

improve snackbar style
This commit is contained in:
Bnyro 2022-09-25 10:07:31 +02:00 committed by GitHub
commit e8e964dce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 52 deletions

View File

@ -1,27 +0,0 @@
package com.github.libretube.extensions
import android.view.View
import android.widget.FrameLayout
import androidx.core.content.res.ResourcesCompat
import com.github.libretube.R
import com.google.android.material.snackbar.Snackbar
fun View.getStyledSnackBar(text: Int): Snackbar {
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 = ResourcesCompat.getDrawable(resources, R.drawable.snackbar_shape, null)
return snackBar
}

View File

@ -16,7 +16,6 @@ import com.github.libretube.constants.PIPED_GITHUB_URL
import com.github.libretube.constants.WEBLATE_URL
import com.github.libretube.constants.WEBSITE_URL
import com.github.libretube.databinding.ActivityAboutBinding
import com.github.libretube.extensions.getStyledSnackBar
import com.github.libretube.ui.base.BaseActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
@ -103,12 +102,16 @@ class AboutActivity : BaseActivity() {
val clip = ClipData.newPlainText(getString(R.string.copied), href)
clipboard.setPrimaryClip(clip)
// show the snackBar with open action
val snackBar = binding.root.getStyledSnackBar(R.string.copied_to_clipboard)
snackBar.setAction(R.string.open_copied) {
Snackbar.make(
binding.root,
R.string.copied_to_clipboard,
Snackbar.LENGTH_LONG
)
.setAction(R.string.open_copied) {
openLinkFromHref(href)
}
snackBar.animationMode = Snackbar.ANIMATION_MODE_FADE
snackBar.show()
.setAnimationMode(Snackbar.ANIMATION_MODE_FADE)
.show()
}
private fun showLicense() {

View File

@ -5,11 +5,11 @@ import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import com.github.libretube.R
import com.github.libretube.databinding.ActivityNointernetBinding
import com.github.libretube.extensions.getStyledSnackBar
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.fragments.DownloadsFragment
import com.github.libretube.util.NetworkHelper
import com.github.libretube.util.ThemeHelper
import com.google.android.material.snackbar.Snackbar
class NoInternetActivity : BaseActivity() {
private lateinit var binding: ActivityNointernetBinding
@ -23,7 +23,7 @@ class NoInternetActivity : BaseActivity() {
if (NetworkHelper.isNetworkAvailable(this)) {
ThemeHelper.restartMainActivity(this)
} else {
binding.root.getStyledSnackBar(R.string.turnInternetOn).show()
Snackbar.make(binding.root, R.string.turnInternetOn, Snackbar.LENGTH_LONG).show()
}
}
binding.noInternetSettingsImageView.setOnClickListener {

View File

@ -16,13 +16,13 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.FragmentHomeBinding
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.getStyledSnackBar
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.adapters.ChannelAdapter
import com.github.libretube.ui.adapters.TrendingAdapter
import com.github.libretube.ui.base.BaseFragment
import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.PreferenceHelper
import com.google.android.material.snackbar.Snackbar
import retrofit2.HttpException
import java.io.IOException
@ -86,8 +86,10 @@ class HomeFragment : BaseFragment() {
// show a [SnackBar] if there are no trending videos available
if (response.isEmpty()) {
binding.root.getStyledSnackBar(
R.string.change_region
Snackbar.make(
binding.root,
R.string.change_region,
Snackbar.LENGTH_LONG
)
.setAction(
R.string.settings

View File

@ -6,11 +6,11 @@ import androidx.preference.Preference
import com.github.libretube.BuildConfig
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.extensions.getStyledSnackBar
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.UpdateDialog
import com.github.libretube.util.NetworkHelper
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -97,8 +97,14 @@ class MainSettings : BasePreferenceFragment() {
update?.setOnPreferenceClickListener {
CoroutineScope(Dispatchers.IO).launch {
if (!NetworkHelper.isNetworkAvailable(requireContext())) {
(activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.unknown_error)
?.show()
(activity as? SettingsActivity)?.binding?.let {
Snackbar.make(
it.root,
R.string.unknown_error,
Snackbar.LENGTH_SHORT
)
.show()
}
return@launch
}
// check for update
@ -109,8 +115,14 @@ class MainSettings : BasePreferenceFragment() {
}
if (updateInfo.name == null) {
// request failed
(activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.unknown_error)
?.show()
(activity as? SettingsActivity)?.binding?.let {
Snackbar.make(
it.root,
R.string.unknown_error,
Snackbar.LENGTH_SHORT
)
.show()
}
} else if (BuildConfig.VERSION_NAME != updateInfo.name) {
// show the UpdateAvailableDialog if there's an update available
val updateAvailableDialog = UpdateDialog(updateInfo)
@ -120,8 +132,14 @@ class MainSettings : BasePreferenceFragment() {
)
} else {
// otherwise show the no update available snackBar
(activity as? SettingsActivity)?.binding?.root?.getStyledSnackBar(R.string.app_uptodate)
?.show()
(activity as? SettingsActivity)?.binding?.let {
Snackbar.make(
it.root,
R.string.unknown_error,
Snackbar.LENGTH_SHORT
)
.show()
}
}
}
true

View File

@ -1,6 +0,0 @@
<?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>

View File

@ -11,6 +11,8 @@
@style/Preference.SwitchPreferenceCompat.Material3
</item>
<item name="snackbarStyle">@style/snackBarStyle</item>
</style>
<style name="StartupTheme" parent="BaseTheme">

View File

@ -171,4 +171,12 @@
</style>
<style name="snackBarStyle" parent="@style/Widget.Material3.Snackbar">
<item name="shapeAppearance">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="android:paddingStart">20dp</item>
<item name="android:paddingEnd">20dp</item>
<item name="maxLines">2</item>
<item name="animationMode">slide</item>
</style>
</resources>

View File

@ -11,6 +11,8 @@
@style/Preference.SwitchPreferenceCompat.Material3
</item>
<item name="snackbarStyle">@style/snackBarStyle</item>
</style>
<style name="StartupTheme" parent="BaseTheme">