修改应用名称为夏季TV,添加播放历史功能,修复搜索框高度问题
This commit is contained in:
@@ -22,6 +22,7 @@ import com.videoapp.tv.R
|
||||
import com.videoapp.tv.PlayerActivity
|
||||
import com.videoapp.tv.SettingsActivity
|
||||
import com.videoapp.tv.data.AppDatabase
|
||||
import com.videoapp.tv.data.PlayHistory
|
||||
import com.videoapp.tv.data.SearchHistory
|
||||
import com.videoapp.tv.data.SearchResult
|
||||
import com.videoapp.tv.engine.SearchCoordinator
|
||||
@@ -35,6 +36,10 @@ class SearchFragment : Fragment() {
|
||||
private lateinit var historyContainer: ViewGroup
|
||||
private lateinit var historyList: ViewGroup
|
||||
private lateinit var btnClearHistory: Button
|
||||
private lateinit var playHistoryContainer: ViewGroup
|
||||
private lateinit var playHistoryList: ViewGroup
|
||||
private lateinit var btnClearPlayHistory: Button
|
||||
private lateinit var emptyPlayHistory: TextView
|
||||
private lateinit var resultsGrid: RecyclerView
|
||||
private lateinit var loadingProgress: View
|
||||
private lateinit var statusText: TextView
|
||||
@@ -42,6 +47,7 @@ class SearchFragment : Fragment() {
|
||||
|
||||
private val searchCoordinator by lazy { SearchCoordinator(requireContext()) }
|
||||
private val historyDao by lazy { AppDatabase.getInstance(requireContext()).searchHistoryDao() }
|
||||
private val playHistoryDao by lazy { AppDatabase.getInstance(requireContext()).playHistoryDao() }
|
||||
private val adapter by lazy {
|
||||
SearchResultAdapter(
|
||||
onItemClick = { result -> openPlayer(result) },
|
||||
@@ -66,6 +72,10 @@ class SearchFragment : Fragment() {
|
||||
historyContainer = view.findViewById(R.id.history_container)
|
||||
historyList = view.findViewById(R.id.history_list)
|
||||
btnClearHistory = view.findViewById(R.id.btn_clear_history)
|
||||
playHistoryContainer = view.findViewById(R.id.play_history_container)
|
||||
playHistoryList = view.findViewById(R.id.play_history_list)
|
||||
btnClearPlayHistory = view.findViewById(R.id.btn_clear_play_history)
|
||||
emptyPlayHistory = view.findViewById(R.id.empty_play_history)
|
||||
resultsGrid = view.findViewById(R.id.results_grid)
|
||||
loadingProgress = view.findViewById(R.id.loading_progress)
|
||||
statusText = view.findViewById(R.id.status_text)
|
||||
@@ -74,6 +84,13 @@ class SearchFragment : Fragment() {
|
||||
setupResultsGrid()
|
||||
setupListeners()
|
||||
loadHistory()
|
||||
loadPlayHistory()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// 每次返回首页时刷新播放历史
|
||||
loadPlayHistory()
|
||||
}
|
||||
|
||||
private fun setupResultsGrid() {
|
||||
@@ -108,6 +125,13 @@ class SearchFragment : Fragment() {
|
||||
showHistory(emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
btnClearPlayHistory.setOnClickListener {
|
||||
lifecycleScope.launch {
|
||||
playHistoryDao.clearAll()
|
||||
showPlayHistory(emptyList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun performSearch(keyword: String) {
|
||||
@@ -117,6 +141,7 @@ class SearchFragment : Fragment() {
|
||||
showLoading(true)
|
||||
statusText.visibility = View.GONE
|
||||
historyContainer.visibility = View.GONE
|
||||
playHistoryContainer.visibility = View.GONE
|
||||
|
||||
lifecycleScope.launch {
|
||||
// Save to history
|
||||
@@ -189,6 +214,17 @@ class SearchFragment : Fragment() {
|
||||
putExtra("detail_url", result.detailUrl)
|
||||
putExtra("title", result.title)
|
||||
putExtra("category", result.category)
|
||||
putExtra("cover_url", result.coverUrl)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun openPlayerFromHistory(playHistory: PlayHistory) {
|
||||
val intent = Intent(requireContext(), PlayerActivity::class.java).apply {
|
||||
putExtra("detail_url", playHistory.detailUrl)
|
||||
putExtra("title", playHistory.title)
|
||||
putExtra("category", playHistory.category)
|
||||
putExtra("cover_url", playHistory.coverUrl)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
@@ -201,6 +237,14 @@ class SearchFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadPlayHistory() {
|
||||
lifecycleScope.launch {
|
||||
playHistoryDao.getRecentPlayHistory().collect { list ->
|
||||
showPlayHistory(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showHistory(list: List<SearchHistory>) {
|
||||
historyList.removeAllViews()
|
||||
if (list.isEmpty()) {
|
||||
@@ -224,6 +268,44 @@ class SearchFragment : Fragment() {
|
||||
}
|
||||
historyList.addView(chip)
|
||||
}
|
||||
historyContainer.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
private fun showPlayHistory(list: List<PlayHistory>) {
|
||||
playHistoryList.removeAllViews()
|
||||
if (list.isEmpty()) {
|
||||
// 显示空状态提示
|
||||
emptyPlayHistory.visibility = View.VISIBLE
|
||||
btnClearPlayHistory.visibility = View.GONE
|
||||
playHistoryList.visibility = View.GONE
|
||||
return
|
||||
}
|
||||
|
||||
// 有播放历史,隐藏空状态提示
|
||||
emptyPlayHistory.visibility = View.GONE
|
||||
btnClearPlayHistory.visibility = View.VISIBLE
|
||||
playHistoryList.visibility = View.VISIBLE
|
||||
|
||||
for (item in list) {
|
||||
val chip = Button(requireContext()).apply {
|
||||
// 显示视频名称和剧集名称
|
||||
text = if (item.episodeName != null) {
|
||||
"${item.title} - ${item.episodeName}"
|
||||
} else {
|
||||
item.title
|
||||
}
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.text_primary))
|
||||
setBackgroundResource(R.drawable.history_chip_selector)
|
||||
textSize = 14f
|
||||
setPadding(24, 12, 24, 12)
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
setOnClickListener {
|
||||
openPlayerFromHistory(item)
|
||||
}
|
||||
}
|
||||
playHistoryList.addView(chip)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user