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
29 changes: 9 additions & 20 deletions .github/workflows/android-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ env:

jobs:
release:
runs-on: ubuntu-latest
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && fromJSON('["self-hosted","stack-android"]') || 'ubuntu-latest' }}
timeout-minutes: 50
outputs:
version: ${{ steps.version.outputs.version }}
Expand Down Expand Up @@ -135,31 +135,20 @@ jobs:
printf 'keyPassword=%s\n' "$ANDROID_KEY_PASSWORD"
} > keystore.properties

- name: Verify and build beta release
timeout-minutes: 40
- name: Build beta release
timeout-minutes: 30
run: |
./gradlew --stacktrace --no-build-cache \
:baseline-profile:assemble \
testDebugUnitTest \
lintDebug \
:app:assembleDebug \
:app:assembleRelease
cache_args=()
if [ "$RUNNER_ENVIRONMENT" = self-hosted ] && [ -n "${GRADLE_USER_HOME:-}" ]; then
cache_args=(--project-cache-dir "$GRADLE_USER_HOME/project-cache/android-beta")
fi
./gradlew --stacktrace "${cache_args[@]}" :app:assembleRelease

- name: Check that R8 kept every view model constructor
run: |
awk '/^dev\.typetype\..*ViewModel:$/ { c = $1; next } /^[^ ]/ { c = "" } c && /<init>\(/ { print "R8 removed the constructor of " c; bad = 1 } END { exit bad }' \
app/build/outputs/mapping/release/usage.txt

- name: Upload lint report
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: typetype-beta-lint-report
path: |
**/build/reports/lint-results-debug.html
if-no-files-found: ignore
retention-days: 14

- name: Verify and prepare beta APK
run: |
export PATH="$JAVA_HOME/bin:$PATH"
Expand Down Expand Up @@ -218,7 +207,7 @@ jobs:
publish:
needs: release
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
runs-on: [self-hosted, ci-stack]
timeout-minutes: 15
permissions:
contents: write
Expand Down
51 changes: 49 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ jobs:
testDebugUnitTest
lintDebug
:app:assembleDebug
:app:assembleRelease
)
./gradlew --stacktrace "${tasks[@]}"
cache_args=()
if [ "$RUNNER_ENVIRONMENT" = self-hosted ] && [ -n "${GRADLE_USER_HOME:-}" ]; then
cache_args=(--project-cache-dir "$GRADLE_USER_HOME/project-cache/android-verify")
fi
./gradlew --stacktrace "${cache_args[@]}" "${tasks[@]}"

- name: Upload debug APK
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
Expand All @@ -112,6 +115,45 @@ jobs:
if-no-files-found: ignore
retention-days: 14

minified:
if: ${{ github.event_name != 'workflow_dispatch' || !inputs.publish_release || github.ref != 'refs/heads/main' }}
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && fromJSON('["self-hosted","stack-android"]') || 'ubuntu-latest' }}
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Java
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: 21

- name: Set up Gradle
uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
with:
cache-disabled: ${{ runner.environment == 'self-hosted' }}

- name: Install Android SDK platform
if: ${{ runner.environment == 'github-hosted' }}
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install \
"platforms;android-37.0" "build-tools;36.0.0" > /dev/null

- name: Build minified release
timeout-minutes: 30
run: |
cache_args=()
if [ "$RUNNER_ENVIRONMENT" = self-hosted ] && [ -n "${GRADLE_USER_HOME:-}" ]; then
cache_args=(--project-cache-dir "$GRADLE_USER_HOME/project-cache/android-minified")
fi
./gradlew --stacktrace "${cache_args[@]}" :app:assembleRelease

- name: Check that R8 kept every view model constructor
run: |
awk '/^dev\.typetype\..*ViewModel:$/ { c = $1; next } /^[^ ]/ { c = "" } c && /<init>\(/ { print "R8 removed the constructor of " c; bad = 1 } END { exit bad }' \
app/build/outputs/mapping/release/usage.txt

release:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && inputs.publish_release }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -183,6 +225,11 @@ jobs:
)
./gradlew --stacktrace "${tasks[@]}"

- name: Check that R8 kept every view model constructor
run: |
awk '/^dev\.typetype\..*ViewModel:$/ { c = $1; next } /^[^ ]/ { c = "" } c && /<init>\(/ { print "R8 removed the constructor of " c; bad = 1 } END { exit bad }' \
app/build/outputs/mapping/release/usage.txt

- name: Upload lint report
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
Expand Down
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 = 11117
versionName = "1.12.0-beta.4"
versionCode = 11118
versionName = "1.13.0-beta.3"
}

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 @@ -13,5 +13,6 @@ class AndroidHiltConventionPlugin : Plugin<Project> {
add("implementation", libs.findLibrary("hilt-android").get())
add("ksp", libs.findLibrary("hilt-compiler").get())
}
guardHiltKsp()
}
}
32 changes: 32 additions & 0 deletions build-logic/convention/src/main/kotlin/HiltKspSafety.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters

abstract class KspLock : BuildService<BuildServiceParameters.None>

private val hiltEntryPoints = listOf("@HiltViewModel", "@AndroidEntryPoint", "@HiltAndroidApp", "@Module", "@Inject")

// KSP tasks that run at the same time in one Gradle daemon can fail or silently generate nothing; the app
// then builds without those Hilt bindings and crashes at runtime. Run them one at a time, and fail the
// build when a variant with Hilt code produced no Java at all.
internal fun Project.guardHiltKsp() {
val lock = gradle.sharedServices.registerIfAbsent("kspLock", KspLock::class.java) {
maxParallelUsages.set(1)
}
val mainSources = fileTree("src/main") { include("**/*.kt") }
val modulePath = path
tasks.matching { it.name.startsWith("ksp") && it.name.endsWith("Kotlin") }.configureEach {
usesService(lock)
if (name.contains("Test")) return@configureEach
val variant = name.removePrefix("ksp").removeSuffix("Kotlin").replaceFirstChar(Char::lowercase)
val generatedJava = layout.buildDirectory.dir("generated/ksp/$variant/java")
doLast {
val usesHilt = mainSources.files.any { file -> file.useLines { lines -> lines.any { line -> hiltEntryPoints.any(line::contains) } } }
val generated = generatedJava.get().asFileTree.matching { include("**/*.java") }
if (usesHilt && generated.isEmpty) {
throw GradleException("KSP generated no Hilt sources for $modulePath ($variant); the bindings would be missing")
}
}
}
}
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),
)
}
Loading