Skip to content

Commit 868ffb9

Browse files
committed
feat(ui): improve appearance of video player info
1 parent 2766ac8 commit 868ffb9

5 files changed

Lines changed: 47 additions & 83 deletions

File tree

app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
444444
start()
445445
}
446446
}
447-
playerBinding?.playerVideoTitleRez?.let {
448-
ObjectAnimator.ofFloat(it, "translationY", titleMove).apply {
449-
duration = 200
450-
start()
451-
}
452-
}
447+
453448
playerBinding?.playerVideoInfo?.let {
454449
ObjectAnimator.ofFloat(it, "translationY", titleMove).apply {
455450
duration = 200
@@ -1001,7 +996,6 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
1001996
// video_bar.startAnimation(fadeAnimation)
1002997

1003998
// TITLE
1004-
playerVideoTitleRez.startAnimation(fadeAnimation)
1005999
playerVideoInfo.startAnimation(fadeAnimation)
10061000
playerEpisodeFiller.startAnimation(fadeAnimation)
10071001
playerVideoTitleHolder.startAnimation(fadeAnimation)

app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class GeneratorPlayer : FullScreenPlayer() {
512512
}
513513
// setEpisodes(viewModel.getAllMeta() ?: emptyList())
514514
isActive = true
515-
setPlayerDimen(null)
515+
updatePlayerInfo(reset = true)
516516
setTitle()
517517
if (!sameEpisode)
518518
hasRequestedStamps = false
@@ -1698,7 +1698,7 @@ class GeneratorPlayer : FullScreenPlayer() {
16981698

16991699
return sortSubs(subtitles).firstOrNull { it.matchesLanguageCode(langCode) }
17001700
}
1701-
1701+
17021702
private fun autoSelectFromSettings(): Boolean {
17031703
// auto select subtitle based on settings
17041704
val langCode = preferredAutoSelectSubtitles
@@ -1831,33 +1831,26 @@ class GeneratorPlayer : FullScreenPlayer() {
18311831
playerBinding?.offlinePin?.isVisible = lastUsedGenerator is DownloadFileGenerator
18321832
}
18331833

1834-
@SuppressLint("SetTextI18n")
1835-
fun setPlayerDimen(widthHeight: Pair<Int, Int>?) {
1836-
val resolution = widthHeight?.let { "${it.first}x${it.second}" }
1837-
val name = currentSelectedLink?.first?.name ?: currentSelectedLink?.second?.name
1838-
val title = getHeaderName()
1839-
1840-
val result = listOfNotNull(
1841-
title?.takeIf { showTitle && it.isNotBlank() },
1842-
name?.takeIf { showName && it.isNotBlank() },
1843-
resolution?.takeIf { showResolution && it.isNotBlank() },
1844-
).joinToString(" - ")
1845-
1846-
playerBinding?.playerVideoTitleRez?.apply {
1847-
text = result
1848-
isVisible = result.isNotBlank()
1834+
/**
1835+
* Show the current playback information (e.g. resolution, codec) in the player info text view.
1836+
*
1837+
* If [reset] is set to `true`, the text view will be cleared instead.
1838+
*/
1839+
private fun updatePlayerInfo(reset: Boolean = false) {
1840+
if (reset) {
1841+
playerBinding?.playerVideoInfo?.text = ""
1842+
playerBinding?.playerVideoInfo?.isGone = true
1843+
return
18491844
}
1850-
}
18511845

1852-
private fun updatePlayerInfo() {
18531846
val tracks = player.getVideoTracks()
18541847

18551848
val videoTrack = tracks.currentVideoTrack
18561849
val audioTrack = tracks.currentAudioTrack
18571850

1858-
val ctx = context ?: return
1859-
val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
1860-
showMediaInfo = prefs.getBoolean(ctx.getString(R.string.show_media_info_key), false)
1851+
val resolution = videoTrack?.let { "${it.width}x${it.height}" }
1852+
val source = currentSelectedLink?.first?.name ?: currentSelectedLink?.second?.name
1853+
val headerName = getHeaderName().orEmpty()
18611854

18621855
val videoCodec = videoTrack?.sampleMimeType?.substringAfterLast('/')?.uppercase()
18631856
val audioCodec = audioTrack?.sampleMimeType?.substringAfterLast('/')?.uppercase()
@@ -1866,17 +1859,22 @@ class GeneratorPlayer : FullScreenPlayer() {
18661859
fromTagToLanguageName(audioTrack?.language)?.let { "[$it]" }
18671860
).joinToString(" ")
18681861

1869-
val stats = arrayOf(videoCodec, audioCodec, language).filter { !it.isNullOrBlank() }.joinToString("")
1862+
val stats = listOfNotNull(
1863+
source.takeIf { showTitle },
1864+
headerName.takeIf { showName },
1865+
resolution.takeIf { showResolution }
1866+
) + arrayOf(videoCodec, audioCodec, language)
1867+
.takeIf { showMediaInfo }.orEmpty()
18701868

18711869
playerBinding?.playerVideoInfo?.apply {
1872-
text = stats
1873-
isVisible = showMediaInfo && stats.isNotBlank()
1870+
text = stats.filter { !it.isNullOrBlank() }.joinToString("")
1871+
isVisible = text.isNotEmpty()
18741872
}
18751873
}
18761874

18771875
override fun playerDimensionsLoaded(width: Int, height: Int) {
18781876
super.playerDimensionsLoaded(width, height)
1879-
setPlayerDimen(width to height)
1877+
updatePlayerInfo()
18801878
}
18811879

18821880
private fun unwrapBundle(savedInstanceState: Bundle?) {
@@ -2066,6 +2064,7 @@ class GeneratorPlayer : FullScreenPlayer() {
20662064

20672065
context?.let { ctx ->
20682066
val settingsManager = PreferenceManager.getDefaultSharedPreferences(ctx)
2067+
showTitle = settingsManager.getBoolean(ctx.getString(R.string.show_title_key), true)
20692068
showName = settingsManager.getBoolean(ctx.getString(R.string.show_name_key), true)
20702069
showResolution = settingsManager.getBoolean(ctx.getString(R.string.show_resolution_key), true)
20712070
showMediaInfo = settingsManager.getBoolean(ctx.getString(R.string.show_media_info_key), false)

app/src/main/res/layout/player_custom_layout.xml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,15 @@
146146
app:layout_constraintLeft_toLeftOf="parent"
147147
app:layout_constraintTop_toTopOf="parent">
148148

149-
<TextView
150-
android:id="@+id/player_video_title_rez"
151-
android:layout_width="match_parent"
152-
android:layout_height="wrap_content"
153-
android:layout_marginBottom="2.5dp"
154-
android:gravity="center"
155-
android:textColor="@color/white"
156-
tools:text="1920x1080" />
157-
158-
159149
<TextView
160150
android:id="@+id/player_video_info"
161151
android:layout_width="match_parent"
162152
android:layout_height="wrap_content"
153+
android:layout_marginBottom="6dp"
163154
android:gravity="center"
164-
android:layout_marginBottom="2.5dp"
165-
android:textColor="@color/white"
166-
android:visibility="gone"
167-
tools:text="HEVC" />
155+
android:textColor="@color/grayTextColor"
156+
android:textSize="12sp"
157+
tools:text="1920x1080 • HDR10 • HEVC" />
168158

169159
<LinearLayout
170160
android:id="@+id/player_video_title_holder"

app/src/main/res/layout/player_custom_layout_tv.xml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,30 +307,17 @@
307307
android:layout_gravity="start"/>
308308
</LinearLayout>
309309

310-
<TextView
311-
android:id="@+id/player_video_title_rez"
312-
android:layout_width="wrap_content"
313-
android:layout_height="wrap_content"
314-
android:layout_gravity="end"
315-
android:gravity="end"
316-
android:maxWidth="600dp"
317-
android:textAlignment="viewEnd"
318-
android:textColor="@color/white"
319-
android:textSize="16sp"
320-
tools:text="1920x1080" />
321-
322310
<TextView
323311
android:id="@+id/player_video_info"
324312
android:layout_width="wrap_content"
325313
android:layout_height="wrap_content"
326314
android:layout_marginStart="6dp"
315+
android:layout_marginTop="6dp"
327316
android:layout_marginBottom="2.5dp"
328-
android:textColor="@color/white"
329-
android:textSize="16sp"
330-
android:visibility="gone"
317+
android:textColor="@color/grayTextColor"
318+
android:textSize="12sp"
331319
android:layout_gravity="end"
332-
tools:text="HDR10 • HEVC" />
333-
320+
tools:text="1920x1080 • HDR10 • HEVC" />
334321

335322
<FrameLayout
336323
android:id="@+id/player_episode_filler_holder"

app/src/main/res/layout/trailer_custom_layout.xml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
android:id="@+id/player_top_holder"
8787
android:layout_width="match_parent"
8888
android:layout_height="match_parent"
89-
android:visibility="gone">
89+
>
9090

9191
<LinearLayout
9292
android:layout_width="match_parent"
@@ -96,6 +96,17 @@
9696
android:layout_marginEnd="32dp"
9797
android:orientation="vertical">
9898

99+
<TextView
100+
android:id="@+id/player_video_info"
101+
android:layout_width="match_parent"
102+
android:layout_height="wrap_content"
103+
android:gravity="center"
104+
android:layout_marginBottom="6dp"
105+
android:textColor="@color/grayTextColor"
106+
android:textSize="12sp"
107+
android:ellipsize="end"
108+
tools:text="1920x1080 • HDR10 • HEVC" />
109+
99110
<LinearLayout
100111
android:id="@+id/player_video_title_holder"
101112
android:layout_width="match_parent"
@@ -111,16 +122,7 @@
111122
android:textSize="16sp"
112123
android:textStyle="bold"
113124
tools:text="Hello world" />
114-
<TextView
115-
android:id="@+id/player_video_info"
116-
android:layout_width="wrap_content"
117-
android:layout_height="wrap_content"
118-
android:layout_marginStart="6dp"
119-
android:layout_marginBottom="2.5dp"
120-
android:textColor="@color/white"
121-
android:textSize="10sp"
122-
android:visibility="gone"
123-
tools:text="HDR10 • HEVC" />
125+
124126
<ImageView
125127
android:id="@+id/offline_pin"
126128
android:layout_width="16dp"
@@ -131,14 +133,6 @@
131133
tools:visibility="visible"
132134
android:layout_gravity="center"/>
133135
</LinearLayout>
134-
<TextView
135-
android:id="@+id/player_video_title_rez"
136-
android:layout_width="match_parent"
137-
android:layout_height="wrap_content"
138-
android:gravity="end"
139-
android:textColor="@color/white"
140-
android:textSize="16sp"
141-
tools:text="1920x1080" />
142136

143137
<FrameLayout
144138
android:id="@+id/player_episode_filler_holder"

0 commit comments

Comments
 (0)