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