Skip to content

Commit c646e50

Browse files
committed
Add help dialog and improve localization
I struggled deciding whether I needed to push the `+` or the `-` buttons, so I added a help dialog. I also noticed the number strings weren't subject to localization. For some reason, I had to increase the horizontal padding in the buttons, otherwise the "p" of "Help" would be pushed to the next line. Signed-off-by: Erik De Boeck <deboeck.erik@gmail.com>
1 parent ef261f8 commit c646e50

5 files changed

Lines changed: 73 additions & 12 deletions

File tree

app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,4 @@ private void stopProgressLoop() {
704704
mHandler.removeCallbacks(progressLoop);
705705
}
706706
}
707-
}
707+
}

app/src/main/java/org/jellyfin/androidtv/ui/playback/overlay/action/SubtitleOffsetPopup.kt

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class SubtitleOffsetPopup(
4444
private var repeatAction: ((Long) -> Unit)? = null
4545

4646
private var dialog: Dialog? = null
47+
private var helpDialog: Dialog? = null
4748
val isShowing: Boolean get() = dialog?.isShowing == true
4849

4950
fun show(
@@ -112,20 +113,66 @@ class SubtitleOffsetPopup(
112113
minWidth = 0
113114
minHeight = 0
114115
minimumHeight = 0
115-
setPadding((14 * density).toInt(), (8 * density).toInt(), (14 * density).toInt(), (8 * density).toInt())
116+
setPadding((20 * density).toInt(), (8 * density).toInt(), (20 * density).toInt(), (8 * density).toInt())
116117
setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
117118
setOnClickListener {
118119
onClick()
119120
updateOffsetText()
120121
}
121122
}
122123

124+
fun showHelpPopup(anchorDialog: Dialog) {
125+
val helpContainer = TextView(context).apply {
126+
text = context.getString(R.string.lbl_subtitle_offset_help)
127+
setTextColor(Color.WHITE)
128+
setTextSize(TypedValue.COMPLEX_UNIT_SP, 15f)
129+
gravity = Gravity.CENTER
130+
background = context.getDrawable(R.drawable.subtitle_offset_panel)
131+
setPadding(panelPaddingHorizontal, panelPaddingVertical, panelPaddingHorizontal, panelPaddingVertical)
132+
}
133+
134+
helpContainer.measure(
135+
ViewGroup.LayoutParams.WRAP_CONTENT,
136+
ViewGroup.LayoutParams.WRAP_CONTENT
137+
)
138+
val helpHeight = helpContainer.measuredHeight
139+
140+
helpDialog = Dialog(context, R.style.Theme_Jellyfin_Dialog).apply {
141+
requestWindowFeature(Window.FEATURE_NO_TITLE)
142+
setContentView(helpContainer)
143+
setCanceledOnTouchOutside(false)
144+
window?.apply {
145+
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
146+
clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
147+
setDimAmount(0f)
148+
attributes = attributes.apply {
149+
width = WindowManager.LayoutParams.WRAP_CONTENT
150+
height = WindowManager.LayoutParams.WRAP_CONTENT
151+
gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
152+
y = panelTopMargin
153+
}
154+
}
155+
setOnDismissListener {
156+
anchorDialog.window?.attributes = anchorDialog.window?.attributes?.apply {
157+
y = panelTopMargin
158+
}
159+
helpDialog = null
160+
}
161+
show()
162+
163+
anchorDialog.window?.attributes = anchorDialog.window?.attributes?.apply {
164+
y = panelTopMargin + helpHeight
165+
}
166+
}
167+
}
168+
123169
val adjustmentButtons = listOf(
124-
createButton("-0.5s") { applyOffsetDelta(-OFFSET_US_500MS) },
125-
createButton("-0.1s") { applyOffsetDelta(-OFFSET_US_100MS) },
126-
createButton("+0.1s") { applyOffsetDelta(OFFSET_US_100MS) },
127-
createButton("+0.5s") { applyOffsetDelta(OFFSET_US_500MS) },
170+
createButton(formatOffset(-OFFSET_US_500MS)) { applyOffsetDelta(-OFFSET_US_500MS) },
171+
createButton(formatOffset(-OFFSET_US_100MS)) { applyOffsetDelta(-OFFSET_US_100MS) },
172+
createButton(formatOffset(OFFSET_US_100MS)) { applyOffsetDelta(OFFSET_US_100MS) },
173+
createButton(formatOffset(OFFSET_US_500MS)) { applyOffsetDelta(OFFSET_US_500MS) },
128174
createButton(context.getString(R.string.lbl_reset)) { resetOffset() },
175+
createButton(context.getString(R.string.lbl_help)) { showHelpPopup(dialog!!) },
129176
)
130177
adjustmentButtons.forEachIndexed { index, button ->
131178
adjustmentRow.addView(
@@ -149,6 +196,12 @@ class SubtitleOffsetPopup(
149196
},
150197
)
151198

199+
container.measure(
200+
ViewGroup.LayoutParams.WRAP_CONTENT,
201+
ViewGroup.LayoutParams.WRAP_CONTENT
202+
)
203+
val mainHeight = container.measuredHeight
204+
152205
repeatAction = { deltaUs -> applyOffsetDelta(deltaUs) }
153206

154207
dialog = Dialog(context, R.style.Theme_Jellyfin_Dialog).apply {
@@ -186,6 +239,7 @@ class SubtitleOffsetPopup(
186239

187240
fun dismiss() {
188241
dialog?.dismiss()
242+
helpDialog?.dismiss()
189243
}
190244

191245
private fun handleRepeatKey(event: KeyEvent, deltaUs: Long): Boolean {
@@ -219,6 +273,6 @@ class SubtitleOffsetPopup(
219273
private fun formatOffset(offsetUs: Long): String {
220274
val seconds = offsetUs / 1_000_000.0
221275
val safeSeconds = if (abs(seconds) < 0.05) 0.0 else seconds
222-
return String.format(Locale.US, "%+.1fs", safeSeconds)
276+
return String.format(Locale.getDefault(), "%+.1f s", safeSeconds)
223277
}
224278
}

app/src/main/java/org/jellyfin/androidtv/ui/player/video/VideoPlayerControls.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private fun PositionText(
254254
private fun formatSubtitleOffset(offset: Duration): String {
255255
val seconds = offset.inWholeMilliseconds / 1000.0
256256
val safeSeconds = if (kotlin.math.abs(seconds) < 0.05) 0.0 else seconds
257-
return String.format(java.util.Locale.US, "%+.1fs", safeSeconds)
257+
return String.format(java.util.Locale.getDefault(), "%+.1f s", safeSeconds)
258258
}
259259

260260
@Composable
@@ -276,16 +276,16 @@ private fun SubtitleOffsetControls(
276276

277277
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
278278
Button(onClick = { playbackManager.state.adjustSubtitleTimingOffset((-500).milliseconds) }) {
279-
Text("-0.5s")
279+
Text(formatSubtitleOffset((-500).milliseconds))
280280
}
281281
Button(onClick = { playbackManager.state.adjustSubtitleTimingOffset((-100).milliseconds) }) {
282-
Text("-0.1s")
282+
Text(formatSubtitleOffset((-100).milliseconds))
283283
}
284284
Button(onClick = { playbackManager.state.adjustSubtitleTimingOffset(100.milliseconds) }) {
285-
Text("+0.1s")
285+
Text(formatSubtitleOffset(100.milliseconds))
286286
}
287287
Button(onClick = { playbackManager.state.adjustSubtitleTimingOffset(500.milliseconds) }) {
288-
Text("+0.5s")
288+
Text(formatSubtitleOffset(500.milliseconds))
289289
}
290290
Button(onClick = { playbackManager.state.resetSubtitleTimingOffset() }) {
291291
Text(stringResource(R.string.lbl_reset))

app/src/main/res/values-nl/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,9 @@
660660
<string name="playback_info_channels">Kanalen: %1$d</string>
661661
<string name="playback_info_video_range">Beeldbereik: %1$s</string>
662662
<string name="playback_info_transcoding_note">Server transcodeert dit bestand</string>
663+
<string name="lbl_subtitle_offset">Ondertitelvertraging</string>
664+
<string name="lbl_subtitle_offset_current">Ondertitelvertraging %1$s</string>
665+
<string name="lbl_reset">Herstel</string>
666+
<string name="lbl_help">Hulp</string>
667+
<string name="lbl_subtitle_offset_help">Ondertitels te laat: gebruik − | Ondertitels te vroeg: gebruik +</string>
663668
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@
623623
<string name="lbl_subtitle_offset">Subtitle offset</string>
624624
<string name="lbl_subtitle_offset_current">Subtitle offset %1$s</string>
625625
<string name="lbl_reset">Reset</string>
626+
<string name="lbl_help">Help</string>
627+
<string name="lbl_subtitle_offset_help">Subtitles too late: use − | Subtitles too early: use +</string>
626628
<plurals name="seconds">
627629
<item quantity="one">%1$s second</item>
628630
<item quantity="other">%1$s seconds</item>

0 commit comments

Comments
 (0)