Skip to content
Closed
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
5 changes: 4 additions & 1 deletion app/smartphone/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,7 @@
-dontwarn com.github.luben.zstd.ZstdInputStreamNoFinalizer
-dontwarn com.github.luben.zstd.util.Native
-dontwarn com.sun.nio.file.SensitivityWatchEventModifier
-dontwarn org.osgi.annotation.bundle.Export
-dontwarn org.osgi.annotation.bundle.Export
-dontwarn io.netty.pkitesting.**
-dontwarn jdk.jfr.**
-dontwarn com.m3u.i18n.R$string
3 changes: 3 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ dependencies {
// auto
implementation(libs.auto.service.annotations)
ksp(libs.auto.service.ksp)

testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
}
5 changes: 5 additions & 0 deletions data/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-dontwarn java.lang.invoke.StringConcatFactory
-dontwarn com.m3u.i18n.R$string

-dontwarn io.netty.pkitesting.**
-dontwarn jdk.jfr.**
27 changes: 3 additions & 24 deletions data/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontwarn java.lang.invoke.StringConcatFactory
-dontwarn com.m3u.i18n.R$string
# ProGuard rules for the data module.
# Rules in this file are only applied when isMinifyEnabled is true for this module.
# For rules that should be applied to consumers of this module, use consumer-rules.pro.
3 changes: 3 additions & 0 deletions data/src/main/java/com/m3u/data/database/dao/ProgrammeDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface ProgrammeDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertOrReplace(programme: Programme)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertOrReplaceAll(programmes: List<Programme>)

@Query("SELECT * FROM programmes WHERE id = :id")
suspend fun getById(id: Int): Programme?

Expand Down
3 changes: 2 additions & 1 deletion data/src/main/java/com/m3u/data/parser/m3u/M3UParserImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ internal class M3UParserImpl @Inject constructor() : M3UParser {
val matches = metadataRegex.findAll(text)
for (match in matches) {
val key = match.groups[1]!!.value
val value = match.groups[2]?.value?.ifBlank { null } ?: continue
val value = (match.groups[2]?.value ?: match.groups[3]?.value)
?.ifBlank { null } ?: continue
put(key.trim(), value.trim())
}
}
Expand Down
13 changes: 5 additions & 8 deletions data/src/main/java/com/m3u/data/repository/CoroutineCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ internal abstract class CoroutineCache<E>(
private val mutex = Mutex()
abstract suspend fun onReceived(cache: List<E>)
suspend fun push(element: E) {
cache += element
if (cache.size >= limit) {
mutex.withLock {
// check again
if (cache.size >= limit) {
onReceived(cache)
cache.clear()
}
mutex.withLock {
cache += element
if (cache.size >= limit) {
onReceived(cache)
cache.clear()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.m3u.data.database.model.epgUrlsOrXtreamXmlUrl
import com.m3u.data.parser.epg.EpgParser
import com.m3u.data.parser.epg.EpgProgramme
import com.m3u.data.parser.epg.toProgramme
import com.m3u.data.repository.createCoroutineCache
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
Expand Down Expand Up @@ -99,11 +100,16 @@ internal class ProgrammeRepositoryImpl @Inject constructor(
epgUrls = epgUrls,
ignoreCache = ignoreCache
)
var count = 0
var currentCount = 0
val cache = createCoroutineCache<Programme>(500) { all ->
programmeDao.insertOrReplaceAll(all)
currentCount += all.size
send(currentCount)
}
producer.collect { programme ->
programmeDao.insertOrReplace(programme)
send(++count)
cache.push(programme)
}
cache.flush()
}

override suspend fun getById(id: Int): Programme? = programmeDao.getById(id)
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ kotlin = "2.3.0"
android-gradle-plugin = "8.9.3"
kotlin-symbol-processor = "2.3.5"

junit = "4.13.2"
kotlinx-coroutines-test = "1.10.1"
androidx-test-ext-junit = "1.3.0"
espresso-core = "3.7.0"
com-google-android-material = "1.13.0"
Expand Down Expand Up @@ -161,6 +163,8 @@ io-coil-kt-compose = { group = "io.coil-kt", name = "coil-compose", version.ref

airbnb-lottie-compose = { group = "com.airbnb.android", name = "lottie-compose", version.ref = "lottie-compose" }

junit = { group = "junit", name = "junit", version.ref = "junit" }
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines-test" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
androidx-test-espresso-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
androidx-test-uiautomator-uiautomator = { group = "androidx.test.uiautomator", name = "uiautomator", version.ref = "androidx-test-uiautomator" }
Expand Down
Loading