-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
阅后即焚 #1839
base: main
Are you sure you want to change the base?
阅后即焚 #1839
Conversation
app/shared/app-data/src/commonMain/kotlin/domain/player/extension/BurnAfterReadExtension.kt
Outdated
Show resolved
Hide resolved
app/shared/app-data/src/commonMain/kotlin/domain/media/cache/CacheCleanupService.kt
Outdated
Show resolved
Hide resolved
app/shared/app-data/src/commonMain/kotlin/domain/media/cache/CacheCleanupService.kt
Outdated
Show resolved
Hide resolved
需要为新的 extension 添加对应单元测试 |
@@ -10,42 +18,271 @@ import me.him188.ani.utils.logging.logger | |||
import org.koin.core.Koin | |||
import org.openani.mediamp.MediampPlayer | |||
import org.openani.mediamp.PlaybackState | |||
import kotlin.time.Duration.Companion.seconds | |||
import java.util.concurrent.CopyOnWriteArrayList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No java package in common source, use kotlinx.collections.immutable.PersistentList
(persistentListOf
) with MutableStateFlow
instead.
PlaybackState.FINISHED -> { | ||
val mediaData = context.player.mediaData.value as? TorrentMediaData ?: return@collect | ||
|
||
stateMutex.withLock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
过于复杂的逻辑,需要考虑重新实现。
上面 doc 中有四个条件,可以抽象出一个接口:
private interface BurnCondition {
val result: Flow<Boolean>
}
为每个条件实现 BurnCondition
:
inner class PlaybackProgressGe90Percent : BurnCondition {
// 启动协程或其他操作来执行监听播放进度超过 90% 的逻辑
override val result = MutableStateFlow(false) // 满足条件时设置为 true
}
监听所有 result flow 来执行真正的删除逻辑:
combine(list) { results -> results.all { it } }
.filter { it }
.collect {
// 执行删除逻辑
}
注意这只是其中一种可行的修改方案,如果你有更好的方案就用你的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我倒是觉得 @StageGuard proposed 的比较过度封装了, 这里只需要抽几个函数就行了, 才不到 100 行代码
// 使用线程安全的列表管理后台任务 | ||
private val backgroundJobs = CopyOnWriteArrayList<Job>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Job 生命周期由上层框架管理, 会自动停止 jobs. Extension 无需考虑关闭 job.
* 1. 播放进度超过 90% | ||
* 2. 播放时长超过 60 秒 | ||
* 3. 不是由于用户手动跳转到结尾导致的播放完成 | ||
* 4. 播放完成后等待 30 秒,期间如果开始新的播放或暂停则取消删除 | ||
*/ | ||
class BurnAfterReadExtension( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个需要增加 test
* 1. 播放进度超过 90% | ||
* 2. 播放时长超过 60 秒 | ||
* 3. 不是由于用户手动跳转到结尾导致的播放完成 | ||
* 4. 播放完成后等待 30 秒,期间如果开始新的播放或暂停则取消删除 | ||
*/ | ||
class BurnAfterReadExtension( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
相对于 "BurnAfterRead" (需要思考才能知道是在干什么), 我更倾向于直白的 DeleteCacheAfterWatchedExtension
.
MarkAsWatchedExtension, | ||
BurnAfterReadExtension, | ||
).map { it.create(context, koin) }, | ||
intrinsicExtensions.map { it.create(context, koin) } + extensions.map { it.create(context, koin) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改变了顺序. 顺序最好不变变动
val intrinsicExtensions = listOf( | ||
EpisodePlayerExtensionFactory { _, _ -> LoadMediaOnSelectExtension() }, | ||
RememberPlayProgressExtension, | ||
MarkAsWatchedExtension, | ||
BurnAfterReadExtension, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加 intrinsic Extension 是不好的, 这可能会破坏现有的单元测试.
BurnAfterReadExtension
应当是一个可选的功能.
// 每24小时检查一次 | ||
kotlinx.coroutines.delay(24 * 60 * 60 * 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 每24小时检查一次 | |
kotlinx.coroutines.delay(24 * 60 * 60 * 1000) | |
// 每24小时检查一次 | |
kotlinx.coroutines.delay(24.hours) |
nit
PlaybackState.FINISHED -> { | ||
val mediaData = context.player.mediaData.value as? TorrentMediaData ?: return@collect | ||
|
||
stateMutex.withLock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我倒是觉得 @StageGuard proposed 的比较过度封装了, 这里只需要抽几个函数就行了, 才不到 100 行代码
) { | ||
Group( | ||
title = { | ||
Text("缓存设置") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他地方已经有一个缓存设置了.
expect 函数不能有 body
docs/contributing/building.md
Outdated
@@ -16,6 +16,7 @@ ani.dandanplay.app.secret=aaaaaaaaaaaaaaa | |||
## 打包 Android APP | |||
|
|||
在 IDE 中双击 Ctrl,可用的命令: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请检查代码能通过编译并且在本地测试一下 由于播放器是核心功能, 我们比较期望有覆盖单元测试以确保它未来不会被破坏, 所以也请增加相关的单元测试. |
添加功能配置:
该功能默认关闭,可在设置中打开
更新开发文档