Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {

defaultConfig {
applicationId = "dev.typetype.android"
versionCode = 11114
versionName = "1.12.0-beta.3"
versionCode = 11115
versionName = "1.13.0-beta.1"
}

signingConfigs {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/dev/typetype/android/AppNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ fun AppNavHost(
onPlayVideo = onPlayVideo,
onOpenChannel = onOpenChannel,
onClosePlayback = mainViewModel::closePlayback,
onOpenPlaylist = { playlistUrl ->
navController.navigate(PublicPlaylistRoute(playlistUrl)) { launchSingleTop = true }
},
) { innerModifier ->
AdaptiveSettingsHost(
navController = navController,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/dev/typetype/android/AppShell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fun AppShell(
onPlayVideo: (videoUrl: String) -> Unit,
onOpenChannel: (channelUrl: String) -> Unit,
onClosePlayback: () -> Unit,
onOpenPlaylist: (playlistUrl: String) -> Unit = {},
content: @Composable (Modifier) -> Unit,
) {
val backStackEntry by navController.currentBackStackEntryAsState()
Expand All @@ -97,7 +98,7 @@ fun AppShell(
currentDestination?.hasRoute<NotificationsRoute>() == true
)
var selectedTabRoute by rememberSaveable { mutableStateOf<String?>(null) }
var isPlayerFullscreen by remember { mutableStateOf(false) }
var isPlayerFullscreen by rememberSaveable { mutableStateOf(false) }
var bottomNavigationHeight by remember { mutableStateOf(0.dp) }
val density = LocalDensity.current
val imeVisible = WindowInsets.ime.getBottom(density) > 0
Expand Down Expand Up @@ -223,6 +224,7 @@ fun AppShell(
mediaController = mediaController,
accessibleControlsEnabled = accessiblePlayerControls,
onOpenChannel = onOpenChannel,
onOpenPlaylist = onOpenPlaylist,
onOpenAccounts = onOpenAccounts,
onClosePlayback = onClosePlayback,
onTransitionProgressChange = { progress ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.typetype.android.data.network.dto.toDomainVideo
import dev.typetype.android.data.network.requireSuccessfulResponse
import dev.typetype.android.domain.channel.Channel
import dev.typetype.android.domain.channel.ChannelPage
import dev.typetype.android.domain.channel.ChannelPlaylistKind
import dev.typetype.android.domain.channel.ChannelPlaylistsPage
import dev.typetype.android.domain.channel.ChannelQuery
import dev.typetype.android.domain.channel.ChannelRepository
Expand Down Expand Up @@ -57,19 +58,21 @@ class ChannelRepositoryImpl @Inject constructor(
}
}
},
hasCourses = body.hasCourses,
),
nextPage = body.nextpage,
)
}

override suspend fun loadPlaylists(
channelUrl: String,
kind: ChannelPlaylistKind,
nextPage: String?,
): Result<ChannelPlaylistsPage> = catching {
val scope = activeAccountScope.require()
val api = apiHolder.require(scope)
val response = withContext(Dispatchers.IO) {
api.channelPlaylists(channelUrl, nextPage)
api.channelPlaylists(channelUrl, nextPage, kind.apiValue())
}
response.requireSuccessfulResponse()
val body = response.body() ?: error("Empty channel playlists body")
Expand All @@ -92,6 +95,11 @@ private fun ChannelSort.apiValue(): String = when (this) {
ChannelSort.Oldest -> "oldest"
}

private fun ChannelPlaylistKind.apiValue(): String? = when (this) {
ChannelPlaylistKind.Playlists -> null
ChannelPlaylistKind.Courses -> "courses"
}

private fun SearchPlaylistDto.toDomain() = SearchPlaylist(
id = id,
title = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface TypeTypeSearchApi {
suspend fun channelPlaylists(
@Query("url") url: String,
@Query("nextpage") nextpage: String? = null,
@Query("tab") tab: String? = null,
): Response<ChannelPlaylistsResponse>

@GET("suggestions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class ChannelResponse(
val isVerified: Boolean = false,
val videos: List<VideoItem> = emptyList(),
val nextpage: String? = null,
val hasCourses: Boolean = false,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.typetype.android.data.network.dto

import kotlinx.serialization.Serializable

@Serializable
data class EndScreenItem(
val id: String = "",
val type: String = "",
val title: String = "",
val url: String = "",
val thumbnailUrl: String = "",
val startMs: Long = 0L,
val endMs: Long = 0L,
val left: Double = 0.0,
val top: Double = 0.0,
val width: Double = 0.0,
val aspectRatio: Double = 0.0,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ data class StreamResponse(
val subtitles: List<SubtitleItem> = emptyList(),
val previewFrames: List<PreviewFrameItem> = emptyList(),
val sponsorBlockSegments: List<SponsorBlockSegmentItem> = emptyList(),
val endScreenElements: List<EndScreenItem> = emptyList(),
val relatedStreams: List<VideoItem> = emptyList(),
val publishedAt: Long? = null,
val isLive: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class UserSettingsDto(
val hideHomeRecommendations: Boolean = false,
val hideContinueWatching: Boolean = false,
val hideRelatedVideos: Boolean = false,
val hideEndScreens: Boolean = false,
val hideComments: Boolean = false,
val hideShorts: Boolean = false,
val hideSubscriptionLiveStreams: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.typetype.android.data.stream

import dev.typetype.android.data.network.dto.EndScreenItem
import dev.typetype.android.domain.stream.EndScreenElement
import dev.typetype.android.domain.stream.EndScreenElementType

internal fun EndScreenItem.toDomainEndScreenElement(): EndScreenElement? {
val elementType = when (type) {
"video" -> EndScreenElementType.Video
"playlist" -> EndScreenElementType.Playlist
"channel" -> EndScreenElementType.Channel
"website" -> EndScreenElementType.Website
else -> return null
}
if (id.isBlank() || url.isBlank() || endMs <= startMs) return null
val placed = left in 0.0..1.0 && top in 0.0..1.0 && left < 1.0 && top < 1.0
if (!placed || !(width > 0.0) || !(aspectRatio > 0.0)) return null
return EndScreenElement(
id = id,
type = elementType,
title = title,
url = url,
thumbnailUrl = thumbnailUrl,
startMs = startMs,
endMs = endMs,
left = left.toFloat(),
top = top.toFloat(),
width = width.toFloat(),
aspectRatio = aspectRatio.toFloat(),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.typetype.android.data.stream

import dev.typetype.android.data.network.dto.SponsorBlockSegmentItem
import dev.typetype.android.domain.stream.SponsorAction
import dev.typetype.android.domain.stream.SponsorBlockSegment
import dev.typetype.android.domain.stream.SponsorCategory
import kotlin.math.roundToLong

internal fun SponsorBlockSegmentItem.toDomainSponsorBlockSegment(
durationSeconds: Long,
): SponsorBlockSegment? {
if (!startTime.isFinite() || !endTime.isFinite()) return null
val scale = if (durationSeconds > 0L && endTime > durationSeconds + 30L) 1.0 else 1_000.0
val startMs = (startTime * scale).roundToLong().coerceAtLeast(0L)
val endMs = (endTime * scale).roundToLong().coerceAtLeast(0L)
if (endMs <= startMs) return null
return SponsorBlockSegment(
startMs = startMs,
endMs = endMs,
category = SponsorCategory.fromKey(category),
action = SponsorAction.fromKey(action),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import dev.typetype.android.core.url.percentEncode
import dev.typetype.android.data.network.PlaybackNetworkObserver
import dev.typetype.android.data.network.dto.AudioStreamItem
import dev.typetype.android.data.network.dto.PreviewFrameItem
import dev.typetype.android.data.network.dto.SponsorBlockSegmentItem
import dev.typetype.android.data.network.dto.StreamResponse
import dev.typetype.android.data.network.dto.StreamSegmentItem
import dev.typetype.android.data.network.dto.SubtitleItem
import dev.typetype.android.data.network.dto.toDomainVideo
import dev.typetype.android.data.network.dto.VideoStreamItem
import dev.typetype.android.data.network.serverResponseException
import dev.typetype.android.domain.stream.Chapter
import dev.typetype.android.domain.stream.SponsorAction
import dev.typetype.android.domain.stream.SponsorBlockSegment
import dev.typetype.android.domain.stream.SponsorCategory
import dev.typetype.android.domain.stream.Stream
import dev.typetype.android.domain.stream.StreamPlaybackContract
import dev.typetype.android.domain.stream.StreamAudioSource
Expand All @@ -29,7 +25,6 @@ import dev.typetype.android.domain.stream.isServerSabrVideoFormat
import dev.typetype.android.domain.server.ServerRepository
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.roundToLong
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -190,6 +185,7 @@ internal class StreamRepositoryImpl @Inject constructor(
it.toDomainSponsorBlockSegment(duration)
},
chapters = streamSegments.map { it.toChapter() },
endScreenElements = endScreenElements.mapNotNull { it.toDomainEndScreenElement() },
relatedStreams = relatedStreams.map { it.toDomainVideo() },
isLive = isLive,
isPostLive = isPostLive,
Expand Down Expand Up @@ -284,22 +280,6 @@ internal class StreamRepositoryImpl @Inject constructor(

}

internal fun SponsorBlockSegmentItem.toDomainSponsorBlockSegment(
durationSeconds: Long,
): SponsorBlockSegment? {
if (!startTime.isFinite() || !endTime.isFinite()) return null
val scale = if (durationSeconds > 0L && endTime > durationSeconds + 30L) 1.0 else 1_000.0
val startMs = (startTime * scale).roundToLong().coerceAtLeast(0L)
val endMs = (endTime * scale).roundToLong().coerceAtLeast(0L)
if (endMs <= startMs) return null
return SponsorBlockSegment(
startMs = startMs,
endMs = endMs,
category = SponsorCategory.fromKey(category),
action = SponsorAction.fromKey(action),
)
}

internal suspend fun <T> cancellableStreamResult(
request: suspend () -> T,
): Result<T> = try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal fun UserSettingsDto.toDomain(serverBaseUrl: String? = null): UserSettin
hideHomeRecommendations = hideHomeRecommendations,
hideContinueWatching = hideContinueWatching,
hideRelatedVideos = hideRelatedVideos,
hideEndScreens = hideEndScreens,
hideComments = hideComments,
hideShorts = hideShorts,
hideSubscriptionLiveStreams = hideSubscriptionLiveStreams == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ internal fun UserSettings.patchFrom(previous: UserSettings): JsonObject = buildJ
if (hideRelatedVideos != previous.hideRelatedVideos) {
put("hideRelatedVideos", hideRelatedVideos)
}
if (hideEndScreens != previous.hideEndScreens) put("hideEndScreens", hideEndScreens)
if (hideComments != previous.hideComments) put("hideComments", hideComments)
if (hideShorts != previous.hideShorts) put("hideShorts", hideShorts)
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -83,7 +84,25 @@ class ChannelPageContractTest {
assertEquals("/channel/playlists", request.requestUrl?.encodedPath)
assertEquals("https://youtube.com/@channel", request.requestUrl?.queryParameter("url"))
assertEquals(cursor, request.requestUrl?.queryParameter("nextpage"))
assertNull(request.requestUrl?.queryParameter("tab"))
assertEquals("Playlist", response.body()?.playlists?.single()?.title)
assertEquals("more", response.body()?.nextpage)
}

@Test
fun channelCoursesAreListedThroughTheCoursesTab() = runBlocking {
server.enqueue(
MockResponse()
.setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody("""{"playlists":[{"id":"c","title":"Course","url":"https://youtube.com/playlist?list=c"}]}"""),
)

val response = api.channelPlaylists(url = "https://youtube.com/@channel", tab = "courses")

val request = server.takeRequest()
assertEquals("/channel/playlists", request.requestUrl?.encodedPath)
assertEquals("courses", request.requestUrl?.queryParameter("tab"))
assertEquals("Course", response.body()?.playlists?.single()?.title)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.typetype.android.data.stream

import dev.typetype.android.data.network.dto.EndScreenItem
import dev.typetype.android.domain.stream.EndScreenElementType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class EndScreenMapperTest {
private fun item(
type: String = "video",
url: String = "https://www.youtube.com/watch?v=x",
startMs: Long = 590_000,
endMs: Long = 610_000,
left: Double = 0.65,
width: Double = 0.32,
aspectRatio: Double = 1.77,
) = EndScreenItem("id", type, "Title", url, "https://i.ytimg.com/a.jpg", startMs, endMs, left, 0.13, width, aspectRatio)

@Test
fun `maps every element type the server sends`() {
assertEquals(EndScreenElementType.Video, item("video").toDomainEndScreenElement()?.type)
assertEquals(EndScreenElementType.Playlist, item("playlist").toDomainEndScreenElement()?.type)
assertEquals(EndScreenElementType.Channel, item("channel").toDomainEndScreenElement()?.type)
assertEquals(EndScreenElementType.Website, item("website").toDomainEndScreenElement()?.type)
}

@Test
fun `keeps timing and placement`() {
val element = requireNotNull(item().toDomainEndScreenElement())

assertEquals(590_000L, element.startMs)
assertEquals(610_000L, element.endMs)
assertEquals(0.65f, element.left, 0.0001f)
assertEquals(0.13f, element.top, 0.0001f)
assertEquals(0.32f, element.width, 0.0001f)
assertEquals("https://i.ytimg.com/a.jpg", element.thumbnailUrl)
}

@Test
fun `drops elements it cannot place or open`() {
assertNull(item(type = "merch").toDomainEndScreenElement())
assertNull(item(url = "").toDomainEndScreenElement())
assertNull(item(startMs = 610_000, endMs = 610_000).toDomainEndScreenElement())
assertNull(item(left = 1.0).toDomainEndScreenElement())
assertNull(item(left = -0.1).toDomainEndScreenElement())
assertNull(item(width = 0.0).toDomainEndScreenElement())
assertNull(item(aspectRatio = 0.0).toDomainEndScreenElement())
assertNull(item(aspectRatio = Double.NaN).toDomainEndScreenElement())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class UserSettingsPatchTest {
hideHomeRecommendations = true,
hideContinueWatching = true,
hideRelatedVideos = true,
hideEndScreens = true,
hideComments = true,
hideShorts = true,
disableWatchHistory = true,
Expand Down Expand Up @@ -222,6 +223,7 @@ class UserSettingsPatchTest {
"hideHomeRecommendations",
"hideContinueWatching",
"hideRelatedVideos",
"hideEndScreens",
"hideComments",
"hideShorts",
"disableWatchHistory",
Expand Down Expand Up @@ -274,6 +276,7 @@ class UserSettingsPatchTest {
"hideHomeRecommendations": true,
"hideContinueWatching": true,
"hideRelatedVideos": true,
"hideEndScreens": true,
"hideComments": true,
"hideShorts": true,
"disableWatchHistory": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ enum class ChannelSort {
Oldest,
}

enum class ChannelPlaylistKind {
Playlists,
Courses,
}

data class ChannelQuery(
val channelUrl: String,
val sort: ChannelSort = ChannelSort.Latest,
Expand All @@ -24,6 +29,7 @@ data class Channel(
val subscriberCount: Long,
val verified: Boolean,
val videos: List<Video>,
val hasCourses: Boolean = false,
)

data class ChannelPage(
Expand Down
Loading