Merge pull request #1065 from Bnyro/master

Resize Mode Pref & Better Dialogs & SnackBars
This commit is contained in:
Bnyro 2022-08-14 17:55:00 +02:00 committed by GitHub
commit cb14f0a161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 150 additions and 109 deletions

View File

@ -19,7 +19,6 @@ import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.ExceptionHandler
import com.github.libretube.util.NotificationHelper
import java.lang.Exception
class MyApp : Application() {
override fun onCreate() {
@ -170,7 +169,8 @@ class MyApp : Application() {
DatabaseHolder.db.watchHistoryDao().insertAll(
*watchHistoryItems.toTypedArray()
)
} catch (e: Exception) {}
} catch (e: Exception) {
}
prefs.edit().putString("watch_history", "").commit()
}
val legacyWatchPositions = prefs.getString("watch_positions", "")
@ -181,7 +181,8 @@ class MyApp : Application() {
DatabaseHolder.db.watchPositionDao().insertAll(
*watchPositions.toTypedArray()
)
} catch (e: Exception) {}
} catch (e: Exception) {
}
prefs.edit().remove("watch_positions").commit()
}
prefs.edit()

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

@ -168,6 +168,7 @@ class PlayerFragment : BaseFragment() {
private var sponsorBlockNotifications = true
private var skipButtonsEnabled = false
private var pipEnabled = true
private var resizeModePref = "fit"
/**
* for autoplay
@ -336,6 +337,11 @@ class PlayerFragment : BaseFragment() {
PreferenceKeys.PICTURE_IN_PICTURE,
true
)
resizeModePref = PreferenceHelper.getString(
PreferenceKeys.PLAYER_RESIZE_MODE,
"fit"
)
}
private fun initializeTransitionLayout() {
@ -513,13 +519,9 @@ class PlayerFragment : BaseFragment() {
.show()
}
override fun onAspectRatioClicked() {
override fun onResizeModeClicked() {
// switching between original aspect ratio (black bars) and zoomed to fill device screen
val aspectRatioModeNames = arrayOf(
context?.getString(R.string.resize_mode_fit),
context?.getString(R.string.resize_mode_zoom),
context?.getString(R.string.resize_mode_fill)
)
val aspectRatioModeNames = context?.resources?.getStringArray(R.array.resizeMode)
val aspectRatioModes = arrayOf(
AspectRatioFrameLayout.RESIZE_MODE_FIT,
@ -605,7 +607,7 @@ class PlayerFragment : BaseFragment() {
context.getString(R.string.repeat_mode_none)
} else context.getString(R.string.repeat_mode_current)
// set the aspect ratio mode
currentAspectRatio = when (exoPlayerView.resizeMode) {
currentResizeMode = when (exoPlayerView.resizeMode) {
AspectRatioFrameLayout.RESIZE_MODE_FIT -> context.getString(R.string.resize_mode_fit)
AspectRatioFrameLayout.RESIZE_MODE_FILL -> context.getString(R.string.resize_mode_fill)
else -> context.getString(R.string.resize_mode_zoom)
@ -979,6 +981,11 @@ class PlayerFragment : BaseFragment() {
controllerHideOnTouch = true
useController = false
player = exoPlayer
resizeMode = when (resizeModePref) {
"fill" -> AspectRatioFrameLayout.RESIZE_MODE_FILL
"zoom" -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM
else -> AspectRatioFrameLayout.RESIZE_MODE_FIT
}
}
if (useSystemCaptionStyle) {

View File

@ -10,7 +10,7 @@ interface PlayerOptionsInterface {
fun onPlaybackSpeedClicked()
fun onAspectRatioClicked()
fun onResizeModeClicked()
fun onRepeatModeClicked()
}

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

@ -67,6 +67,7 @@ object PreferenceKeys {
const val DEFAULT_SUBTITLE = "default_subtitle"
const val SKIP_BUTTONS = "skip_buttons"
const val PICTURE_IN_PICTURE = "picture_in_picture"
const val PLAYER_RESIZE_MODE = "player_resize_mode"
/**
* Background mode

View File

@ -25,7 +25,7 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
var currentAutoplayMode: String? = null
var currentRepeatMode: String? = null
var currentQuality: String? = null
var currentAspectRatio: String? = null
var currentResizeMode: String? = null
var currentCaptions: String? = null
override fun onCreateView(
@ -67,10 +67,10 @@ class PlayerOptionsBottomSheet : BottomSheetDialogFragment() {
binding.repeatMode.updateText(currentRepeatMode)
binding.aspectRatio.updateText(currentAspectRatio)
binding.resizeMode.updateText(currentResizeMode)
binding.aspectRatio.setOnClickListener {
playerOptionsInterface.onAspectRatioClicked()
binding.resizeMode.setOnClickListener {
playerOptionsInterface.onResizeModeClicked()
this.dismiss()
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#FF000000"
android:pathData="M6,42L6,30.5h3v6.35l7.4,-7.4 2.15,2.15 -7.4,7.4h6.35v3ZM30.5,42v-3h6.35l-7.35,-7.35 2.15,-2.15L39,36.85L39,30.5h3L42,42ZM16.35,18.5 L9,11.15v6.35L6,17.5L6,6h11.5v3h-6.35l7.35,7.35ZM31.65,18.5 L29.5,16.35L36.85,9L30.5,9L30.5,6L42,6v11.5h-3v-6.35Z" />
</vector>

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>

View File

@ -39,8 +39,8 @@
app:drawableStartCompat="@drawable/ic_repeat" />
<TextView
android:id="@+id/aspectRatio"
android:id="@+id/resizeMode"
style="@style/BottomSheetItem"
android:text="@string/aspect_ratio"
android:text="@string/player_resize_mode"
app:drawableStartCompat="@drawable/ic_aspect_ratio" />
</LinearLayout>

View File

@ -23,7 +23,7 @@
<Button
android:id="@+id/addToPlaylist"
style="@style/CustomDialogButton"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="@string/addToPlaylist" />
</LinearLayout>

View File

@ -14,22 +14,22 @@
android:text="@string/app_name"
android:textSize="20sp" />
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/playlistName">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/playlist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/playlistName"
android:inputType="text"
android:padding="12dp" />
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:orientation="horizontal">
<Button
@ -40,7 +40,7 @@
<Button
android:id="@+id/create_new_playlist"
style="@style/CustomDialogButton"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="@string/createPlaylist" />
</LinearLayout>

View File

@ -4,7 +4,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
@ -14,37 +13,37 @@
android:text="@string/app_name"
android:textSize="20sp" />
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/instance_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/instance_name"
android:inputType="text"
android:padding="12dp" />
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/instance_frontend_url">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceFrontendUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/instance_frontend_url"
android:inputType="text"
android:padding="12dp" />
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/instance_api_url">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceApiUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/instance_api_url"
android:inputType="text"
android:padding="12dp" />
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
@ -61,7 +60,7 @@
<Button
android:id="@+id/addInstance"
style="@style/CustomDialogButton"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="@string/addInstance" />
</LinearLayout>

View File

@ -13,22 +13,22 @@
android:text="@string/app_name"
android:textSize="20sp" />
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/delete_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword"
android:padding="12dp" />
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:orientation="horizontal">
<Button
@ -39,7 +39,7 @@
<Button
android:id="@+id/delete_account_confirm"
style="@style/CustomDialogButton"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="@string/deleteAccount" />
</LinearLayout>

View File

@ -4,7 +4,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
@ -14,33 +13,33 @@
android:text="@string/app_name"
android:textSize="20sp" />
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/username">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:inputType="text"
android:padding="12dp" />
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomDialogTextInputLayout"
android:hint="@string/password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword"
android:padding="12dp" />
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:orientation="horizontal">
<Button
@ -51,7 +50,7 @@
<Button
android:id="@+id/login"
style="@style/CustomDialogButton"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="@string/login" />
</LinearLayout>

View File

@ -846,4 +846,16 @@
<item>120</item>
</string-array>
<string-array name="resizeMode">
<item>@string/resize_mode_fit</item>
<item>@string/resize_mode_zoom</item>
<item>@string/resize_mode_fill</item>
</string-array>
<string-array name="resizeModeValues">
<item>fit</item>
<item>zoom</item>
<item>fill</item>
</string-array>
</resources>

View File

@ -313,4 +313,5 @@
<string name="backup_restore">Backup &amp; restore</string>
<string name="backup">Backup</string>
<string name="picture_in_picture">Picture in Picture</string>
<string name="player_resize_mode">Resize mode</string>
</resources>

View File

@ -63,7 +63,7 @@
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">right</item>
<item name="android:layout_gravity">end</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:padding">8dp</item>
@ -73,16 +73,10 @@
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="hintEnabled">false</item>
<item name="android:layout_marginLeft">15dp</item>
<item name="android:layout_marginRight">15dp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">10dp</item>
</style>

View File

@ -77,6 +77,15 @@
app:key="default_subtitle"
app:title="@string/default_subtitle_language" />
<ListPreference
android:defaultValue="fit"
android:entries="@array/resizeMode"
android:entryValues="@array/resizeModeValues"
android:icon="@drawable/ic_zoom"
app:key="player_resize_mode"
app:title="@string/player_resize_mode"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_next"