修改应用名称为夏季TV,添加播放历史功能,修复搜索框高度问题
This commit is contained in:
@@ -15,7 +15,9 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.ui.PlayerView
|
||||
import com.videoapp.tv.data.AppDatabase
|
||||
import com.videoapp.tv.data.ConfigRepository
|
||||
import com.videoapp.tv.data.PlayHistory
|
||||
import com.videoapp.tv.engine.Episode
|
||||
import com.videoapp.tv.engine.PlaySource
|
||||
import com.videoapp.tv.engine.VideoExtractor
|
||||
@@ -35,6 +37,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
private var exoPlayer: ExoPlayer? = null
|
||||
private val videoExtractor = VideoExtractor()
|
||||
private val configRepo by lazy { ConfigRepository(this) }
|
||||
private val playHistoryDao by lazy { AppDatabase.getInstance(this).playHistoryDao() }
|
||||
|
||||
private var sources: List<PlaySource> = emptyList()
|
||||
private var currentSourceIndex = 0
|
||||
@@ -44,6 +47,12 @@ class PlayerActivity : AppCompatActivity() {
|
||||
private val hideRunnable = Runnable { hideControls() }
|
||||
private var controlsVisible = true
|
||||
|
||||
// 用于保存播放历史的信息
|
||||
private var videoTitle: String = ""
|
||||
private var videoCategory: String? = null
|
||||
private var coverUrl: String? = null
|
||||
private var detailUrl: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_player)
|
||||
@@ -57,7 +66,10 @@ class PlayerActivity : AppCompatActivity() {
|
||||
errorText = findViewById(R.id.error_text)
|
||||
btnClose = findViewById(R.id.btn_close)
|
||||
|
||||
val detailUrl = intent.getStringExtra("detail_url") ?: ""
|
||||
detailUrl = intent.getStringExtra("detail_url") ?: ""
|
||||
videoTitle = intent.getStringExtra("title") ?: ""
|
||||
videoCategory = intent.getStringExtra("category")
|
||||
coverUrl = intent.getStringExtra("cover_url")
|
||||
|
||||
btnClose.setOnClickListener { finish() }
|
||||
|
||||
@@ -161,6 +173,9 @@ class PlayerActivity : AppCompatActivity() {
|
||||
showLoading(true)
|
||||
val config = configRepo.getConfig()
|
||||
|
||||
// 保存播放历史
|
||||
savePlayHistory(ep.title)
|
||||
|
||||
lifecycleScope.launch {
|
||||
val (directUrl, iframeUrl) = videoExtractor.extractFromPlayPage(ep.playUrl, config)
|
||||
|
||||
@@ -174,7 +189,37 @@ class PlayerActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun savePlayHistory(episodeName: String?) {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
// 检查是否已存在相同的播放记录
|
||||
val existing = playHistoryDao.findByDetailUrl(detailUrl)
|
||||
if (existing != null) {
|
||||
// 更新现有记录的播放时间和剧集
|
||||
playHistoryDao.updatePlayTime(existing.id, System.currentTimeMillis(), episodeName)
|
||||
} else {
|
||||
// 插入新记录
|
||||
val playHistory = PlayHistory(
|
||||
title = videoTitle,
|
||||
episodeName = episodeName,
|
||||
detailUrl = detailUrl,
|
||||
coverUrl = coverUrl,
|
||||
category = videoCategory,
|
||||
playTime = System.currentTimeMillis()
|
||||
)
|
||||
playHistoryDao.insert(playHistory)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 保存播放历史失败不影响播放功能
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryPlayDirectly(detailUrl: String, config: com.videoapp.tv.data.SiteConfig) {
|
||||
// 保存播放历史(直接播放时使用标题作为剧集名)
|
||||
savePlayHistory(videoTitle)
|
||||
|
||||
lifecycleScope.launch {
|
||||
val (directUrl, iframeUrl) = videoExtractor.extractFromPlayPage(detailUrl, config)
|
||||
if (directUrl != null) {
|
||||
|
||||
Reference in New Issue
Block a user