From 2824f3f396c6405f3f26eb4fd0d3ad150962d1a8 Mon Sep 17 00:00:00 2001 From: xiaji Date: Tue, 9 Jun 2026 19:55:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SearchFragment=20=E4=BD=BF=E7=94=A8=20S?= =?UTF-8?q?ourceHandler=20=E6=89=A7=E8=A1=8C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/videoapp/tv/ui/SearchFragment.kt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/videoapp/tv/ui/SearchFragment.kt b/app/src/main/java/com/videoapp/tv/ui/SearchFragment.kt index ba1e8bd..94fc2bd 100644 --- a/app/src/main/java/com/videoapp/tv/ui/SearchFragment.kt +++ b/app/src/main/java/com/videoapp/tv/ui/SearchFragment.kt @@ -25,7 +25,8 @@ 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 +import com.videoapp.tv.data.ConfigRepository +import com.videoapp.tv.engine.SourceRegistry import kotlinx.coroutines.launch class SearchFragment : Fragment() { @@ -45,7 +46,7 @@ class SearchFragment : Fragment() { private lateinit var statusText: TextView private lateinit var fallbackWebView: WebView - private val searchCoordinator by lazy { SearchCoordinator(requireContext()) } + private val configRepo by lazy { ConfigRepository(requireContext()) } private val historyDao by lazy { AppDatabase.getInstance(requireContext()).searchHistoryDao() } private val playHistoryDao by lazy { AppDatabase.getInstance(requireContext()).playHistoryDao() } private val adapter by lazy { @@ -137,6 +138,13 @@ class SearchFragment : Fragment() { private fun performSearch(keyword: String) { if (keyword.isEmpty()) return + val currentId = configRepo.getCurrentSourceId() + val handler = SourceRegistry.getOrDefault(currentId) + if (handler == null) { + showStatus("未知源") + return + } + hideFallbackWebView() showLoading(true) statusText.visibility = View.GONE @@ -144,7 +152,6 @@ class SearchFragment : Fragment() { playHistoryContainer.visibility = View.GONE lifecycleScope.launch { - // Save to history val existing = historyDao.findByKeyword(keyword) if (existing != null) { historyDao.updateTime(existing.id, System.currentTimeMillis()) @@ -154,7 +161,7 @@ class SearchFragment : Fragment() { } lifecycleScope.launch { - searchCoordinator.search( + handler.search( keyword = keyword, onResult = { results -> showLoading(false) @@ -165,22 +172,15 @@ class SearchFragment : Fragment() { }, onError = { error -> showLoading(false) - if (error == "FALLBACK_WEBVIEW") { - showFallbackWebView(keyword) - } else { - showStatus("搜索失败,请重试") - Toast.makeText(requireContext(), error, Toast.LENGTH_LONG).show() - } - }, - onFallbackToWebView = { - showFallbackWebView(keyword) + showStatus("搜索失败,请重试") + Toast.makeText(requireContext(), error, Toast.LENGTH_LONG).show() } ) } } private fun showFallbackWebView(keyword: String) { - val config = searchCoordinator.getConfig() + val config = configRepo.getConfig() val base = config.baseUrl.trimEnd('/') val path = config.searchPath.trimStart('/') val params = "${config.keywordParam}=${java.net.URLEncoder.encode(keyword, "UTF-8")}"