refactor: make audio player more accessible and redesign

This commit is contained in:
Bnyro 2023-11-05 13:49:27 +01:00
parent a593da17c1
commit f7db69fb77
3 changed files with 81 additions and 66 deletions

View File

@ -168,28 +168,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
)
}
binding.download.setOnClickListener {
val videoId = PlayingQueue.getCurrent()?.url?.toID() ?: return@setOnClickListener
val newFragment = DownloadDialog()
newFragment.arguments = bundleOf(IntentData.videoId to videoId)
newFragment.show(childFragmentManager, DownloadDialog::class.java.name)
}
binding.share.setOnClickListener {
val currentVideo = PlayingQueue.getCurrent() ?: return@setOnClickListener
val bundle = bundleOf(
IntentData.id to currentVideo.url!!.toID(),
IntentData.shareObjectType to ShareObjectType.VIDEO,
IntentData.shareData to ShareData(currentVideo = currentVideo.title)
)
val newShareDialog = ShareDialog()
newShareDialog.arguments = bundle
newShareDialog.show(childFragmentManager, null)
}
binding.chapters.setOnClickListener {
binding.openChapters.setOnClickListener {
val playerService = playerService ?: return@setOnClickListener
viewModel.chaptersLiveData.value = playerService.streams?.chapters.orEmpty()
@ -197,6 +176,12 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
.show(childFragmentManager)
}
binding.close.setOnClickListener {
activity?.unbindService(connection)
BackgroundHelper.stopBackgroundPlay(requireContext())
killFragment()
}
binding.miniPlayerClose.setOnClickListener {
activity?.unbindService(connection)
BackgroundHelper.stopBackgroundPlay(requireContext())
@ -214,6 +199,10 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
if (isPaused) playerService?.play() else playerService?.pause()
}
binding.showMore.setOnClickListener {
onLongTap()
}
// load the stream info into the UI
updateStreamInfo()
@ -371,7 +360,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
}
playerService?.onNewVideo = { streams, videoId ->
updateStreamInfo(streams.toStreamItem(videoId))
_binding?.chapters?.isVisible = streams.chapters.isNotEmpty()
_binding?.openChapters?.isVisible = streams.chapters.isNotEmpty()
}
initializeSeekBar()
}
@ -400,7 +389,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
override fun onLongTap() {
val current = PlayingQueue.getCurrent() ?: return
VideoOptionsBottomSheet()
.apply { arguments = bundleOf(IntentData.shareData to current) }
.apply { arguments = bundleOf(IntentData.streamItem to current) }
.show(childFragmentManager)
}

View File

@ -56,6 +56,22 @@
app:track="@drawable/player_switch_track"
app:trackTint="?colorControlNormal" />
<ImageView
android:id="@+id/open_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="6dp"
android:src="@drawable/ic_video" />
<ImageView
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="6dp"
android:src="@drawable/ic_close" />
</LinearLayout>
<FrameLayout
@ -259,52 +275,64 @@
<com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
app:cardCornerRadius="18dp">
android:layout_marginTop="30dp"
app:shapeAppearanceOverlay="@style/CardOnlyBottomCorners">
<LinearLayout
android:layout_width="wrap_content"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="15dp">
<ImageView
android:id="@+id/open_queue"
style="@style/AudioPlayerButton"
android:src="@drawable/ic_queue" />
<ImageView
android:id="@+id/playback_options"
style="@style/AudioPlayerButton"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleX="0.9"
android:scaleY="0.9"
android:src="@drawable/ic_speed" />
<ImageView
android:id="@+id/open_video"
style="@style/AudioPlayerButton"
android:src="@drawable/ic_video" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/open_chapters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleX="0.9"
android:scaleY="0.9"
android:src="@drawable/ic_frame" />
<ImageView
android:id="@+id/open_queue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_queue" />
</LinearLayout>
<ImageView
android:id="@+id/download"
style="@style/AudioPlayerButton"
android:src="@drawable/ic_download" />
android:id="@+id/show_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleX="0.9"
android:scaleY="0.9"
android:src="@drawable/ic_three_dots" />
<ImageView
android:id="@+id/share"
style="@style/AudioPlayerButton"
android:src="@drawable/ic_share" />
<ImageView
android:id="@+id/chapters"
style="@style/AudioPlayerButton"
android:src="@drawable/ic_frame"
android:visibility="gone" />
</LinearLayout>
</FrameLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -196,6 +196,14 @@
<item name="android:drawableTint" tools:targetApi="m">?android:attr/textColorPrimary</item>
</style>
<style name="CardOnlyBottomCorners">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">0dp</item>
<item name="cornerSizeTopLeft">0dp</item>
<item name="cornerSizeBottomRight">18dp</item>
<item name="cornerSizeBottomLeft">18dp</item>
</style>
<style name="HomeCategoryTitle">
<item name="android:layout_width">match_parent</item>
@ -209,16 +217,6 @@
</style>
<style name="AudioPlayerButton">
<item name="android:layout_width">30dp</item>
<item name="android:layout_height">30dp</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
<item name="android:layout_marginStart">10dp</item>
<item name="android:layout_marginEnd">10dp</item>
</style>
<style name="TextViewMarquee">
<item name="android:singleLine">true</item>