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
|
||||
data class ChapterSegment(
|
||||
val title: String? = null,
|
||||
val image: String? = null,
|
||||
val start: Long? = null
|
||||
val title: String,
|
||||
val image: String,
|
||||
val start: Long
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ class ChaptersAdapter(
|
||||
holder.binding.apply {
|
||||
ImageHelper.loadImage(chapter.image, chapterImage)
|
||||
chapterTitle.text = chapter.title
|
||||
timeStamp.text = chapter.start?.let { DateUtils.formatElapsedTime(it) }
|
||||
timeStamp.text = DateUtils.formatElapsedTime(chapter.start)
|
||||
|
||||
val color = if (selectedPosition == position) {
|
||||
ThemeHelper.getThemeColor(root.context, android.R.attr.colorControlHighlight)
|
||||
@ -40,7 +40,7 @@ class ChaptersAdapter(
|
||||
|
||||
root.setOnClickListener {
|
||||
updateSelectedPosition(position)
|
||||
val chapterStart = chapter.start!! * 1000 // s -> ms
|
||||
val chapterStart = chapter.start * 1000 // s -> ms
|
||||
exoPlayer.seekTo(chapterStart)
|
||||
}
|
||||
}
|
||||
|
@ -1183,13 +1183,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
// enable the chapters dialog in the player
|
||||
val titles = chapters.map { chapter ->
|
||||
"(${chapter.start?.let { DateUtils.formatElapsedTime(it) }}) ${chapter.title}"
|
||||
"(${DateUtils.formatElapsedTime(chapter.start)}) ${chapter.title}"
|
||||
}
|
||||
playerBinding.chapterLL.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.chapters)
|
||||
.setItems(titles.toTypedArray()) { _, index ->
|
||||
exoPlayer.seekTo(chapters[index].start!! * 1000)
|
||||
exoPlayer.seekTo(chapters[index].start * 1000)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
@ -1206,7 +1206,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
binding.player.postDelayed(this::setCurrentChapterName, 100)
|
||||
|
||||
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
|
||||
if (chapterName != playerBinding.chapterName.text) {
|
||||
@ -1222,7 +1222,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
*/
|
||||
private fun getCurrentChapterIndex(): Int? {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user