Merge pull request #3391 from Isira-Seneviratne/ChapterSegment_non_null

Make ChapterSegment parameters non-null.
This commit is contained in:
Bnyro 2023-03-26 10:34:51 +02:00 committed by GitHub
commit 72dc5ce7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -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
)

View File

@ -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)
}
}

View File

@ -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) {