remove Thumbnail class and replace it with Uri

This commit is contained in:
Christian Schabesberger 2024-09-09 18:55:58 +02:00
parent 0744d43b20
commit 5710596972
7 changed files with 23 additions and 102 deletions

View File

@ -24,12 +24,12 @@ import android.net.Uri
import androidx.media3.common.PlaybackException
import net.newpipe.newplayer.utils.Thumbnail
data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Thumbnail?)
data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Uri?)
data class MetaInfo(
val title: String,
val channelName: String,
val thumbnail: Thumbnail?,
val thumbnail: Uri?,
val lengthInS: Int
)
@ -44,7 +44,7 @@ interface MediaRepository {
suspend fun getAvailableSubtitleVariants(item: String): List<String>
suspend fun getSubtitle(item: String, variant: String): Uri
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Thumbnail>?
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>?
suspend fun getChapters(item: String): List<Chapter>
suspend fun getTimestampLink(item: String, timestampInSeconds: Long): String

View File

@ -1,32 +0,0 @@
/* NewPlayer
*
* @author Christian Schabesberger
*
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
*
* NewPlayer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*
*/
package net.newpipe.newplayer.model
import net.newpipe.newplayer.utils.Thumbnail
data class ChapterItem(
val title: String,
val offsetInMs: Long,
val thumbnail: Thumbnail
)

View File

@ -21,6 +21,7 @@
package net.newpipe.newplayer.model
import android.net.Uri
import androidx.media3.common.Player
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
@ -34,7 +35,7 @@ data class PlaylistItem(
val creator: String,
val id: String,
val uniqueId: Long,
val thumbnail: Thumbnail?,
val thumbnail: Uri?,
val lengthInS: Int
) {
companion object {
@ -84,7 +85,7 @@ suspend fun getPlaylistItemsFromExoplayer(
idLookupTable: HashMap<Long, String>
) =
with(CoroutineScope(coroutineContext)) {
(0..player.mediaItemCount - 1).map { index ->
(0..<player.mediaItemCount).map { index ->
val mediaItem = player.getMediaItemAt(index)
val uniqueId = mediaItem.mediaId.toLong()
val id = idLookupTable.get(uniqueId)

View File

@ -21,6 +21,7 @@
package net.newpipe.newplayer.ui.videoplayer.streamselect
import android.net.Uri
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
@ -55,10 +56,7 @@ import net.newpipe.newplayer.NewPlayerException
import net.newpipe.newplayer.R
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.ui.videoplayer.ITEM_CORNER_SHAPE
import net.newpipe.newplayer.utils.BitmapThumbnail
import net.newpipe.newplayer.utils.OnlineThumbnail
import net.newpipe.newplayer.utils.Thumbnail
import net.newpipe.newplayer.utils.VectorThumbnail
import net.newpipe.newplayer.utils.getLocale
import net.newpipe.newplayer.utils.getTimeStringFromMs
@ -77,7 +75,7 @@ fun isActiveChapter(chapterId: Int, chapters: List<Chapter>, playbackPosition: L
fun ChapterItem(
modifier: Modifier = Modifier,
id: Int,
thumbnail: Thumbnail?,
thumbnail: Uri?,
chapterTitle: String,
chapterStartInMs: Long,
onClicked: (Int) -> Unit,

View File

@ -1,32 +0,0 @@
/* NewPlayer
*
* @author Christian Schabesberger
*
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
*
* NewPlayer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.utils
import android.graphics.Bitmap
import android.graphics.drawable.VectorDrawable
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
interface Thumbnail
data class OnlineThumbnail(val url: String) : Thumbnail
data class BitmapThumbnail(val img: ImageBitmap) : Thumbnail
data class VectorThumbnail(val vec:ImageVector) : Thumbnail

View File

@ -25,6 +25,7 @@ import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.graphics.drawable.shapes.Shape
import android.net.Uri
import android.view.WindowManager
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.WindowInsets
@ -152,7 +153,7 @@ fun getTimeStringFromMs(
@Composable
fun Thumbnail(
modifier: Modifier = Modifier,
thumbnail: Thumbnail?,
thumbnail: Uri?,
contentDescription: String,
shape: androidx.compose.ui.graphics.Shape? = null
) {
@ -163,31 +164,17 @@ fun Thumbnail(
.clip(shape)
}
when (thumbnail) {
is OnlineThumbnail -> AsyncImage(
if (thumbnail != null) {
AsyncImage(
modifier = modifier,
model = thumbnail.url,
model = thumbnail,
contentDescription = contentDescription,
)
is BitmapThumbnail -> Image(
modifier = modifier,
bitmap = thumbnail.img,
contentDescription = contentDescription
)
is VectorThumbnail -> Image(
modifier = modifier,
imageVector = thumbnail.vec,
contentDescription = contentDescription
)
null -> Image(
} else {
Image(
modifier = modifier,
painter = painterResource(R.drawable.tiny_placeholder),
contentDescription = contentDescription
)
}
}
}

View File

@ -6,7 +6,6 @@ import androidx.media3.common.PlaybackException
import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.MediaRepository
import net.newpipe.newplayer.MetaInfo
import net.newpipe.newplayer.utils.OnlineThumbnail
import net.newpipe.newplayer.utils.Thumbnail
import okhttp3.OkHttpClient
import okhttp3.Request
@ -27,14 +26,14 @@ class TestMediaRepository(val context: Context) : MediaRepository {
"6502" -> MetaInfo(
title = context.getString(R.string.ccc_6502_title),
channelName = context.getString(R.string.ccc_6502_channel),
thumbnail = OnlineThumbnail(context.getString(R.string.ccc_6502_thumbnail)),
thumbnail = Uri.parse(context.getString(R.string.ccc_6502_thumbnail)),
lengthInS = context.resources.getInteger(R.integer.ccc_6502_length)
)
"imu" -> MetaInfo(
title = context.getString(R.string.ccc_imu_title),
channelName = context.getString(R.string.ccc_imu_channel),
thumbnail = OnlineThumbnail(context.getString(R.string.ccc_imu_thumbnail)),
thumbnail = Uri.parse(context.getString(R.string.ccc_imu_thumbnail)),
lengthInS = context.resources.getInteger(R.integer.ccc_imu_length)
)
@ -84,7 +83,7 @@ class TestMediaRepository(val context: Context) : MediaRepository {
}
)
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Thumbnail>? {
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>? {
val templateUrl = when (item) {
"6502" -> context.getString(R.string.ccc_6502_preview_thumbnails)
"imu" -> context.getString(R.string.ccc_imu_preview_thumbnails)
@ -99,11 +98,11 @@ class TestMediaRepository(val context: Context) : MediaRepository {
else -> throw Exception("Unknown stream: $item")
}
var thumbMap = HashMap<Long, Thumbnail>()
var thumbMap = HashMap<Long, Uri>()
for (i in 1..thumbCount) {
val timeStamp = (i - 1) * 10 * 1000
thumbMap.put(timeStamp.toLong(), OnlineThumbnail(String.format(templateUrl, i)))
thumbMap.put(timeStamp.toLong(), Uri.parse(String.format(templateUrl, i)))
}
return thumbMap
@ -121,14 +120,14 @@ class TestMediaRepository(val context: Context) : MediaRepository {
Chapter(
it.toLong(), chapterTitle = "Dummy Chapter at timestamp $it",
thumbnail = when (item) {
"6502" -> OnlineThumbnail(
"6502" -> Uri.parse(
String.format(
context.getString(R.string.ccc_6502_preview_thumbnails),
it / (10 * 1000)
)
)
"imu" -> OnlineThumbnail(
"imu" -> Uri.parse(
String.format(
context.getString(R.string.ccc_imu_preview_thumbnails),
it / (10 * 1000)