mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #3391 from Isira-Seneviratne/ChapterSegment_non_null
Make ChapterSegment parameters non-null.
This commit is contained in:
commit
72dc5ce7d1
@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ChapterSegment(
|
data class ChapterSegment(
|
||||||
val title: String? = null,
|
val title: String,
|
||||||
val image: String? = null,
|
val image: String,
|
||||||
val start: Long? = null
|
val start: Long
|
||||||
)
|
)
|
||||||
|
@ -29,7 +29,7 @@ class ChaptersAdapter(
|
|||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
ImageHelper.loadImage(chapter.image, chapterImage)
|
ImageHelper.loadImage(chapter.image, chapterImage)
|
||||||
chapterTitle.text = chapter.title
|
chapterTitle.text = chapter.title
|
||||||
timeStamp.text = chapter.start?.let { DateUtils.formatElapsedTime(it) }
|
timeStamp.text = DateUtils.formatElapsedTime(chapter.start)
|
||||||
|
|
||||||
val color = if (selectedPosition == position) {
|
val color = if (selectedPosition == position) {
|
||||||
ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight)
|
ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight)
|
||||||
@ -40,7 +40,7 @@ class ChaptersAdapter(
|
|||||||
|
|
||||||
root.setOnClickListener {
|
root.setOnClickListener {
|
||||||
updateSelectedPosition(position)
|
updateSelectedPosition(position)
|
||||||
val chapterStart = chapter.start!! * 1000 // s -> ms
|
val chapterStart = chapter.start * 1000 // s -> ms
|
||||||
exoPlayer.seekTo(chapterStart)
|
exoPlayer.seekTo(chapterStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1183,13 +1183,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
// enable the chapters dialog in the player
|
// enable the chapters dialog in the player
|
||||||
val titles = chapters.map { chapter ->
|
val titles = chapters.map { chapter ->
|
||||||
"(${chapter.start?.let { DateUtils.formatElapsedTime(it) }}) ${chapter.title}"
|
"(${DateUtils.formatElapsedTime(chapter.start)}) ${chapter.title}"
|
||||||
}
|
}
|
||||||
playerBinding.chapterLL.setOnClickListener {
|
playerBinding.chapterLL.setOnClickListener {
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.chapters)
|
.setTitle(R.string.chapters)
|
||||||
.setItems(titles.toTypedArray()) { _, index ->
|
.setItems(titles.toTypedArray()) { _, index ->
|
||||||
exoPlayer.seekTo(chapters[index].start!! * 1000)
|
exoPlayer.seekTo(chapters[index].start * 1000)
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
@ -1206,7 +1206,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
binding.player.postDelayed(this::setCurrentChapterName, 100)
|
binding.player.postDelayed(this::setCurrentChapterName, 100)
|
||||||
|
|
||||||
val chapterIndex = getCurrentChapterIndex() ?: return
|
val chapterIndex = getCurrentChapterIndex() ?: return
|
||||||
val chapterName = chapters[chapterIndex].title?.trim()
|
val chapterName = chapters[chapterIndex].title.trim()
|
||||||
|
|
||||||
// change the chapter name textView text to the chapterName
|
// change the chapter name textView text to the chapterName
|
||||||
if (chapterName != playerBinding.chapterName.text) {
|
if (chapterName != playerBinding.chapterName.text) {
|
||||||
@ -1222,7 +1222,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
*/
|
*/
|
||||||
private fun getCurrentChapterIndex(): Int? {
|
private fun getCurrentChapterIndex(): Int? {
|
||||||
val currentPosition = exoPlayer.currentPosition / 1000
|
val currentPosition = exoPlayer.currentPosition / 1000
|
||||||
return chapters.indexOfLast { currentPosition >= it.start!! }.takeIf { it >= 0 }
|
return chapters.indexOfLast { currentPosition >= it.start }.takeIf { it >= 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMediaSource(uri: Uri, mimeType: String) {
|
private fun setMediaSource(uri: Uri, mimeType: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user