feat: add tooltips to playback sheet

This commit is contained in:
FineFindus 2023-08-14 18:40:52 +02:00 committed by Bnyro
parent 609449f1e7
commit e5efe97693
6 changed files with 32 additions and 95 deletions

View File

@ -19,11 +19,11 @@ import com.github.libretube.obj.NewPipeSubscription
import com.github.libretube.obj.NewPipeSubscriptions import com.github.libretube.obj.NewPipeSubscriptions
import com.github.libretube.obj.PipedImportPlaylist import com.github.libretube.obj.PipedImportPlaylist
import com.github.libretube.obj.PipedImportPlaylistFile import com.github.libretube.obj.PipedImportPlaylistFile
import java.util.stream.Collectors
import kotlin.streams.toList import kotlin.streams.toList
import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.encodeToStream import kotlinx.serialization.json.encodeToStream
import java.util.stream.Collectors
object ImportHelper { object ImportHelper {
/** /**

View File

@ -62,7 +62,11 @@ class AddToPlaylistDialog(
if (playlists.isEmpty()) return@repeatOnLifecycle if (playlists.isEmpty()) return@repeatOnLifecycle
binding.playlistsSpinner.adapter = binding.playlistsSpinner.adapter =
ArrayAdapter(requireContext(), R.layout.dropdown_item, playlists.map { it.name!! }) ArrayAdapter(
requireContext(),
R.layout.dropdown_item,
playlists.map { it.name!! }
)
// select the last used playlist // select the last used playlist
viewModel.lastSelectedPlaylistId?.let { id -> viewModel.lastSelectedPlaylistId?.let { id ->

View File

@ -0,0 +1,15 @@
package com.github.libretube.ui.extensions
import android.os.Build
import android.widget.ImageView
/**
* Attempts to set the tooltip for the ImageView.
* If the OS does not support tooltips, this function will have no effect.
* @param tooltip The tooltip of the image
*/
fun ImageView.trySetTooltip(tooltip: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tooltipText = tooltip
}
}

View File

@ -5,7 +5,6 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.text.format.DateUtils import android.text.format.DateUtils
@ -50,6 +49,7 @@ import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.obj.BottomSheetItem import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.toggleSystemBars import com.github.libretube.ui.extensions.toggleSystemBars
import com.github.libretube.ui.extensions.trySetTooltip
import com.github.libretube.ui.interfaces.PlayerGestureOptions import com.github.libretube.ui.interfaces.PlayerGestureOptions
import com.github.libretube.ui.interfaces.PlayerOptions import com.github.libretube.ui.interfaces.PlayerOptions
import com.github.libretube.ui.listeners.PlayerGestureController import com.github.libretube.ui.listeners.PlayerGestureController
@ -128,11 +128,15 @@ open class CustomExoPlayerView(
// locking the player // locking the player
binding.lockPlayer.setOnClickListener { binding.lockPlayer.setOnClickListener {
// change the locked/unlocked icon // change the locked/unlocked icon
val icon = if (!isPlayerLocked) R.drawable.ic_locked else R.drawable.ic_unlocked; val icon = if (!isPlayerLocked) R.drawable.ic_locked else R.drawable.ic_unlocked
val tooltip = if (!isPlayerLocked) R.string.tooltip_unlocked else R.string.tooltip_locked; val tooltip = if (!isPlayerLocked) {
R.string.tooltip_unlocked
} else {
R.string.tooltip_locked
}
binding.lockPlayer.setImageResource(icon) binding.lockPlayer.setImageResource(icon)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) binding.lockPlayer.trySetTooltip(context.getString(tooltip))
binding.lockPlayer.tooltipText = context.getString(tooltip)
// show/hide all the controls // show/hide all the controls
lockPlayer(isPlayerLocked) lockPlayer(isPlayerLocked)

View File

@ -1,88 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/standard_bottom_sheet"
style="@style/Widget.Material3.BottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Drag handle for accessibility -->
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:id="@+id/drag_handle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/options_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/bottom_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/rounded_ripple"
android:padding="10dp">
<ImageView
android:id="@+id/repeat"
style="@style/QueueSheetOption"
android:src="@drawable/ic_repeat" />
<ImageView
android:id="@+id/shuffle"
style="@style/QueueSheetOption"
android:src="@drawable/ic_shuffle" />
<ImageView
android:id="@+id/reverse"
style="@style/QueueSheetOption"
android:src="@drawable/ic_reverse" />
<ImageView
android:id="@+id/add_to_playlist"
style="@style/QueueSheetOption"
android:src="@drawable/ic_playlist_add" />
<ImageView
android:id="@+id/sort"
style="@style/QueueSheetOption"
android:src="@drawable/ic_sort" />
<ImageView
android:id="@+id/watch_positions_options"
style="@style/QueueSheetOption"
android:src="@drawable/ic_eye" />
<ImageView
android:id="@+id/clear_queue"
style="@style/QueueSheetOption"
android:src="@drawable/ic_close" />
<ImageView
style="@style/QueueSheetOption"
android:layout_width="0dp"
android:layout_weight="1"
android:tooltipText="Dismiss"
android:src="@drawable/ic_arrow_down" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -57,6 +57,7 @@
<ImageView <ImageView
android:id="@+id/reset_speed" android:id="@+id/reset_speed"
android:tooltipText="@string/reset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -95,6 +96,7 @@
<ImageView <ImageView
android:id="@+id/reset_pitch" android:id="@+id/reset_pitch"
android:tooltipText="@string/reset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"