From 94e848700ef1585d9989b8b4f35a8b790ea50c18 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 2 Dec 2024 21:56:55 +0100 Subject: [PATCH] refactor: simplify ImportHelper#importPlaylists --- .../com/github/libretube/helpers/ImportHelper.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt index 05999987e..e141107de 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt @@ -191,9 +191,7 @@ object ImportHelper { ImportFormat.YOUTUBECSV -> { val playlist = PipedImportPlaylist() activity.contentResolver.openInputStream(uri)?.use { inputStream -> - val lines = inputStream.bufferedReader().use { reader -> - reader.lines().collect(Collectors.toList()) - } + val lines = inputStream.bufferedReader().readLines() // invalid playlist file, hence returning if (lines.size < 2) return @@ -214,12 +212,13 @@ object ImportHelper { for (line in lines.subList(startIndex, lines.size)) { if (line.isBlank()) continue - line.split(",") + val videoId = line.split(",") .firstOrNull() ?.takeIf { it.isNotBlank() } - ?.let { videoId -> - playlist.videos += videoId.trim() - } + + if (videoId != null) { + playlist.videos += videoId.trim() + } } importPlaylists.add(playlist) }