Skip to content

Commit ea0683c

Browse files
committed
fix: Applied PR suggestions
1 parent 314eb7c commit ea0683c

53 files changed

Lines changed: 3115 additions & 7947 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Android/YouTubeSummarizer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# tl;dw
2-
TLDW (Too Long Didn't Watch) Is a summary generation app for YouTube videos.
2+
TLDW (Too Long Didn't Watch) is a summary generation app for YouTube videos.
33

44
# Demo
55

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,61 @@
11
plugins {
2-
alias(libs.plugins.android.application)
3-
alias(libs.plugins.kotlin.android)
4-
alias(libs.plugins.kotlin.compose)
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
alias(libs.plugins.ktfmt)
56
}
67

7-
kotlin {
8-
jvmToolchain(17)
9-
}
10-
11-
android {
12-
namespace = "com.tldw.app"
13-
compileSdk = 36
8+
kotlin { jvmToolchain(17) }
149

15-
defaultConfig {
16-
applicationId = "com.tldw.app"
17-
minSdk = 31
18-
targetSdk = 36
19-
versionCode = 1
20-
versionName = "1.0"
21-
}
10+
ktfmt { googleStyle() }
2211

23-
buildTypes {
24-
release {
25-
isMinifyEnabled = false
26-
proguardFiles(
27-
getDefaultProguardFile("proguard-android-optimize.txt"),
28-
"proguard-rules.pro"
29-
)
30-
}
12+
android {
13+
namespace = "com.tldw.app"
14+
compileSdk = 36
15+
16+
defaultConfig {
17+
applicationId = "com.tldw.app"
18+
minSdk = 31
19+
targetSdk = 36
20+
versionCode = 1
21+
versionName = "1.0"
22+
}
23+
24+
buildTypes {
25+
release {
26+
isMinifyEnabled = false
27+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
3128
}
29+
}
3230

33-
buildFeatures {
34-
compose = true
35-
}
31+
buildFeatures { compose = true }
3632
}
3733

3834
dependencies {
39-
implementation(libs.androidx.core.ktx)
40-
implementation(libs.androidx.lifecycle.runtime.ktx)
41-
implementation(libs.androidx.lifecycle.runtime.compose)
42-
implementation(libs.androidx.lifecycle.viewmodel.compose)
43-
implementation(libs.androidx.activity.compose)
44-
implementation(platform(libs.androidx.compose.bom))
45-
implementation(libs.androidx.ui)
46-
implementation(libs.androidx.ui.graphics)
47-
implementation(libs.androidx.ui.tooling.preview)
48-
implementation(libs.androidx.material3)
49-
implementation(libs.androidx.material.icons.extended)
50-
implementation(libs.kotlinx.coroutines.android)
51-
implementation(libs.okhttp)
52-
implementation(libs.gson)
53-
implementation(libs.leap.sdk.android)
54-
implementation(libs.leap.model.downloader)
55-
implementation(libs.coil.compose)
56-
implementation(libs.compose.markdown)
57-
58-
debugImplementation(libs.androidx.ui.tooling)
59-
debugImplementation(libs.androidx.ui.test.manifest)
60-
61-
testImplementation(libs.junit)
62-
testImplementation(libs.kotlinx.coroutines.test)
63-
testImplementation(libs.mockito.kotlin)
64-
testImplementation(libs.okhttp.mockwebserver)
35+
implementation(libs.androidx.core.ktx)
36+
implementation(libs.androidx.lifecycle.runtime.ktx)
37+
implementation(libs.androidx.lifecycle.runtime.compose)
38+
implementation(libs.androidx.lifecycle.viewmodel.compose)
39+
implementation(libs.androidx.activity.compose)
40+
implementation(platform(libs.androidx.compose.bom))
41+
implementation(libs.androidx.ui)
42+
implementation(libs.androidx.ui.graphics)
43+
implementation(libs.androidx.ui.tooling.preview)
44+
implementation(libs.androidx.material3)
45+
implementation(libs.androidx.material.icons.extended)
46+
implementation(libs.kotlinx.coroutines.android)
47+
implementation(libs.okhttp)
48+
implementation(libs.gson)
49+
implementation(libs.leap.sdk.android)
50+
implementation(libs.leap.model.downloader)
51+
implementation(libs.coil.compose)
52+
implementation(libs.compose.markdown)
53+
54+
debugImplementation(libs.androidx.ui.tooling)
55+
debugImplementation(libs.androidx.ui.test.manifest)
56+
57+
testImplementation(libs.junit)
58+
testImplementation(libs.kotlinx.coroutines.test)
59+
testImplementation(libs.mockito.kotlin)
60+
testImplementation(libs.okhttp.mockwebserver)
6561
}

Android/YouTubeSummarizer/app/src/main/java/com/tldw/app/Consts.kt

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@ package com.tldw.app
33
import com.tldw.app.domain.model.VideoInfo
44

55
object Consts {
6-
const val MODEL_NAME = "LFM2-350M"
7-
const val QUANTIZATION_SLUG = "Q8_0"
8-
const val TLDR_SYSTEM_PROMPT =
9-
"You are a helpful assistant. Given a YouTube video transcript, produce a concise TL;DR summary in 3-5 bullet points."
10-
const val MAX_TRANSCRIPT_CHARS = 4000
6+
const val MODEL_NAME = "LFM2-350M"
7+
const val QUANTIZATION_SLUG = "Q8_0"
8+
const val TLDR_SYSTEM_PROMPT =
9+
"You are a helpful assistant. Given a YouTube video transcript, produce a concise TL;DR summary in 3-5 bullet points."
10+
const val MAX_TRANSCRIPT_CHARS = 4000
1111

12-
val VIDEO_PRINTING_PRESS =
13-
VideoInfo(
14-
videoId = "Y0NopNiSkKw",
15-
title = "The Complete History of the Printing Press | How Printing Changed the World",
16-
channelName = "History of Innovations",
17-
durationSeconds = 595L,
18-
viewCount = 425L,
19-
)
12+
val VIDEO_PRINTING_PRESS =
13+
VideoInfo(
14+
videoId = "Y0NopNiSkKw",
15+
title = "The Complete History of the Printing Press | How Printing Changed the World",
16+
channelName = "History of Innovations",
17+
durationSeconds = 595L,
18+
viewCount = 425L,
19+
)
2020

21-
val VIDEO_SLEEP_SUPERPOWER =
22-
VideoInfo(
23-
videoId = "5MuIMqhT8DM",
24-
title = "Sleep Is Your Superpower | Matt Walker | TED",
25-
channelName = "TED",
26-
durationSeconds = 1158L,
27-
viewCount = 16505865L,
28-
)
21+
val VIDEO_SLEEP_SUPERPOWER =
22+
VideoInfo(
23+
videoId = "5MuIMqhT8DM",
24+
title = "Sleep Is Your Superpower | Matt Walker | TED",
25+
channelName = "TED",
26+
durationSeconds = 1158L,
27+
viewCount = 16505865L,
28+
)
2929

30-
val VIDEO_BUILD_GPT =
31-
VideoInfo(
32-
videoId = "kCc8FmEb1nY",
33-
title = "Let's build GPT: from scratch, in code, spelled out.",
34-
channelName = "Andrej Karpathy",
35-
durationSeconds = 6980L,
36-
viewCount = 7168320L,
37-
)
30+
val VIDEO_BUILD_GPT =
31+
VideoInfo(
32+
videoId = "kCc8FmEb1nY",
33+
title = "Let's build GPT: from scratch, in code, spelled out.",
34+
channelName = "Andrej Karpathy",
35+
durationSeconds = 6980L,
36+
viewCount = 7168320L,
37+
)
3838
}

Android/YouTubeSummarizer/app/src/main/java/com/tldw/app/MainActivity.kt

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,47 @@ import com.tldw.app.ui.transcriptscreen.TranscriptScreenRoute
2222

2323
class MainActivity : ComponentActivity() {
2424

25-
val mainViewModel: MainViewModel by viewModels {
26-
val repository = ModelRepositoryImpl(applicationContext)
27-
MainViewModelFactory(CheckModelDownloadedUseCase(repository))
28-
}
29-
30-
override fun onCreate(savedInstanceState: Bundle?) {
31-
super.onCreate(savedInstanceState)
32-
enableEdgeToEdge()
25+
val mainViewModel: MainViewModel by viewModels {
26+
val repository = ModelRepositoryImpl(applicationContext)
27+
MainViewModelFactory(CheckModelDownloadedUseCase(repository))
28+
}
3329

34-
val sharedUrl = resolveSharedUrl(intent)
35-
mainViewModel.checkStatus()
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
32+
enableEdgeToEdge()
3633

37-
setContent {
38-
TldwTheme {
39-
Surface(modifier = Modifier.fillMaxSize()) {
40-
val state by mainViewModel.state.collectAsStateWithLifecycle()
34+
val sharedUrl = resolveSharedUrl(intent)
4135

42-
when {
43-
state.isCheckingStatus -> {
44-
Box(
45-
contentAlignment = Alignment.Center,
46-
modifier = Modifier.fillMaxSize()
47-
) {
48-
CircularProgressIndicator()
49-
}
50-
}
36+
setContent {
37+
TldwTheme {
38+
Surface(modifier = Modifier.fillMaxSize()) {
39+
val state by mainViewModel.state.collectAsStateWithLifecycle()
5140

52-
state.isModelDownloaded -> {
53-
TranscriptScreenRoute(
54-
sharedUrl = sharedUrl,
55-
onNavigateToModelDownload = { mainViewModel.checkStatus() },
56-
)
57-
}
58-
59-
else -> {
60-
ModelDownloadScreenRoute(onModelReady = { mainViewModel.checkStatus() })
61-
}
62-
}
63-
}
41+
when {
42+
state.isCheckingStatus -> {
43+
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
44+
CircularProgressIndicator()
45+
}
46+
}
47+
state.isModelDownloaded -> {
48+
TranscriptScreenRoute(
49+
sharedUrl = sharedUrl,
50+
onNavigateToModelDownload = { mainViewModel.checkStatus() },
51+
)
6452
}
53+
else -> {
54+
ModelDownloadScreenRoute(onModelReady = { mainViewModel.checkStatus() })
55+
}
56+
}
6557
}
58+
}
6659
}
60+
}
6761

68-
private fun resolveSharedUrl(intent: Intent): String? =
69-
if (intent.action == Intent.ACTION_SEND && intent.type == "text/plain") {
70-
intent.getStringExtra(Intent.EXTRA_TEXT)
71-
} else {
72-
null
73-
}
62+
private fun resolveSharedUrl(intent: Intent): String? =
63+
if (intent.action == Intent.ACTION_SEND && intent.type == "text/plain") {
64+
intent.getStringExtra(Intent.EXTRA_TEXT)
65+
} else {
66+
null
67+
}
7468
}

Android/YouTubeSummarizer/app/src/main/java/com/tldw/app/MainViewModel.kt

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,28 @@ import kotlinx.coroutines.flow.asStateFlow
99
import kotlinx.coroutines.flow.update
1010
import kotlinx.coroutines.launch
1111

12-
data class MainState(
13-
val isCheckingStatus: Boolean = true,
14-
val isModelDownloaded: Boolean = false,
15-
)
12+
data class MainState(val isCheckingStatus: Boolean = true, val isModelDownloaded: Boolean = false)
1613

17-
class MainViewModel(
18-
private val checkModelDownloadedUseCase: CheckModelDownloadedUseCase,
19-
) : ViewModel() {
14+
class MainViewModel(private val checkModelDownloadedUseCase: CheckModelDownloadedUseCase) :
15+
ViewModel() {
2016

21-
private val _state = MutableStateFlow(MainState())
22-
val state: StateFlow<MainState> = _state.asStateFlow()
17+
private val _state = MutableStateFlow(MainState())
18+
val state: StateFlow<MainState> = _state.asStateFlow()
2319

24-
init {
25-
checkStatus()
26-
}
20+
init {
21+
checkStatus()
22+
}
2723

28-
fun checkStatus() {
29-
viewModelScope.launch {
30-
_state.update { it.copy(isCheckingStatus = true) }
31-
try {
32-
val isDownloaded = checkModelDownloadedUseCase()
33-
_state.update { it.copy(isCheckingStatus = false, isModelDownloaded = isDownloaded) }
34-
} catch (e: Exception) {
35-
// If it fails, assume not downloaded or handle gracefully.
36-
_state.update { it.copy(isCheckingStatus = false, isModelDownloaded = false) }
37-
}
38-
}
24+
fun checkStatus() {
25+
viewModelScope.launch {
26+
_state.update { it.copy(isCheckingStatus = true) }
27+
try {
28+
val isDownloaded = checkModelDownloadedUseCase()
29+
_state.update { it.copy(isCheckingStatus = false, isModelDownloaded = isDownloaded) }
30+
} catch (e: Exception) {
31+
// If it fails, assume not downloaded or handle gracefully.
32+
_state.update { it.copy(isCheckingStatus = false, isModelDownloaded = false) }
33+
}
3934
}
35+
}
4036
}

Android/YouTubeSummarizer/app/src/main/java/com/tldw/app/MainViewModelFactory.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.ViewModelProvider
55
import com.tldw.app.domain.usecase.CheckModelDownloadedUseCase
66

7-
class MainViewModelFactory(
8-
private val checkModelDownloadedUseCase: CheckModelDownloadedUseCase,
9-
) : ViewModelProvider.Factory {
10-
@Suppress("UNCHECKED_CAST")
11-
override fun <T : ViewModel> create(modelClass: Class<T>): T {
12-
if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
13-
return MainViewModel(checkModelDownloadedUseCase) as T
14-
}
15-
throw IllegalArgumentException("Unknown ViewModel class")
7+
class MainViewModelFactory(private val checkModelDownloadedUseCase: CheckModelDownloadedUseCase) :
8+
ViewModelProvider.Factory {
9+
@Suppress("UNCHECKED_CAST")
10+
override fun <T : ViewModel> create(modelClass: Class<T>): T {
11+
if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
12+
return MainViewModel(checkModelDownloadedUseCase) as T
1613
}
14+
throw IllegalArgumentException("Unknown ViewModel class")
15+
}
1716
}
18-

0 commit comments

Comments
 (0)