feat: 历史播放进入时不自动播放,滚动定位到历史剧集
This commit is contained in:
@@ -7,6 +7,7 @@ import android.view.View
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.Button
|
||||
import android.widget.HorizontalScrollView
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -30,6 +31,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
private lateinit var controlPanel: View
|
||||
private lateinit var sourceList: LinearLayout
|
||||
private lateinit var episodeList: LinearLayout
|
||||
private lateinit var episodeScroll: HorizontalScrollView
|
||||
private lateinit var loadingIndicator: View
|
||||
private lateinit var errorText: android.widget.TextView
|
||||
private lateinit var btnClose: ImageButton
|
||||
@@ -42,6 +44,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
private var sources: List<PlaySource> = emptyList()
|
||||
private var currentSourceIndex = 0
|
||||
private var currentEpisode: Episode? = null
|
||||
private var historyEpisode: String? = null
|
||||
|
||||
private val hideHandler = Handler(Looper.getMainLooper())
|
||||
private val hideRunnable = Runnable { hideControls() }
|
||||
@@ -62,6 +65,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
controlPanel = findViewById(R.id.control_panel)
|
||||
sourceList = findViewById(R.id.source_list)
|
||||
episodeList = findViewById(R.id.episode_list)
|
||||
episodeScroll = findViewById(R.id.episode_scroll)
|
||||
loadingIndicator = findViewById(R.id.loading_indicator)
|
||||
errorText = findViewById(R.id.error_text)
|
||||
btnClose = findViewById(R.id.btn_close)
|
||||
@@ -70,6 +74,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||
videoTitle = intent.getStringExtra("title") ?: ""
|
||||
videoCategory = intent.getStringExtra("category")
|
||||
coverUrl = intent.getStringExtra("cover_url")
|
||||
historyEpisode = intent.getStringExtra("history_episode")
|
||||
|
||||
btnClose.setOnClickListener { finish() }
|
||||
|
||||
@@ -131,18 +136,19 @@ class PlayerActivity : AppCompatActivity() {
|
||||
if (index !in sources.indices) return
|
||||
currentSourceIndex = index
|
||||
|
||||
// Highlight selected source
|
||||
for (i in 0 until sourceList.childCount) {
|
||||
sourceList.getChildAt(i).isSelected = (i == index)
|
||||
}
|
||||
|
||||
// Build episode list for this source
|
||||
val source = sources[index]
|
||||
buildEpisodeUI(source.episodes)
|
||||
|
||||
// Auto-play first episode
|
||||
if (source.episodes.isNotEmpty()) {
|
||||
playEpisode(source.episodes.first())
|
||||
if (historyEpisode != null) {
|
||||
scrollToEpisode(historyEpisode!!)
|
||||
} else {
|
||||
if (source.episodes.isNotEmpty()) {
|
||||
playEpisode(source.episodes.first())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +174,20 @@ class PlayerActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollToEpisode(episodeTitle: String) {
|
||||
episodeScroll.post {
|
||||
for (i in 0 until episodeList.childCount) {
|
||||
val child = episodeList.getChildAt(i) as? Button
|
||||
if (child?.text == episodeTitle) {
|
||||
val left = child.left - episodeList.paddingStart
|
||||
episodeScroll.smoothScrollTo(left, 0)
|
||||
child.isSelected = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun playEpisode(ep: Episode) {
|
||||
currentEpisode = ep
|
||||
showLoading(true)
|
||||
|
||||
@@ -225,6 +225,7 @@ class SearchFragment : Fragment() {
|
||||
putExtra("title", playHistory.title)
|
||||
putExtra("category", playHistory.category)
|
||||
putExtra("cover_url", playHistory.coverUrl)
|
||||
putExtra("history_episode", playHistory.episodeName)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user